Skip to content

Commit

Permalink
src: use non-deprecated GetCreationContext from V8
Browse files Browse the repository at this point in the history
Fixes: nodejs/node-v8#193

PR-URL: #37587
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
  • Loading branch information
targos committed Mar 15, 2021
1 parent b1c1c46 commit 8e8dea3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
9 changes: 6 additions & 3 deletions src/api/callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ 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->CreationContext());
Environment* env =
Environment::GetCurrent(recv->GetCreationContext().ToLocalChecked());
CHECK_NOT_NULL(env);
if (!env->can_call_into_js()) return Local<Value>();

Expand Down Expand Up @@ -252,7 +253,8 @@ 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->CreationContext());
Environment* env =
Environment::GetCurrent(callback->GetCreationContext().ToLocalChecked());
CHECK_NOT_NULL(env);
Context::Scope context_scope(env->context());
MaybeLocal<Value> ret =
Expand All @@ -274,7 +276,8 @@ MaybeLocal<Value> MakeSyncCallback(Isolate* isolate,
Local<Function> callback,
int argc,
Local<Value> 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<Value>();

Expand Down
4 changes: 2 additions & 2 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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> promise,
Local<Value> parent) {
Local<Context> context = promise->CreationContext();
Local<Context> context = promise->GetCreationContext().ToLocalChecked();
Environment* env = Environment::GetCurrent(context);
if (env == nullptr) return;

Expand Down Expand Up @@ -357,7 +357,7 @@ static void FastPromiseHook(PromiseHookType type, Local<Promise> promise,

static void FullPromiseHook(PromiseHookType type, Local<Promise> promise,
Local<Value> parent) {
Local<Context> context = promise->CreationContext();
Local<Context> context = promise->GetCreationContext().ToLocalChecked();

Environment* env = Environment::GetCurrent(context);
if (env == nullptr) return;
Expand Down
3 changes: 2 additions & 1 deletion src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ 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->CreationContext()->GetIsolate(), isolate);
DCHECK_EQ(handle->GetCreationContext().ToLocalChecked()->GetIsolate(),
isolate);
DCHECK_EQ(env()->isolate(), isolate);

return handle;
Expand Down
6 changes: 3 additions & 3 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ ModuleWrap::~ModuleWrap() {
Local<Context> ModuleWrap::context() const {
Local<Value> obj = object()->GetInternalField(kContextObjectSlot);
if (obj.IsEmpty()) return {};
return obj.As<Object>()->CreationContext();
return obj.As<Object>()->GetCreationContext().ToLocalChecked();
}

ModuleWrap* ModuleWrap::GetFromModule(Environment* env,
Expand Down Expand Up @@ -122,7 +122,7 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
Local<Context> 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(
Expand Down Expand Up @@ -237,7 +237,7 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& 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,
Expand Down
15 changes: 8 additions & 7 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,8 @@ MaybeLocal<Value> MessagePort::ReceiveMessage(Local<Context> context,
void MessagePort::OnMessage(MessageProcessingMode mode) {
Debug(this, "Running MessagePort::OnMessage()");
HandleScope handle_scope(env()->isolate());
Local<Context> context = object(env()->isolate())->CreationContext();
Local<Context> context =
object(env()->isolate())->GetCreationContext().ToLocalChecked();

size_t processing_limit;
if (mode == MessageProcessingMode::kNormalOperation) {
Expand Down Expand Up @@ -843,7 +844,7 @@ Maybe<bool> MessagePort::PostMessage(Environment* env,
const TransferList& transfer_v) {
Isolate* isolate = env->isolate();
Local<Object> obj = object(isolate);
Local<Context> context = obj->CreationContext();
Local<Context> context = obj->GetCreationContext().ToLocalChecked();

std::shared_ptr<Message> msg = std::make_shared<Message>();

Expand Down Expand Up @@ -941,7 +942,7 @@ static Maybe<bool> ReadIterable(Environment* env,
void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Local<Object> obj = args.This();
Local<Context> context = obj->CreationContext();
Local<Context> context = obj->GetCreationContext().ToLocalChecked();

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

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

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

MessagePort* port1 = MessagePort::New(env, context);
Expand Down
3 changes: 2 additions & 1 deletion src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ 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->CreationContext()->GetIsolate(), args.GetIsolate());
CHECK_EQ(port->GetCreationContext().ToLocalChecked()->GetIsolate(),
args.GetIsolate());
args.GetReturnValue().Set(port);
}
}
Expand Down

0 comments on commit 8e8dea3

Please sign in to comment.