Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 430c7ee

Browse files
committedMar 12, 2021
src: use non-deprecated GetCreationContext from V8
Fixes: nodejs/node-v8#193
1 parent a47f565 commit 430c7ee

6 files changed

+23
-17
lines changed
 

‎src/api/callback.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
223223
Local<Value> argv[],
224224
async_context asyncContext) {
225225
// Check can_call_into_js() first because calling Get() might do so.
226-
Environment* env = Environment::GetCurrent(recv->CreationContext());
226+
Environment* env =
227+
Environment::GetCurrent(recv->GetCreationContext().ToLocalChecked());
227228
CHECK_NOT_NULL(env);
228229
if (!env->can_call_into_js()) return Local<Value>();
229230

@@ -252,7 +253,8 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
252253
//
253254
// Because of the AssignToContext() call in src/node_contextify.cc,
254255
// the two contexts need not be the same.
255-
Environment* env = Environment::GetCurrent(callback->CreationContext());
256+
Environment* env =
257+
Environment::GetCurrent(callback->GetCreationContext().ToLocalChecked());
256258
CHECK_NOT_NULL(env);
257259
Context::Scope context_scope(env->context());
258260
MaybeLocal<Value> ret =
@@ -274,7 +276,8 @@ MaybeLocal<Value> MakeSyncCallback(Isolate* isolate,
274276
Local<Function> callback,
275277
int argc,
276278
Local<Value> argv[]) {
277-
Environment* env = Environment::GetCurrent(callback->CreationContext());
279+
Environment* env =
280+
Environment::GetCurrent(callback->GetCreationContext().ToLocalChecked());
278281
CHECK_NOT_NULL(env);
279282
if (!env->can_call_into_js()) return Local<Value>();
280283

‎src/async_wrap.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ static uint16_t ToAsyncHooksType(PromiseHookType type) {
298298
// Simplified JavaScript hook fast-path for when there is no destroy hook
299299
static void FastPromiseHook(PromiseHookType type, Local<Promise> promise,
300300
Local<Value> parent) {
301-
Local<Context> context = promise->CreationContext();
301+
Local<Context> context = promise->GetCreationContext().ToLocalChecked();
302302
Environment* env = Environment::GetCurrent(context);
303303
if (env == nullptr) return;
304304

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

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

362362
Environment* env = Environment::GetCurrent(context);
363363
if (env == nullptr) return;

‎src/base_object-inl.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ v8::Local<v8::Object> BaseObject::object() const {
8383
v8::Local<v8::Object> BaseObject::object(v8::Isolate* isolate) const {
8484
v8::Local<v8::Object> handle = object();
8585

86-
DCHECK_EQ(handle->CreationContext()->GetIsolate(), isolate);
86+
DCHECK_EQ(handle->GetCreationContext().ToLocalChecked()->GetIsolate(),
87+
isolate);
8788
DCHECK_EQ(env()->isolate(), isolate);
8889

8990
return handle;

‎src/module_wrap.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ModuleWrap::~ModuleWrap() {
8383
Local<Context> ModuleWrap::context() const {
8484
Local<Value> obj = object()->GetInternalField(kContextObjectSlot);
8585
if (obj.IsEmpty()) return {};
86-
return obj.As<Object>()->CreationContext();
86+
return obj.As<Object>()->GetCreationContext().ToLocalChecked();
8787
}
8888

8989
ModuleWrap* ModuleWrap::GetFromModule(Environment* env,
@@ -122,7 +122,7 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
122122
Local<Context> context;
123123
ContextifyContext* contextify_context = nullptr;
124124
if (args[1]->IsUndefined()) {
125-
context = that->CreationContext();
125+
context = that->GetCreationContext().ToLocalChecked();
126126
} else {
127127
CHECK(args[1]->IsObject());
128128
contextify_context = ContextifyContext::ContextFromContextifiedSandbox(
@@ -237,7 +237,7 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
237237
obj->object()->SetInternalField(kSyntheticEvaluationStepsSlot, args[3]);
238238
}
239239

240-
// Use the extras object as an object whose CreationContext() will be the
240+
// Use the extras object as an object whose GetCreationContext() will be the
241241
// original `context`, since the `Context` itself strictly speaking cannot
242242
// be stored in an internal field.
243243
obj->object()->SetInternalField(kContextObjectSlot,

‎src/node_messaging.cc

+8-7
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,8 @@ MaybeLocal<Value> MessagePort::ReceiveMessage(Local<Context> context,
727727
void MessagePort::OnMessage(MessageProcessingMode mode) {
728728
Debug(this, "Running MessagePort::OnMessage()");
729729
HandleScope handle_scope(env()->isolate());
730-
Local<Context> context = object(env()->isolate())->CreationContext();
730+
Local<Context> context =
731+
object(env()->isolate())->GetCreationContext().ToLocalChecked();
731732

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

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

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

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

1052-
MaybeLocal<Value> payload =
1053-
port->ReceiveMessage(port->object()->CreationContext(),
1054-
MessageProcessingMode::kForceReadMessages);
1053+
MaybeLocal<Value> payload = port->ReceiveMessage(
1054+
port->object()->GetCreationContext().ToLocalChecked(),
1055+
MessageProcessingMode::kForceReadMessages);
10551056
if (!payload.IsEmpty())
10561057
args.GetReturnValue().Set(payload.ToLocalChecked());
10571058
}
@@ -1410,7 +1411,7 @@ static void MessageChannel(const FunctionCallbackInfo<Value>& args) {
14101411
return;
14111412
}
14121413

1413-
Local<Context> context = args.This()->CreationContext();
1414+
Local<Context> context = args.This()->GetCreationContext().ToLocalChecked();
14141415
Context::Scope context_scope(context);
14151416

14161417
MessagePort* port1 = MessagePort::New(env, context);

‎src/node_worker.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,8 @@ void GetEnvMessagePort(const FunctionCallbackInfo<Value>& args) {
790790
Local<Object> port = env->message_port();
791791
CHECK_IMPLIES(!env->is_main_thread(), !port.IsEmpty());
792792
if (!port.IsEmpty()) {
793-
CHECK_EQ(port->CreationContext()->GetIsolate(), args.GetIsolate());
793+
CHECK_EQ(port->GetCreationContext().ToLocalChecked()->GetIsolate(),
794+
args.GetIsolate());
794795
args.GetReturnValue().Set(port);
795796
}
796797
}

0 commit comments

Comments
 (0)
Please sign in to comment.