From ff7f8167ebc30eee6ef4d89284d979b4c68764ef Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Mon, 25 Dec 2023 13:53:25 -0500 Subject: [PATCH] src: refactor `GetCreationContext` calls --- src/api/callback.cc | 7 +++---- src/base_object-inl.h | 3 +-- src/module_wrap.cc | 2 +- src/node_messaging.cc | 12 ++++++------ src/node_worker.cc | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/api/callback.cc b/src/api/callback.cc index 3a8bd9155a8545..579bfb6e7fda5c 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -248,8 +248,7 @@ 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->GetCreationContext().ToLocalChecked()); + Environment* env = Environment::GetCurrent(recv->GetCreationContextChecked()); CHECK_NOT_NULL(env); if (!env->can_call_into_js()) return Local(); @@ -279,7 +278,7 @@ 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->GetCreationContext().ToLocalChecked()); + Environment::GetCurrent(callback->GetCreationContextChecked()); CHECK_NOT_NULL(env); Context::Scope context_scope(env->context()); MaybeLocal ret = @@ -302,7 +301,7 @@ MaybeLocal MakeSyncCallback(Isolate* isolate, int argc, Local argv[]) { Environment* env = - Environment::GetCurrent(callback->GetCreationContext().ToLocalChecked()); + Environment::GetCurrent(callback->GetCreationContextChecked()); CHECK_NOT_NULL(env); if (!env->can_call_into_js()) return Local(); diff --git a/src/base_object-inl.h b/src/base_object-inl.h index 2ca432e2dfd3c6..da8fed7b3013df 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -55,8 +55,7 @@ v8::Local BaseObject::object() const { v8::Local BaseObject::object(v8::Isolate* isolate) const { v8::Local handle = object(); - DCHECK_EQ(handle->GetCreationContext().ToLocalChecked()->GetIsolate(), - isolate); + DCHECK_EQ(handle->GetCreationContextChecked()->GetIsolate(), isolate); DCHECK_EQ(env()->isolate(), isolate); return handle; diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 52976d61814256..742f3960c881b9 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -89,7 +89,7 @@ Local ModuleWrap::context() const { // If this fails, there is likely a bug e.g. ModuleWrap::context() is accessed // before the ModuleWrap constructor completes. CHECK(obj->IsObject()); - return obj.As()->GetCreationContext().ToLocalChecked(); + return obj.As()->GetCreationContextChecked(); } ModuleWrap* ModuleWrap::GetFromModule(Environment* env, diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 59d2495ddb27bd..0195a1bb2e448c 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -800,7 +800,7 @@ void MessagePort::OnMessage(MessageProcessingMode mode) { HandleScope handle_scope(env()->isolate()); Local context = - object(env()->isolate())->GetCreationContext().ToLocalChecked(); + object(env()->isolate())->GetCreationContextChecked(); size_t processing_limit; if (mode == MessageProcessingMode::kNormalOperation) { @@ -1057,7 +1057,7 @@ bool GetTransferList(Environment* env, void MessagePort::PostMessage(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Local obj = args.This(); - Local context = obj->GetCreationContext().ToLocalChecked(); + Local context = obj->GetCreationContextChecked(); if (args.Length() == 0) { return THROW_ERR_MISSING_ARGS(env, "Not enough arguments to " @@ -1143,9 +1143,9 @@ void MessagePort::ReceiveMessage(const FunctionCallbackInfo& args) { return; } - MaybeLocal payload = port->ReceiveMessage( - port->object()->GetCreationContext().ToLocalChecked(), - MessageProcessingMode::kForceReadMessages); + MaybeLocal payload = + port->ReceiveMessage(port->object()->GetCreationContextChecked(), + MessageProcessingMode::kForceReadMessages); if (!payload.IsEmpty()) args.GetReturnValue().Set(payload.ToLocalChecked()); } @@ -1610,7 +1610,7 @@ static void MessageChannel(const FunctionCallbackInfo& args) { return; } - Local context = args.This()->GetCreationContext().ToLocalChecked(); + Local context = args.This()->GetCreationContextChecked(); Context::Scope context_scope(context); MessagePort* port1 = MessagePort::New(env, context); diff --git a/src/node_worker.cc b/src/node_worker.cc index 0affbe7c85a013..552fdc438a0895 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -907,7 +907,7 @@ void GetEnvMessagePort(const FunctionCallbackInfo& args) { Local port = env->message_port(); CHECK_IMPLIES(!env->is_main_thread(), !port.IsEmpty()); if (!port.IsEmpty()) { - CHECK_EQ(port->GetCreationContext().ToLocalChecked()->GetIsolate(), + CHECK_EQ(port->GetCreationContextChecked()->GetIsolate(), args.GetIsolate()); args.GetReturnValue().Set(port); }