Skip to content

Commit

Permalink
src: refactor GetCreationContext calls
Browse files Browse the repository at this point in the history
PR-URL: #51287
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
anonrig authored and richardlau committed Mar 25, 2024
1 parent 0afeede commit f9d1f3b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/api/callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
Local<Value> 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<Value>();

Expand Down Expand Up @@ -279,7 +278,7 @@ MaybeLocal<Value> 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<Value> ret =
Expand All @@ -302,7 +301,7 @@ MaybeLocal<Value> MakeSyncCallback(Isolate* isolate,
int argc,
Local<Value> argv[]) {
Environment* env =
Environment::GetCurrent(callback->GetCreationContext().ToLocalChecked());
Environment::GetCurrent(callback->GetCreationContextChecked());
CHECK_NOT_NULL(env);
if (!env->can_call_into_js()) return Local<Value>();

Expand Down
3 changes: 1 addition & 2 deletions src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ v8::Local<v8::Object> BaseObject::object() const {
v8::Local<v8::Object> BaseObject::object(v8::Isolate* isolate) const {
v8::Local<v8::Object> handle = object();

DCHECK_EQ(handle->GetCreationContext().ToLocalChecked()->GetIsolate(),
isolate);
DCHECK_EQ(handle->GetCreationContextChecked()->GetIsolate(), isolate);
DCHECK_EQ(env()->isolate(), isolate);

return handle;
Expand Down
2 changes: 1 addition & 1 deletion src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Local<Context> 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<Object>()->GetCreationContext().ToLocalChecked();
return obj.As<Object>()->GetCreationContextChecked();
}

ModuleWrap* ModuleWrap::GetFromModule(Environment* env,
Expand Down
12 changes: 6 additions & 6 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ void MessagePort::OnMessage(MessageProcessingMode mode) {

HandleScope handle_scope(env()->isolate());
Local<Context> context =
object(env()->isolate())->GetCreationContext().ToLocalChecked();
object(env()->isolate())->GetCreationContextChecked();

size_t processing_limit;
if (mode == MessageProcessingMode::kNormalOperation) {
Expand Down Expand Up @@ -1048,7 +1048,7 @@ bool GetTransferList(Environment* env,
void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Local<Object> obj = args.This();
Local<Context> context = obj->GetCreationContext().ToLocalChecked();
Local<Context> context = obj->GetCreationContextChecked();

if (args.Length() == 0) {
return THROW_ERR_MISSING_ARGS(env, "Not enough arguments to "
Expand Down Expand Up @@ -1134,9 +1134,9 @@ void MessagePort::ReceiveMessage(const FunctionCallbackInfo<Value>& args) {
return;
}

MaybeLocal<Value> payload = port->ReceiveMessage(
port->object()->GetCreationContext().ToLocalChecked(),
MessageProcessingMode::kForceReadMessages);
MaybeLocal<Value> payload =
port->ReceiveMessage(port->object()->GetCreationContextChecked(),
MessageProcessingMode::kForceReadMessages);
if (!payload.IsEmpty())
args.GetReturnValue().Set(payload.ToLocalChecked());
}
Expand Down Expand Up @@ -1547,7 +1547,7 @@ static void MessageChannel(const FunctionCallbackInfo<Value>& args) {
return;
}

Local<Context> context = args.This()->GetCreationContext().ToLocalChecked();
Local<Context> context = args.This()->GetCreationContextChecked();
Context::Scope context_scope(context);

MessagePort* port1 = MessagePort::New(env, context);
Expand Down
2 changes: 1 addition & 1 deletion src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ void GetEnvMessagePort(const FunctionCallbackInfo<Value>& args) {
Local<Object> 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);
}
Expand Down

0 comments on commit f9d1f3b

Please sign in to comment.