From 430c7eea420cdf6e650738ac3e90d0ed86029528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 28 Feb 2021 17:45:24 +0100 Subject: [PATCH] src: use non-deprecated GetCreationContext from V8 Fixes: https://github.com/nodejs/node-v8/issues/193 --- src/api/callback.cc | 9 ++++++--- src/async_wrap.cc | 4 ++-- src/base_object-inl.h | 3 ++- src/module_wrap.cc | 6 +++--- src/node_messaging.cc | 15 ++++++++------- src/node_worker.cc | 3 ++- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/api/callback.cc b/src/api/callback.cc index a7b23dd4924baf..f8bf9170596afe 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -223,7 +223,8 @@ MaybeLocal MakeCallback(Isolate* isolate, Local argv[], async_context asyncContext) { // Check can_call_into_js() first because calling Get() might do so. - Environment* env = Environment::GetCurrent(recv->CreationContext()); + Environment* env = + Environment::GetCurrent(recv->GetCreationContext().ToLocalChecked()); CHECK_NOT_NULL(env); if (!env->can_call_into_js()) return Local(); @@ -252,7 +253,8 @@ MaybeLocal MakeCallback(Isolate* isolate, // // Because of the AssignToContext() call in src/node_contextify.cc, // the two contexts need not be the same. - Environment* env = Environment::GetCurrent(callback->CreationContext()); + Environment* env = + Environment::GetCurrent(callback->GetCreationContext().ToLocalChecked()); CHECK_NOT_NULL(env); Context::Scope context_scope(env->context()); MaybeLocal ret = @@ -274,7 +276,8 @@ MaybeLocal MakeSyncCallback(Isolate* isolate, Local callback, int argc, Local argv[]) { - Environment* env = Environment::GetCurrent(callback->CreationContext()); + Environment* env = + Environment::GetCurrent(callback->GetCreationContext().ToLocalChecked()); CHECK_NOT_NULL(env); if (!env->can_call_into_js()) return Local(); diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 3748d542c95021..0baf8010907043 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -298,7 +298,7 @@ static uint16_t ToAsyncHooksType(PromiseHookType type) { // Simplified JavaScript hook fast-path for when there is no destroy hook static void FastPromiseHook(PromiseHookType type, Local promise, Local parent) { - Local context = promise->CreationContext(); + Local context = promise->GetCreationContext().ToLocalChecked(); Environment* env = Environment::GetCurrent(context); if (env == nullptr) return; @@ -357,7 +357,7 @@ static void FastPromiseHook(PromiseHookType type, Local promise, static void FullPromiseHook(PromiseHookType type, Local promise, Local parent) { - Local context = promise->CreationContext(); + Local context = promise->GetCreationContext().ToLocalChecked(); Environment* env = Environment::GetCurrent(context); if (env == nullptr) return; diff --git a/src/base_object-inl.h b/src/base_object-inl.h index b9f99a03ddfb3e..ff3610c60a822c 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -83,7 +83,8 @@ v8::Local BaseObject::object() const { v8::Local BaseObject::object(v8::Isolate* isolate) const { v8::Local handle = object(); - DCHECK_EQ(handle->CreationContext()->GetIsolate(), isolate); + DCHECK_EQ(handle->GetCreationContext().ToLocalChecked()->GetIsolate(), + isolate); DCHECK_EQ(env()->isolate(), isolate); return handle; diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 532d7382dfd810..d33cb19b3dcead 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -83,7 +83,7 @@ ModuleWrap::~ModuleWrap() { Local ModuleWrap::context() const { Local obj = object()->GetInternalField(kContextObjectSlot); if (obj.IsEmpty()) return {}; - return obj.As()->CreationContext(); + return obj.As()->GetCreationContext().ToLocalChecked(); } ModuleWrap* ModuleWrap::GetFromModule(Environment* env, @@ -122,7 +122,7 @@ void ModuleWrap::New(const FunctionCallbackInfo& args) { Local context; ContextifyContext* contextify_context = nullptr; if (args[1]->IsUndefined()) { - context = that->CreationContext(); + context = that->GetCreationContext().ToLocalChecked(); } else { CHECK(args[1]->IsObject()); contextify_context = ContextifyContext::ContextFromContextifiedSandbox( @@ -237,7 +237,7 @@ void ModuleWrap::New(const FunctionCallbackInfo& args) { obj->object()->SetInternalField(kSyntheticEvaluationStepsSlot, args[3]); } - // Use the extras object as an object whose CreationContext() will be the + // Use the extras object as an object whose GetCreationContext() will be the // original `context`, since the `Context` itself strictly speaking cannot // be stored in an internal field. obj->object()->SetInternalField(kContextObjectSlot, diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 595f793a6241d4..fbe6c407a6cea2 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -727,7 +727,8 @@ MaybeLocal MessagePort::ReceiveMessage(Local context, void MessagePort::OnMessage(MessageProcessingMode mode) { Debug(this, "Running MessagePort::OnMessage()"); HandleScope handle_scope(env()->isolate()); - Local context = object(env()->isolate())->CreationContext(); + Local context = + object(env()->isolate())->GetCreationContext().ToLocalChecked(); size_t processing_limit; if (mode == MessageProcessingMode::kNormalOperation) { @@ -843,7 +844,7 @@ Maybe MessagePort::PostMessage(Environment* env, const TransferList& transfer_v) { Isolate* isolate = env->isolate(); Local obj = object(isolate); - Local context = obj->CreationContext(); + Local context = obj->GetCreationContext().ToLocalChecked(); std::shared_ptr msg = std::make_shared(); @@ -941,7 +942,7 @@ static Maybe ReadIterable(Environment* env, void MessagePort::PostMessage(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Local obj = args.This(); - Local context = obj->CreationContext(); + Local context = obj->GetCreationContext().ToLocalChecked(); if (args.Length() == 0) { return THROW_ERR_MISSING_ARGS(env, "Not enough arguments to " @@ -1049,9 +1050,9 @@ void MessagePort::ReceiveMessage(const FunctionCallbackInfo& args) { return; } - MaybeLocal payload = - port->ReceiveMessage(port->object()->CreationContext(), - MessageProcessingMode::kForceReadMessages); + MaybeLocal payload = port->ReceiveMessage( + port->object()->GetCreationContext().ToLocalChecked(), + MessageProcessingMode::kForceReadMessages); if (!payload.IsEmpty()) args.GetReturnValue().Set(payload.ToLocalChecked()); } @@ -1410,7 +1411,7 @@ static void MessageChannel(const FunctionCallbackInfo& args) { return; } - Local context = args.This()->CreationContext(); + Local context = args.This()->GetCreationContext().ToLocalChecked(); Context::Scope context_scope(context); MessagePort* port1 = MessagePort::New(env, context); diff --git a/src/node_worker.cc b/src/node_worker.cc index c1a0c6668bf612..15dea5c501b101 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -790,7 +790,8 @@ void GetEnvMessagePort(const FunctionCallbackInfo& args) { Local port = env->message_port(); CHECK_IMPLIES(!env->is_main_thread(), !port.IsEmpty()); if (!port.IsEmpty()) { - CHECK_EQ(port->CreationContext()->GetIsolate(), args.GetIsolate()); + CHECK_EQ(port->GetCreationContext().ToLocalChecked()->GetIsolate(), + args.GetIsolate()); args.GetReturnValue().Set(port); } }