Skip to content

Commit 76453f1

Browse files
gahaastargos
authored andcommitted
src: replace deprecated uses of FunctionTemplate::GetFunction
PR-URL: #22993 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 8bf004b commit 76453f1

36 files changed

+134
-71
lines changed

doc/api/addons.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ functions and returning those back to JavaScript:
635635

636636
namespace demo {
637637

638+
using v8::Context;
638639
using v8::Function;
639640
using v8::FunctionCallbackInfo;
640641
using v8::FunctionTemplate;
@@ -652,8 +653,9 @@ void MyFunction(const FunctionCallbackInfo<Value>& args) {
652653
void CreateFunction(const FunctionCallbackInfo<Value>& args) {
653654
Isolate* isolate = args.GetIsolate();
654655

656+
Local<Context> context = isolate->GetCurrentContext();
655657
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, MyFunction);
656-
Local<Function> fn = tpl->GetFunction();
658+
Local<Function> fn = tpl->GetFunction(context).ToLocalChecked();
657659

658660
// omit this to make it anonymous
659661
fn->SetName(String::NewFromUtf8(isolate, "theFunction"));
@@ -777,9 +779,10 @@ void MyObject::Init(Local<Object> exports) {
777779
// Prototype
778780
NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne);
779781

780-
constructor.Reset(isolate, tpl->GetFunction());
782+
Local<Context> context = isolate->GetCurrentContext();
783+
constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
781784
exports->Set(String::NewFromUtf8(isolate, "MyObject"),
782-
tpl->GetFunction());
785+
tpl->GetFunction(context).ToLocalChecked());
783786
}
784787

785788
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
@@ -969,7 +972,8 @@ void MyObject::Init(Isolate* isolate) {
969972
// Prototype
970973
NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne);
971974

972-
constructor.Reset(isolate, tpl->GetFunction());
975+
Local<Context> context = isolate->GetCurrentContext();
976+
constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
973977
}
974978

975979
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
@@ -1177,7 +1181,8 @@ void MyObject::Init(Isolate* isolate) {
11771181
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject"));
11781182
tpl->InstanceTemplate()->SetInternalFieldCount(1);
11791183

1180-
constructor.Reset(isolate, tpl->GetFunction());
1184+
Local<Context> context = isolate->GetCurrentContext();
1185+
constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
11811186
}
11821187

