From 5db39aca4e6c9b6b4e51c6fe9ff0afd459de209d 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/module_wrap.cc | 6 +++--- src/node_messaging.cc | 13 +++++++------ 4 files changed, 18 insertions(+), 14 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/module_wrap.cc b/src/module_wrap.cc index 4f9a8d27277268..57eb0c99b2ac63 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 78fb46ab6f2803..7c140c9436c917 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -700,7 +700,8 @@ MaybeLocal MessagePort::ReceiveMessage(Local context, void MessagePort::OnMessage() { 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; { @@ -811,7 +812,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(); @@ -909,7 +910,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 " @@ -1017,8 +1018,8 @@ void MessagePort::ReceiveMessage(const FunctionCallbackInfo& args) { return; } - MaybeLocal payload = - port->ReceiveMessage(port->object()->CreationContext(), false); + MaybeLocal payload = port->ReceiveMessage( + port->object()->GetCreationContext().ToLocalChecked(), false); if (!payload.IsEmpty()) args.GetReturnValue().Set(payload.ToLocalChecked()); } @@ -1377,7 +1378,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);