Skip to content

Commit

Permalink
src: use non-deprecated GetCreationContext from V8
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Feb 28, 2021
1 parent e37ba87 commit 5db39ac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 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
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
13 changes: 7 additions & 6 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,8 @@ MaybeLocal<Value> MessagePort::ReceiveMessage(Local<Context> context,
void MessagePort::OnMessage() {
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;
{
Expand Down Expand Up @@ -811,7 +812,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 @@ -909,7 +910,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 @@ -1017,8 +1018,8 @@ void MessagePort::ReceiveMessage(const FunctionCallbackInfo<Value>& args) {
return;
}

MaybeLocal<Value> payload =
port->ReceiveMessage(port->object()->CreationContext(), false);
MaybeLocal<Value> payload = port->ReceiveMessage(
port->object()->GetCreationContext().ToLocalChecked(), false);
if (!payload.IsEmpty())
args.GetReturnValue().Set(payload.ToLocalChecked());
}
Expand Down Expand Up @@ -1377,7 +1378,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

0 comments on commit 5db39ac

Please sign in to comment.