11831188
void MyObject::New(const FunctionCallbackInfo<Value>& args) {

src/cares_wrap.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,23 +2224,23 @@ void Initialize(Local<Object> target,
22242224
Local<String> addrInfoWrapString =
22252225
FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap");
22262226
aiw->SetClassName(addrInfoWrapString);
2227-
target->Set(addrInfoWrapString, aiw->GetFunction());
2227+
target->Set(addrInfoWrapString, aiw->GetFunction(context).ToLocalChecked());
22282228

22292229
Local<FunctionTemplate> niw =
22302230
BaseObject::MakeLazilyInitializedJSTemplate(env);
22312231
AsyncWrap::AddWrapMethods(env, niw);
22322232
Local<String> nameInfoWrapString =
22332233
FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap");
22342234
niw->SetClassName(nameInfoWrapString);
2235-
target->Set(nameInfoWrapString, niw->GetFunction());
2235+
target->Set(nameInfoWrapString, niw->GetFunction(context).ToLocalChecked());
22362236

22372237
Local<FunctionTemplate> qrw =
22382238
BaseObject::MakeLazilyInitializedJSTemplate(env);
22392239
AsyncWrap::AddWrapMethods(env, qrw);
22402240
Local<String> queryWrapString =
22412241
FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap");
22422242
qrw->SetClassName(queryWrapString);
2243-
target->Set(queryWrapString, qrw->GetFunction());
2243+
target->Set(queryWrapString, qrw->GetFunction(context).ToLocalChecked());
22442244

22452245
Local<FunctionTemplate> channel_wrap =
22462246
env->NewFunctionTemplate(ChannelWrap::New);
@@ -2267,7 +2267,8 @@ void Initialize(Local<Object> target,
22672267
Local<String> channelWrapString =
22682268
FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap");
22692269
channel_wrap->SetClassName(channelWrapString);
2270-
target->Set(channelWrapString, channel_wrap->GetFunction());
2270+
target->Set(channelWrapString,
2271+
channel_wrap->GetFunction(context).ToLocalChecked());
22712272
}
22722273

22732274
} // anonymous namespace

src/env-inl.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,13 +710,15 @@ inline v8::Local<v8::FunctionTemplate>
710710
inline void Environment::SetMethod(v8::Local<v8::Object> that,
711711
const char* name,
712712
v8::FunctionCallback callback) {
713+
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
713714
v8::Local<v8::Function> function =
714-
NewFunctionTemplate(callback,
715-
v8::Local<v8::Signature>(),
715+
NewFunctionTemplate(callback, v8::Local<v8::Signature>(),
716716
// TODO(TimothyGu): Investigate if SetMethod is ever
717717
// used for constructors.
718718
v8::ConstructorBehavior::kAllow,
719-
v8::SideEffectType::kHasSideEffect)->GetFunction();
719+
v8::SideEffectType::kHasSideEffect)
720+
->GetFunction(context)
721+
.ToLocalChecked();
720722
// kInternalized strings are created in the old space.
721723
const v8::NewStringType type = v8::NewStringType::kInternalized;
722724
v8::Local<v8::String> name_string =
@@ -728,13 +730,15 @@ inline void Environment::SetMethod(v8::Local<v8::Object> that,
728730
inline void Environment::SetMethodNoSideEffect(v8::Local<v8::Object> that,
729731
const char* name,
730732
v8::FunctionCallback callback) {
733+
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
731734
v8::Local<v8::Function> function =
732-
NewFunctionTemplate(callback,
733-
v8::Local<v8::Signature>(),
735+
NewFunctionTemplate(callback, v8::Local<v8::Signature>(),
734736
// TODO(TimothyGu): Investigate if SetMethod is ever
735737
// used for constructors.
736738
v8::ConstructorBehavior::kAllow,
737-
v8::SideEffectType::kHasNoSideEffect)->GetFunction();
739+
v8::SideEffectType::kHasNoSideEffect)
740+
->GetFunction(context)
741+
.ToLocalChecked();
738742
// kInternalized strings are created in the old space.
739743
const v8::NewStringType type = v8::NewStringType::kInternalized;
740744
v8::Local<v8::String> name_string =

src/env.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,10 @@ void Environment::Start(const std::vector<std::string>& args,
230230
auto process_template = FunctionTemplate::New(isolate());
231231
process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate(), "process"));
232232

233-
auto process_object =
234-
process_template->GetFunction()->NewInstance(context()).ToLocalChecked();
233+
auto process_object = process_template->GetFunction(context())
234+
.ToLocalChecked()
235+
->NewInstance(context())
236+
.ToLocalChecked();
235237
set_process_object(process_object);
236238

237239
SetupProcessObject(this, args, exec_args);

src/fs_event_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void FSEventWrap::Initialize(Local<Object> target,
121121
Local<FunctionTemplate>(),
122122
static_cast<PropertyAttribute>(ReadOnly | DontDelete | v8::DontEnum));
123123

124-
target->Set(fsevent_string, t->GetFunction());
124+
target->Set(fsevent_string, t->GetFunction(context).ToLocalChecked());
125125
}
126126

127127

src/inspector_js_api.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@ void Initialize(Local<Object> target, Local<Value> unused,
310310
AsyncWrap::AddWrapMethods(env, tmpl);
311311
env->SetProtoMethod(tmpl, "dispatch", JSBindingsConnection::Dispatch);
312312
env->SetProtoMethod(tmpl, "disconnect", JSBindingsConnection::Disconnect);
313-
target->Set(env->context(), conn_str, tmpl->GetFunction()).ToChecked();
313+
target
314+
->Set(env->context(), conn_str,
315+
tmpl->GetFunction(env->context()).ToLocalChecked())
316+
.ToChecked();
314317
}
315318

316319
} // namespace

src/js_stream.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void JSStream::Initialize(Local<Object> target,
211211
env->SetProtoMethod(t, "emitEOF", EmitEOF);
212212

213213
StreamBase::AddMethods<JSStream>(env, t);
214-
target->Set(jsStreamString, t->GetFunction());
214+
target->Set(jsStreamString, t->GetFunction(context).ToLocalChecked());
215215
}
216216

217217
} // namespace node

src/module_wrap.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,8 @@ void ModuleWrap::Initialize(Local<Object> target,
801801
env->SetProtoMethodNoSideEffect(tpl, "getStaticDependencySpecifiers",
802802
GetStaticDependencySpecifiers);
803803

804-
target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"), tpl->GetFunction());
804+
target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"),
805+
tpl->GetFunction(context).ToLocalChecked());
805806
env->SetMethod(target, "resolve", Resolve);
806807
env->SetMethod(target,
807808
"setImportModuleDynamicallyCallback",

src/node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,10 @@ inline void NODE_SET_METHOD(v8::Local<v8::Object> recv,
372372
v8::FunctionCallback callback) {
373373
v8::Isolate* isolate = v8::Isolate::GetCurrent();
374374
v8::HandleScope handle_scope(isolate);
375+
v8::Local<v8::Context> context = isolate->GetCurrentContext();
375376
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
376377
callback);
377-
v8::Local<v8::Function> fn = t->GetFunction();
378+
v8::Local<v8::Function> fn = t->GetFunction(context).ToLocalChecked();
378379
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
379380
v8::NewStringType::kInternalized).ToLocalChecked();
380381
fn->SetName(fn_name);

src/node_api.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,9 @@ napi_status napi_define_class(napi_env env,
15181518
}
15191519
}
15201520

1521-
*result = v8impl::JsValueFromV8LocalValue(scope.Escape(tpl->GetFunction()));
1521+
v8::Local<v8::Context> context = isolate->GetCurrentContext();
1522+
*result = v8impl::JsValueFromV8LocalValue(
1523+
scope.Escape(tpl->GetFunction(context).ToLocalChecked()));
15221524

15231525
if (static_property_count > 0) {
15241526
std::vector<napi_property_descriptor> static_descriptors;

0 commit comments

Comments
 (0)