diff --git a/doc/api/addons.md b/doc/api/addons.md index cddb1a38cecb0a..3df6873a0dd8eb 100644 --- a/doc/api/addons.md +++ b/doc/api/addons.md @@ -632,6 +632,7 @@ functions and returning those back to JavaScript: namespace demo { +using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -649,8 +650,9 @@ void MyFunction(const FunctionCallbackInfo& args) { void CreateFunction(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); + Local context = isolate->GetCurrentContext(); Local tpl = FunctionTemplate::New(isolate, MyFunction); - Local fn = tpl->GetFunction(); + Local fn = tpl->GetFunction(context).ToLocalChecked(); // omit this to make it anonymous fn->SetName(String::NewFromUtf8(isolate, "theFunction")); @@ -774,9 +776,10 @@ void MyObject::Init(Local exports) { // Prototype NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne); - constructor.Reset(isolate, tpl->GetFunction()); + Local context = isolate->GetCurrentContext(); + constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); exports->Set(String::NewFromUtf8(isolate, "MyObject"), - tpl->GetFunction()); + tpl->GetFunction(context).ToLocalChecked()); } void MyObject::New(const FunctionCallbackInfo& args) { @@ -958,7 +961,8 @@ void MyObject::Init(Isolate* isolate) { // Prototype NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne); - constructor.Reset(isolate, tpl->GetFunction()); + Local context = isolate->GetCurrentContext(); + constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); } void MyObject::New(const FunctionCallbackInfo& args) { diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 3cf1d434d3ca71..320fba3a70b99e 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -2129,7 +2129,7 @@ void Initialize(Local target, Local addrInfoWrapString = FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap"); aiw->SetClassName(addrInfoWrapString); - target->Set(addrInfoWrapString, aiw->GetFunction()); + target->Set(addrInfoWrapString, aiw->GetFunction(context).ToLocalChecked()); Local niw = BaseObject::MakeLazilyInitializedJSTemplate(env); @@ -2137,7 +2137,7 @@ void Initialize(Local target, Local nameInfoWrapString = FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap"); niw->SetClassName(nameInfoWrapString); - target->Set(nameInfoWrapString, niw->GetFunction()); + target->Set(nameInfoWrapString, niw->GetFunction(context).ToLocalChecked()); Local qrw = BaseObject::MakeLazilyInitializedJSTemplate(env); @@ -2145,7 +2145,7 @@ void Initialize(Local target, Local queryWrapString = FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap"); qrw->SetClassName(queryWrapString); - target->Set(queryWrapString, qrw->GetFunction()); + target->Set(queryWrapString, qrw->GetFunction(context).ToLocalChecked()); Local channel_wrap = env->NewFunctionTemplate(ChannelWrap::New); @@ -2172,7 +2172,8 @@ void Initialize(Local target, Local channelWrapString = FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap"); channel_wrap->SetClassName(channelWrapString); - target->Set(channelWrapString, channel_wrap->GetFunction()); + target->Set(channelWrapString, + channel_wrap->GetFunction(context).ToLocalChecked()); } } // anonymous namespace diff --git a/src/env-inl.h b/src/env-inl.h index dc842582d12342..32b393e476210c 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -685,13 +685,15 @@ inline v8::Local inline void Environment::SetMethod(v8::Local that, const char* name, v8::FunctionCallback callback) { + v8::Local context = isolate()->GetCurrentContext(); v8::Local function = - NewFunctionTemplate(callback, - v8::Local(), + NewFunctionTemplate(callback, v8::Local(), // TODO(TimothyGu): Investigate if SetMethod is ever // used for constructors. v8::ConstructorBehavior::kAllow, - v8::SideEffectType::kHasSideEffect)->GetFunction(); + v8::SideEffectType::kHasSideEffect) + ->GetFunction(context) + .ToLocalChecked(); // kInternalized strings are created in the old space. const v8::NewStringType type = v8::NewStringType::kInternalized; v8::Local name_string = @@ -703,13 +705,15 @@ inline void Environment::SetMethod(v8::Local that, inline void Environment::SetMethodNoSideEffect(v8::Local that, const char* name, v8::FunctionCallback callback) { + v8::Local context = isolate()->GetCurrentContext(); v8::Local function = - NewFunctionTemplate(callback, - v8::Local(), + NewFunctionTemplate(callback, v8::Local(), // TODO(TimothyGu): Investigate if SetMethod is ever // used for constructors. v8::ConstructorBehavior::kAllow, - v8::SideEffectType::kHasNoSideEffect)->GetFunction(); + v8::SideEffectType::kHasNoSideEffect) + ->GetFunction(context) + .ToLocalChecked(); // kInternalized strings are created in the old space. const v8::NewStringType type = v8::NewStringType::kInternalized; v8::Local name_string = diff --git a/src/env.cc b/src/env.cc index 38fdce89d145ca..b5a7b2978cf5d4 100644 --- a/src/env.cc +++ b/src/env.cc @@ -212,8 +212,10 @@ void Environment::Start(int argc, auto process_template = FunctionTemplate::New(isolate()); process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate(), "process")); - auto process_object = - process_template->GetFunction()->NewInstance(context()).ToLocalChecked(); + auto process_object = process_template->GetFunction(context()) + .ToLocalChecked() + ->NewInstance(context()) + .ToLocalChecked(); set_process_object(process_object); SetupProcessObject(this, argc, argv, exec_argc, exec_argv); diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 164614ae81145f..4902e767bb492b 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -116,7 +116,7 @@ void FSEventWrap::Initialize(Local target, Local(), static_cast(ReadOnly | DontDelete | v8::DontEnum)); - target->Set(fsevent_string, t->GetFunction()); + target->Set(fsevent_string, t->GetFunction(context).ToLocalChecked()); } diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index e126bb117ad426..62a9108476ac4f 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -303,7 +303,10 @@ void Initialize(Local target, Local unused, AsyncWrap::AddWrapMethods(env, tmpl); env->SetProtoMethod(tmpl, "dispatch", JSBindingsConnection::Dispatch); env->SetProtoMethod(tmpl, "disconnect", JSBindingsConnection::Disconnect); - target->Set(env->context(), conn_str, tmpl->GetFunction()).ToChecked(); + target + ->Set(env->context(), conn_str, + tmpl->GetFunction(env->context()).ToLocalChecked()) + .ToChecked(); } } // namespace diff --git a/src/js_stream.cc b/src/js_stream.cc index 5d5a01b731381d..12448f50e2daae 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -209,7 +209,7 @@ void JSStream::Initialize(Local target, env->SetProtoMethod(t, "emitEOF", EmitEOF); StreamBase::AddMethods(env, t); - target->Set(jsStreamString, t->GetFunction()); + target->Set(jsStreamString, t->GetFunction(context).ToLocalChecked()); } } // namespace node diff --git a/src/module_wrap.cc b/src/module_wrap.cc index ab1950311ad631..8b8a32440cfa5e 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -795,7 +795,8 @@ void ModuleWrap::Initialize(Local target, env->SetProtoMethodNoSideEffect(tpl, "getStaticDependencySpecifiers", GetStaticDependencySpecifiers); - target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"), tpl->GetFunction()); + target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"), + tpl->GetFunction(context).ToLocalChecked()); env->SetMethod(target, "resolve", Resolve); env->SetMethod(target, "setImportModuleDynamicallyCallback", diff --git a/src/node.h b/src/node.h index b4252cbf5eb691..ba66d8ececbbd9 100644 --- a/src/node.h +++ b/src/node.h @@ -357,9 +357,10 @@ inline void NODE_SET_METHOD(v8::Local recv, v8::FunctionCallback callback) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope handle_scope(isolate); + v8::Local context = isolate->GetCurrentContext(); v8::Local t = v8::FunctionTemplate::New(isolate, callback); - v8::Local fn = t->GetFunction(); + v8::Local fn = t->GetFunction(context).ToLocalChecked(); v8::Local fn_name = v8::String::NewFromUtf8(isolate, name); fn->SetName(fn_name); recv->Set(fn_name, fn); diff --git a/src/node_api.cc b/src/node_api.cc index 2b57ce3930ef85..6dee09eb44a4d1 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -1125,7 +1125,9 @@ napi_status napi_define_class(napi_env env, } } - *result = v8impl::JsValueFromV8LocalValue(scope.Escape(tpl->GetFunction())); + v8::Local context = isolate->GetCurrentContext(); + *result = v8impl::JsValueFromV8LocalValue( + scope.Escape(tpl->GetFunction(context).ToLocalChecked())); if (static_property_count > 0) { std::vector static_descriptors; diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 877c6d6b571a2a..cb7cac79f240bf 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -203,7 +203,8 @@ void ContextifyContext::Init(Environment* env, Local target) { Local function_template = FunctionTemplate::New(env->isolate()); function_template->InstanceTemplate()->SetInternalFieldCount(1); - env->set_script_data_constructor_function(function_template->GetFunction()); + env->set_script_data_constructor_function( + function_template->GetFunction(env->context()).ToLocalChecked()); env->SetMethod(target, "makeContext", MakeContext); env->SetMethod(target, "isContext", IsContext); @@ -601,7 +602,8 @@ class ContextifyScript : public BaseObject { env->SetProtoMethod(script_tmpl, "runInContext", RunInContext); env->SetProtoMethod(script_tmpl, "runInThisContext", RunInThisContext); - target->Set(class_name, script_tmpl->GetFunction()); + target->Set(class_name, + script_tmpl->GetFunction(env->context()).ToLocalChecked()); env->set_script_context_constructor_template(script_tmpl); Local parsing_context_symbol = diff --git a/src/node_counters.cc b/src/node_counters.cc index 99b3b8fd8ba1ac..744bb77ac49014 100644 --- a/src/node_counters.cc +++ b/src/node_counters.cc @@ -119,7 +119,9 @@ void InitPerfCounters(Environment* env, Local target) { for (size_t i = 0; i < arraysize(tab); i++) { Local key = OneByteString(env->isolate(), tab[i].name); - Local val = env->NewFunctionTemplate(tab[i].func)->GetFunction(); + Local val = env->NewFunctionTemplate(tab[i].func) + ->GetFunction(env->context()) + .ToLocalChecked(); target->Set(key, val); } diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 84ca68a79729bc..61aac93e0ee4f4 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -365,7 +365,8 @@ void SecureContext::Initialize(Environment* env, Local target) { t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kTicketKeyIVIndex"), Integer::NewFromUnsigned(env->isolate(), kTicketKeyIVIndex)); - target->Set(secureContextString, t->GetFunction()); + target->Set(secureContextString, + t->GetFunction(env->context()).ToLocalChecked()); env->set_secure_context_constructor_template(t); } @@ -2576,7 +2577,7 @@ void CipherBase::Initialize(Environment* env, Local target) { env->SetProtoMethod(t, "setAAD", SetAAD); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "CipherBase"), - t->GetFunction()); + t->GetFunction(env->context()).ToLocalChecked()); } @@ -3166,7 +3167,8 @@ void Hmac::Initialize(Environment* env, v8::Local target) { env->SetProtoMethod(t, "update", HmacUpdate); env->SetProtoMethod(t, "digest", HmacDigest); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Hmac"), t->GetFunction()); + target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Hmac"), + t->GetFunction(env->context()).ToLocalChecked()); } @@ -3285,7 +3287,8 @@ void Hash::Initialize(Environment* env, v8::Local target) { env->SetProtoMethod(t, "update", HashUpdate); env->SetProtoMethod(t, "digest", HashDigest); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Hash"), t->GetFunction()); + target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Hash"), + t->GetFunction(env->context()).ToLocalChecked()); } @@ -3478,7 +3481,8 @@ void Sign::Initialize(Environment* env, v8::Local target) { env->SetProtoMethod(t, "update", SignUpdate); env->SetProtoMethod(t, "sign", SignFinal); - target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Sign"), t->GetFunction()); + target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Sign"), + t->GetFunction(env->context()).ToLocalChecked()); } @@ -3645,7 +3649,7 @@ void Verify::Initialize(Environment* env, v8::Local target) { env->SetProtoMethod(t, "verify", VerifyFinal); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Verify"), - t->GetFunction()); + t->GetFunction(env->context()).ToLocalChecked()); } @@ -3930,7 +3934,7 @@ void DiffieHellman::Initialize(Environment* env, Local target) { attributes); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellman"), - t->GetFunction()); + t->GetFunction(env->context()).ToLocalChecked()); Local t2 = env->NewFunctionTemplate(DiffieHellmanGroup); t2->InstanceTemplate()->SetInternalFieldCount(1); @@ -3959,7 +3963,7 @@ void DiffieHellman::Initialize(Environment* env, Local target) { attributes); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellmanGroup"), - t2->GetFunction()); + t2->GetFunction(env->context()).ToLocalChecked()); } @@ -4308,7 +4312,7 @@ void ECDH::Initialize(Environment* env, Local target) { env->SetProtoMethod(t, "setPrivateKey", SetPrivateKey); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ECDH"), - t->GetFunction()); + t->GetFunction(env->context()).ToLocalChecked()); } diff --git a/src/node_dtrace.cc b/src/node_dtrace.cc index 86aa700d2ebd91..1f9dcc663b5c7a 100644 --- a/src/node_dtrace.cc +++ b/src/node_dtrace.cc @@ -276,7 +276,9 @@ void InitDTrace(Environment* env, Local target) { for (size_t i = 0; i < arraysize(tab); i++) { Local key = OneByteString(env->isolate(), tab[i].name); - Local val = env->NewFunctionTemplate(tab[i].func)->GetFunction(); + Local val = env->NewFunctionTemplate(tab[i].func) + ->GetFunction(env->context()) + .ToLocalChecked(); target->Set(key, val); } diff --git a/src/node_file.cc b/src/node_file.cc index f08833b201b19d..901d1bfd1d8cdf 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1964,7 +1964,10 @@ void Initialize(Local target, Local wrapString = FIXED_ONE_BYTE_STRING(env->isolate(), "FSReqWrap"); fst->SetClassName(wrapString); - target->Set(context, wrapString, fst->GetFunction()).FromJust(); + target + ->Set(context, wrapString, + fst->GetFunction(env->context()).ToLocalChecked()) + .FromJust(); // Create FunctionTemplate for FileHandleReadWrap. There’s no need // to do anything in the constructor, so we only store the instance template. @@ -1998,7 +2001,10 @@ void Initialize(Local target, FIXED_ONE_BYTE_STRING(env->isolate(), "FileHandle"); fd->SetClassName(handleString); StreamBase::AddMethods(env, fd); - target->Set(context, handleString, fd->GetFunction()).FromJust(); + target + ->Set(context, handleString, + fd->GetFunction(env->context()).ToLocalChecked()) + .FromJust(); env->set_fd_constructor_template(fdt); // Create FunctionTemplate for FileHandle::CloseReq diff --git a/src/node_http2.cc b/src/node_http2.cc index 8907730b05c5ce..0da9565a4af796 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -2845,7 +2845,7 @@ void Initialize(Local target, env->set_http2stream_constructor_template(streamt); target->Set(context, FIXED_ONE_BYTE_STRING(env->isolate(), "Http2Stream"), - stream->GetFunction()).FromJust(); + stream->GetFunction(env->context()).ToLocalChecked()).FromJust(); Local session = env->NewFunctionTemplate(Http2Session::New); @@ -2872,7 +2872,7 @@ void Initialize(Local target, Http2Session::RefreshSettings); target->Set(context, http2SessionClassName, - session->GetFunction()).FromJust(); + session->GetFunction(env->context()).ToLocalChecked()).FromJust(); Local constants = Object::New(isolate); Local name_for_error_code = Array::New(isolate); diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 34b0578c856ff5..8df048a4d68a86 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -769,7 +769,7 @@ void Initialize(Local target, env->SetProtoMethod(t, "getCurrentBuffer", Parser::GetCurrentBuffer); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "HTTPParser"), - t->GetFunction()); + t->GetFunction(env->context()).ToLocalChecked()); } } // anonymous namespace diff --git a/src/node_perf.cc b/src/node_perf.cc index 900fbb4c9db528..d39af10079041f 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -397,7 +397,7 @@ void Initialize(Local target, Local pe = FunctionTemplate::New(isolate); pe->SetClassName(performanceEntryString); - Local fn = pe->GetFunction(); + Local fn = pe->GetFunction(context).ToLocalChecked(); target->Set(context, performanceEntryString, fn).FromJust(); env->set_performance_entry_template(fn); diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index 767bc024e46be1..bd7b58fe4ae03e 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -58,7 +58,8 @@ void StatWatcher::Initialize(Environment* env, Local target) { env->SetProtoMethod(t, "unref", HandleWrap::Unref); env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef); - target->Set(statWatcherString, t->GetFunction()); + target->Set(statWatcherString, + t->GetFunction(env->context()).ToLocalChecked()); } diff --git a/src/node_trace_events.cc b/src/node_trace_events.cc index 985c706dc4a2f1..b545d0b05a9971 100644 --- a/src/node_trace_events.cc +++ b/src/node_trace_events.cc @@ -226,7 +226,7 @@ void Initialize(Local target, env->SetProtoMethod(category_set, "disable", NodeCategorySet::Disable); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "CategorySet"), - category_set->GetFunction()); + category_set->GetFunction(env->context()).ToLocalChecked()); } } // namespace node diff --git a/src/node_worker.cc b/src/node_worker.cc index af7b3d7ab92fa5..a401c6a6ffdf56 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -441,7 +441,7 @@ void InitWorker(Local target, Local workerString = FIXED_ONE_BYTE_STRING(env->isolate(), "Worker"); w->SetClassName(workerString); - target->Set(workerString, w->GetFunction()); + target->Set(workerString, w->GetFunction(env->context()).ToLocalChecked()); } env->SetMethod(target, "getEnvMessagePort", GetEnvMessagePort); diff --git a/src/node_zlib.cc b/src/node_zlib.cc index c1cc9dce277d1b..4d5e7a81483fca 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -757,7 +757,7 @@ void Initialize(Local target, Local zlibString = FIXED_ONE_BYTE_STRING(env->isolate(), "Zlib"); z->SetClassName(zlibString); - target->Set(zlibString, z->GetFunction()); + target->Set(zlibString, z->GetFunction(env->context()).ToLocalChecked()); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ZLIB_VERSION"), FIXED_ONE_BYTE_STRING(env->isolate(), ZLIB_VERSION)); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index e1e9d0c574baa0..791897cbcadeeb 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -57,7 +57,9 @@ Local PipeWrap::Instantiate(Environment* env, EscapableHandleScope handle_scope(env->isolate()); AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent); CHECK_EQ(false, env->pipe_constructor_template().IsEmpty()); - Local constructor = env->pipe_constructor_template()->GetFunction(); + Local constructor = env->pipe_constructor_template() + ->GetFunction(env->context()) + .ToLocalChecked(); CHECK_EQ(false, constructor.IsEmpty()); Local type_value = Int32::New(env->isolate(), type); Local instance = @@ -96,7 +98,7 @@ void PipeWrap::Initialize(Local target, env->SetProtoMethod(t, "fchmod", Fchmod); - target->Set(pipeString, t->GetFunction()); + target->Set(pipeString, t->GetFunction(env->context()).ToLocalChecked()); env->set_pipe_constructor_template(t); // Create FunctionTemplate for PipeConnectWrap. @@ -105,7 +107,7 @@ void PipeWrap::Initialize(Local target, Local wrapString = FIXED_ONE_BYTE_STRING(env->isolate(), "PipeConnectWrap"); cwt->SetClassName(wrapString); - target->Set(wrapString, cwt->GetFunction()); + target->Set(wrapString, cwt->GetFunction(env->context()).ToLocalChecked()); // Define constants Local constants = Object::New(env->isolate()); diff --git a/src/process_wrap.cc b/src/process_wrap.cc index f58ff1635da23e..7da9e05b96f3ec 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -68,7 +68,8 @@ class ProcessWrap : public HandleWrap { env->SetProtoMethod(constructor, "unref", HandleWrap::Unref); env->SetProtoMethod(constructor, "hasRef", HandleWrap::HasRef); - target->Set(processString, constructor->GetFunction()); + target->Set(processString, + constructor->GetFunction(env->context()).ToLocalChecked()); } size_t self_size() const override { return sizeof(*this); } diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc index 1e7a4ea3eb3be8..85ccfe52032865 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -59,7 +59,8 @@ class SignalWrap : public HandleWrap { env->SetProtoMethod(constructor, "start", Start); env->SetProtoMethod(constructor, "stop", Stop); - target->Set(signalString, constructor->GetFunction()); + target->Set(signalString, + constructor->GetFunction(env->context()).ToLocalChecked()); } size_t self_size() const override { return sizeof(*this); } diff --git a/src/stream_pipe.cc b/src/stream_pipe.cc index bfe7d4297257a0..b99c6e35e6c4cf 100644 --- a/src/stream_pipe.cc +++ b/src/stream_pipe.cc @@ -255,7 +255,10 @@ void InitializeStreamPipe(Local target, AsyncWrap::AddWrapMethods(env, pipe); pipe->SetClassName(stream_pipe_string); pipe->InstanceTemplate()->SetInternalFieldCount(1); - target->Set(context, stream_pipe_string, pipe->GetFunction()).FromJust(); + target + ->Set(context, stream_pipe_string, + pipe->GetFunction(context).ToLocalChecked()) + .FromJust(); } } // anonymous namespace diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 2dea245fd1dddc..55740c058a024a 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -68,7 +68,7 @@ void LibuvStreamWrap::Initialize(Local target, FIXED_ONE_BYTE_STRING(env->isolate(), "ShutdownWrap"); sw->SetClassName(wrapString); AsyncWrap::AddWrapMethods(env, sw); - target->Set(wrapString, sw->GetFunction()); + target->Set(wrapString, sw->GetFunction(env->context()).ToLocalChecked()); env->set_shutdown_wrap_template(sw->InstanceTemplate()); Local ww = @@ -78,7 +78,8 @@ void LibuvStreamWrap::Initialize(Local target, FIXED_ONE_BYTE_STRING(env->isolate(), "WriteWrap"); ww->SetClassName(writeWrapString); AsyncWrap::AddWrapMethods(env, ww); - target->Set(writeWrapString, ww->GetFunction()); + target->Set(writeWrapString, + ww->GetFunction(env->context()).ToLocalChecked()); env->set_write_wrap_template(ww->InstanceTemplate()); } diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index efd66da02b290a..a440321d02cf1e 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -59,7 +59,9 @@ Local TCPWrap::Instantiate(Environment* env, EscapableHandleScope handle_scope(env->isolate()); AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent); CHECK_EQ(env->tcp_constructor_template().IsEmpty(), false); - Local constructor = env->tcp_constructor_template()->GetFunction(); + Local constructor = env->tcp_constructor_template() + ->GetFunction(env->context()) + .ToLocalChecked(); CHECK_EQ(constructor.IsEmpty(), false); Local type_value = Int32::New(env->isolate(), type); Local instance = @@ -112,7 +114,7 @@ void TCPWrap::Initialize(Local target, env->SetProtoMethod(t, "setSimultaneousAccepts", SetSimultaneousAccepts); #endif - target->Set(tcpString, t->GetFunction()); + target->Set(tcpString, t->GetFunction(env->context()).ToLocalChecked()); env->set_tcp_constructor_template(t); // Create FunctionTemplate for TCPConnectWrap. @@ -122,7 +124,7 @@ void TCPWrap::Initialize(Local target, Local wrapString = FIXED_ONE_BYTE_STRING(env->isolate(), "TCPConnectWrap"); cwt->SetClassName(wrapString); - target->Set(wrapString, cwt->GetFunction()); + target->Set(wrapString, cwt->GetFunction(env->context()).ToLocalChecked()); // Define constants Local constants = Object::New(env->isolate()); diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 53ab0a6eaca2d0..36f475a0039725 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -63,12 +63,16 @@ class TimerWrap : public HandleWrap { env->SetProtoMethod(constructor, "start", Start); - target->Set(timerString, constructor->GetFunction()); - - target->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "setupTimers"), - env->NewFunctionTemplate(SetupTimers) - ->GetFunction(env->context()).ToLocalChecked()).FromJust(); + target->Set(timerString, + constructor->GetFunction(env->context()).ToLocalChecked()); + + target + ->Set(env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), "setupTimers"), + env->NewFunctionTemplate(SetupTimers) + ->GetFunction(env->context()) + .ToLocalChecked()) + .FromJust(); } size_t self_size() const override { return sizeof(*this); } @@ -85,9 +89,9 @@ class TimerWrap : public HandleWrap { auto toggle_ref_cb = [] (const FunctionCallbackInfo& args) { Environment::GetCurrent(args)->ToggleImmediateRef(args[0]->IsTrue()); }; - auto toggle_ref_function = - env->NewFunctionTemplate(toggle_ref_cb)->GetFunction(env->context()) - .ToLocalChecked(); + auto toggle_ref_function = env->NewFunctionTemplate(toggle_ref_cb) + ->GetFunction(env->context()) + .ToLocalChecked(); auto result = Array::New(env->isolate(), 2); result->Set(env->context(), 0, env->immediate_info()->fields().GetJSArray()).FromJust(); diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index e731c0c130216b..bf46d2ac4dcf1a 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -901,9 +901,10 @@ void TLSWrap::Initialize(Local target, env->SetProtoMethod(t, "getServername", GetServername); env->SetProtoMethod(t, "setServername", SetServername); - env->set_tls_wrap_constructor_function(t->GetFunction()); + env->set_tls_wrap_constructor_function( + t->GetFunction(env->context()).ToLocalChecked()); - target->Set(tlsWrapString, t->GetFunction()); + target->Set(tlsWrapString, t->GetFunction(env->context()).ToLocalChecked()); } } // namespace node diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index dd9d50cb3c88c6..d92091c9c8b4c1 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -68,7 +68,7 @@ void TTYWrap::Initialize(Local target, env->SetMethodNoSideEffect(target, "isTTY", IsTTY); env->SetMethodNoSideEffect(target, "guessHandleType", GuessHandleType); - target->Set(ttyString, t->GetFunction()); + target->Set(ttyString, t->GetFunction(env->context()).ToLocalChecked()); env->set_tty_constructor_template(t); } diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 82bcfd01535c37..e920545576331e 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -135,8 +135,9 @@ void UDPWrap::Initialize(Local target, AsyncWrap::AddWrapMethods(env, t); - target->Set(udpString, t->GetFunction()); - env->set_udp_constructor_function(t->GetFunction()); + target->Set(udpString, t->GetFunction(env->context()).ToLocalChecked()); + env->set_udp_constructor_function( + t->GetFunction(env->context()).ToLocalChecked()); // Create FunctionTemplate for SendWrap Local swt = @@ -145,7 +146,8 @@ void UDPWrap::Initialize(Local target, Local sendWrapString = FIXED_ONE_BYTE_STRING(env->isolate(), "SendWrap"); swt->SetClassName(sendWrapString); - target->Set(sendWrapString, swt->GetFunction()); + target->Set(sendWrapString, + swt->GetFunction(env->context()).ToLocalChecked()); } diff --git a/src/uv.cc b/src/uv.cc index 72d05feb684fd2..1ba20446da432f 100644 --- a/src/uv.cc +++ b/src/uv.cc @@ -56,7 +56,9 @@ void Initialize(Local target, Environment* env = Environment::GetCurrent(context); Isolate* isolate = env->isolate(); target->Set(FIXED_ONE_BYTE_STRING(isolate, "errname"), - env->NewFunctionTemplate(ErrName)->GetFunction()); + env->NewFunctionTemplate(ErrName) + ->GetFunction(env->context()) + .ToLocalChecked()); #define V(name, _) NODE_DEFINE_CONSTANT(target, UV_##name); UV_ERRNO_MAP(V) diff --git a/test/addons/heap-profiler/binding.cc b/test/addons/heap-profiler/binding.cc index 09feefa66902aa..861fb5a80c4651 100644 --- a/test/addons/heap-profiler/binding.cc +++ b/test/addons/heap-profiler/binding.cc @@ -18,8 +18,11 @@ inline void Test(const v8::FunctionCallbackInfo& args) { inline void Initialize(v8::Local binding) { v8::Isolate* const isolate = binding->GetIsolate(); + v8::Local context = isolate->GetCurrentContext(); binding->Set(v8::String::NewFromUtf8(isolate, "test"), - v8::FunctionTemplate::New(isolate, Test)->GetFunction()); + v8::FunctionTemplate::New(isolate, Test) + ->GetFunction(context) + .ToLocalChecked()); } NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize) diff --git a/test/addons/new-target/binding.cc b/test/addons/new-target/binding.cc index 3ae2aca7c2ef95..21b932ae018dfd 100644 --- a/test/addons/new-target/binding.cc +++ b/test/addons/new-target/binding.cc @@ -11,8 +11,11 @@ inline void NewClass(const v8::FunctionCallbackInfo& args) { inline void Initialize(v8::Local binding) { auto isolate = binding->GetIsolate(); + auto context = isolate->GetCurrentContext(); binding->Set(v8::String::NewFromUtf8(isolate, "Class"), - v8::FunctionTemplate::New(isolate, NewClass)->GetFunction()); + v8::FunctionTemplate::New(isolate, NewClass) + ->GetFunction(context) + .ToLocalChecked()); } NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize) diff --git a/test/addons/openssl-binding/binding.cc b/test/addons/openssl-binding/binding.cc index fa40b3346a7a39..bb00f1e176d7ce 100644 --- a/test/addons/openssl-binding/binding.cc +++ b/test/addons/openssl-binding/binding.cc @@ -23,7 +23,9 @@ inline void Initialize(v8::Local exports, v8::Local context) { auto isolate = context->GetIsolate(); auto key = v8::String::NewFromUtf8(isolate, "randomBytes"); - auto value = v8::FunctionTemplate::New(isolate, RandomBytes)->GetFunction(); + auto value = v8::FunctionTemplate::New(isolate, RandomBytes) + ->GetFunction(context) + .ToLocalChecked(); assert(exports->Set(context, key, value).IsJust()); } diff --git a/test/addons/zlib-binding/binding.cc b/test/addons/zlib-binding/binding.cc index a9a8c14306c486..1d0af911115359 100644 --- a/test/addons/zlib-binding/binding.cc +++ b/test/addons/zlib-binding/binding.cc @@ -46,7 +46,9 @@ inline void Initialize(v8::Local exports, v8::Local context) { auto isolate = context->GetIsolate(); auto key = v8::String::NewFromUtf8(isolate, "compressBytes"); - auto value = v8::FunctionTemplate::New(isolate, CompressBytes)->GetFunction(); + auto value = v8::FunctionTemplate::New(isolate, CompressBytes) + ->GetFunction(context) + .ToLocalChecked(); assert(exports->Set(context, key, value).IsJust()); } diff --git a/test/cctest/test_node_postmortem_metadata.cc b/test/cctest/test_node_postmortem_metadata.cc index b911a92c0de10b..d897b819c5b129 100644 --- a/test/cctest/test_node_postmortem_metadata.cc +++ b/test/cctest/test_node_postmortem_metadata.cc @@ -120,8 +120,10 @@ TEST_F(DebugSymbolsTest, HandleWrapList) { auto obj_template = v8::FunctionTemplate::New(isolate_); obj_template->InstanceTemplate()->SetInternalFieldCount(1); - v8::Local object = - obj_template->GetFunction()->NewInstance(env.context()).ToLocalChecked(); + v8::Local object = obj_template->GetFunction(env.context()) + .ToLocalChecked() + ->NewInstance(env.context()) + .ToLocalChecked(); TestHandleWrap obj(*env, object, &handle); auto queue = reinterpret_cast((*env)->handle_wrap_queue()); @@ -147,8 +149,10 @@ TEST_F(DebugSymbolsTest, ReqWrapList) { auto obj_template = v8::FunctionTemplate::New(isolate_); obj_template->InstanceTemplate()->SetInternalFieldCount(1); - v8::Local object = - obj_template->GetFunction()->NewInstance(env.context()).ToLocalChecked(); + v8::Local object = obj_template->GetFunction(env.context()) + .ToLocalChecked() + ->NewInstance(env.context()) + .ToLocalChecked(); TestReqWrap obj(*env, object); // NOTE (mmarchini): Workaround to fix failing tests on ARM64 machines with