Skip to content

Commit 70d60c4

Browse files
gahaashashseed
authored andcommitted
[cleanup][v8] Replace uses of deprecated API
1 parent c17d90b commit 70d60c4

38 files changed

+148
-80
lines changed

doc/api/addons.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ functions and returning those back to JavaScript:
632632

633633
namespace demo {
634634

635+
using v8::Context;
635636
using v8::Function;
636637
using v8::FunctionCallbackInfo;
637638
using v8::FunctionTemplate;
@@ -649,8 +650,9 @@ void MyFunction(const FunctionCallbackInfo<Value>& args) {
649650
void CreateFunction(const FunctionCallbackInfo<Value>& args) {
650651
Isolate* isolate = args.GetIsolate();
651652

653+
Local<Context> context = isolate->GetCurrentContext();
652654
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, MyFunction);
653-
Local<Function> fn = tpl->GetFunction();
655+
Local<Function> fn = tpl->GetFunction(context).ToLocalChecked();
654656

655657
// omit this to make it anonymous
656658
fn->SetName(String::NewFromUtf8(isolate, "theFunction"));
@@ -774,9 +776,10 @@ void MyObject::Init(Local<Object> exports) {
774776
// Prototype
775777
NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne);
776778

777-
constructor.Reset(isolate, tpl->GetFunction());
779+
Local<Context> context = isolate->GetCurrentContext();
780+
constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
778781
exports->Set(String::NewFromUtf8(isolate, "MyObject"),
779-
tpl->GetFunction());
782+
tpl->GetFunction(context).ToLocalChecked());
780783
}
781784

782785
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
@@ -958,7 +961,8 @@ void MyObject::Init(Isolate* isolate) {
958961
// Prototype
959962
NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne);
960963

961-
constructor.Reset(isolate, tpl->GetFunction());
964+
Local<Context> context = isolate->GetCurrentContext();
965+
constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
962966
}
963967

964968
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
@@ -2129,23 +2129,23 @@ void Initialize(Local<Object> target,
21292129
Local<String> addrInfoWrapString =
21302130
FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap");
21312131
aiw->SetClassName(addrInfoWrapString);
2132-
target->Set(addrInfoWrapString, aiw->GetFunction());
2132+
target->Set(addrInfoWrapString, aiw->GetFunction(context).ToLocalChecked());
21332133

21342134
Local<FunctionTemplate> niw =
21352135
BaseObject::MakeLazilyInitializedJSTemplate(env);
21362136
AsyncWrap::AddWrapMethods(env, niw);
21372137
Local<String> nameInfoWrapString =
21382138
FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap");
21392139
niw->SetClassName(nameInfoWrapString);
2140-
target->Set(nameInfoWrapString, niw->GetFunction());
2140+
target->Set(nameInfoWrapString, niw->GetFunction(context).ToLocalChecked());
21412141

21422142
Local<FunctionTemplate> qrw =
21432143
BaseObject::MakeLazilyInitializedJSTemplate(env);
21442144
AsyncWrap::AddWrapMethods(env, qrw);
21452145
Local<String> queryWrapString =
21462146
FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap");
21472147
qrw->SetClassName(queryWrapString);
2148-
target->Set(queryWrapString, qrw->GetFunction());
2148+
target->Set(queryWrapString, qrw->GetFunction(context).ToLocalChecked());
21492149

21502150
Local<FunctionTemplate> channel_wrap =
21512151
env->NewFunctionTemplate(ChannelWrap::New);
@@ -2172,7 +2172,8 @@ void Initialize(Local<Object> target,
21722172
Local<String> channelWrapString =
21732173
FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap");
21742174
channel_wrap->SetClassName(channelWrapString);
2175-
target->Set(channelWrapString, channel_wrap->GetFunction());
2175+
target->Set(channelWrapString,
2176+
channel_wrap->GetFunction(context).ToLocalChecked());
21762177
}
21772178

21782179
} // anonymous namespace

