From fe151d32a52c45322ec5d6d7e577d0f134cf71b0 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 | 15 ++++++++------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/api/callback.cc b/src/api/callback.cc index a7b23dd4924..f8bf9170596 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 3748d542c95..0baf8010907 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 4f9a8d27277..57eb0c99b2a 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 2699bd2792e..66beff63320 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -702,7 +702,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) { @@ -815,7 +816,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(); @@ -913,7 +914,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 " @@ -1021,9 +1022,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()); } @@ -1382,7 +1383,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);