src/env-inl.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,13 +685,15 @@ inline v8::Local<v8::FunctionTemplate>
685685
inline void Environment::SetMethod(v8::Local<v8::Object> that,
686686
const char* name,
687687
v8::FunctionCallback callback) {
688+
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
688689
v8::Local<v8::Function> function =
689-
NewFunctionTemplate(callback,
690-
v8::Local<v8::Signature>(),
690+
NewFunctionTemplate(callback, v8::Local<v8::Signature>(),
691691
// TODO(TimothyGu): Investigate if SetMethod is ever
692692
// used for constructors.
693693
v8::ConstructorBehavior::kAllow,
694-
v8::SideEffectType::kHasSideEffect)->GetFunction();
694+
v8::SideEffectType::kHasSideEffect)
695+
->GetFunction(context)
696+
.ToLocalChecked();
695697
// kInternalized strings are created in the old space.
696698
const v8::NewStringType type = v8::NewStringType::kInternalized;
697699
v8::Local<v8::String> name_string =
@@ -703,13 +705,15 @@ inline void Environment::SetMethod(v8::Local<v8::Object> that,
703705
inline void Environment::SetMethodNoSideEffect(v8::Local<v8::Object> that,
704706
const char* name,
705707
v8::FunctionCallback callback) {
708+
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
706709
v8::Local<v8::Function> function =
707-
NewFunctionTemplate(callback,
708-
v8::Local<v8::Signature>(),
710+
NewFunctionTemplate(callback, v8::Local<v8::Signature>(),
709711
// TODO(TimothyGu): Investigate if SetMethod is ever
710712
// used for constructors.
711713
v8::ConstructorBehavior::kAllow,
712-
v8::SideEffectType::kHasNoSideEffect)->GetFunction();
714+
v8::SideEffectType::kHasNoSideEffect)
715+
->GetFunction(context)
716+
.ToLocalChecked();
713717
// kInternalized strings are created in the old space.
714718
const v8::NewStringType type = v8::NewStringType::kInternalized;
715719
v8::Local<v8::String> name_string =

src/env.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@ void Environment::Start(int argc,
212212
auto process_template = FunctionTemplate::New(isolate());
213213
process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate(), "process"));
214214

215-
auto process_object =
216-
process_template->GetFunction()->NewInstance(context()).ToLocalChecked();
215+
auto process_object = process_template->GetFunction(context())
216+
.ToLocalChecked()
217+
->NewInstance(context())
218+
.ToLocalChecked();
217219
set_process_object(process_object);
218220

219221
SetupProcessObject(this, argc, argv, exec_argc, exec_argv);

src/fs_event_wrap.cc

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

119-
target->Set(fsevent_string, t->GetFunction());
119+
target->Set(fsevent_string, t->GetFunction(context).ToLocalChecked());
120120
}
121121

122122

src/inspector_js_api.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ void Initialize(Local<Object> target, Local<Value> unused,
303303
AsyncWrap::AddWrapMethods(env, tmpl);
304304
env->SetProtoMethod(tmpl, "dispatch", JSBindingsConnection::Dispatch);
305305
env->SetProtoMethod(tmpl, "disconnect", JSBindingsConnection::Disconnect);
306-
target->Set(env->context(), conn_str, tmpl->GetFunction()).ToChecked();
306+
target
307+
->Set(env->context(), conn_str,
308+
tmpl->GetFunction(env->context()).ToLocalChecked())
309+
.ToChecked();
307310
}
308311

309312
} // namespace

src/js_stream.cc

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

211211
StreamBase::AddMethods<JSStream>(env, t);
212-
target->Set(jsStreamString, t->GetFunction());
212+
target->Set(jsStreamString, t->GetFunction(context).ToLocalChecked());
213213
}
214214

215215
} // namespace node

src/module_wrap.cc

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

798-
target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"), tpl->GetFunction());
798+
target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"),
799+
tpl->GetFunction(context).ToLocalChecked());
799800
env->SetMethod(target, "resolve", Resolve);
800801
env->SetMethod(target,
801802
"setImportModuleDynamicallyCallback",

src/node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,10 @@ inline void NODE_SET_METHOD(v8::Local<v8::Object> recv,
357357
v8::FunctionCallback callback) {
358358
v8::Isolate* isolate = v8::Isolate::GetCurrent();
359359
v8::HandleScope handle_scope(isolate);
360+
v8::Local<v8::Context> context = isolate->GetCurrentContext();
360361
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
361362
callback);
362-
v8::Local<v8::Function> fn = t->GetFunction();
363+
v8::Local<v8::Function> fn = t->GetFunction(context).ToLocalChecked();
363364
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name);
364365
fn->SetName(fn_name);
365366
recv->Set(fn_name, fn);

src/node_api.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,9 @@ napi_status napi_define_class(napi_env env,
11251125
}
11261126
}
11271127

1128-
*result = v8impl::JsValueFromV8LocalValue(scope.Escape(tpl->GetFunction()));
1128+
v8::Local<v8::Context> context = isolate->GetCurrentContext();
1129+
*result = v8impl::JsValueFromV8LocalValue(
1130+
scope.Escape(tpl->GetFunction(context).ToLocalChecked()));
11291131

11301132
if (static_property_count > 0) {
11311133
std::vector<napi_property_descriptor> static_descriptors;

0 commit comments

Comments
 (0)