Skip to content

Commit 68ee8e9

Browse files
legendecasruyadorno
authored andcommittedAug 21, 2022
src: split property helpers from node::Environment
PR-URL: #44056 Backport-PR-URL: #44251 Refs: #42528 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Feng Yu <[email protected]>
1 parent e028edb commit 68ee8e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1505
-1293
lines changed
 

‎src/README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -390,32 +390,33 @@ void Initialize(Local<Object> target,
390390
void* priv) {
391391
Environment* env = Environment::GetCurrent(context);
392392

393-
env->SetMethod(target, "getaddrinfo", GetAddrInfo);
394-
env->SetMethod(target, "getnameinfo", GetNameInfo);
393+
SetMethod(context, target, "getaddrinfo", GetAddrInfo);
394+
SetMethod(context, target, "getnameinfo", GetNameInfo);
395395

396396
// 'SetMethodNoSideEffect' means that debuggers can safely execute this
397397
// function for e.g. previews.
398-
env->SetMethodNoSideEffect(target, "canonicalizeIP", CanonicalizeIP);
398+
SetMethodNoSideEffect(context, target, "canonicalizeIP", CanonicalizeIP);
399399

400400
// ... more code ...
401401

402+
Isolate* isolate = env->isolate();
402403
// Building the `ChannelWrap` class for JS:
403404
Local<FunctionTemplate> channel_wrap =
404-
env->NewFunctionTemplate(ChannelWrap::New);
405+
NewFunctionTemplate(isolate, ChannelWrap::New);
405406
// Allow for 1 internal field, see `BaseObject` for details on this:
406407
channel_wrap->InstanceTemplate()->SetInternalFieldCount(1);
407408
channel_wrap->Inherit(AsyncWrap::GetConstructorTemplate(env));
408409

409410
// Set various methods on the class (i.e. on the prototype):
410-
env->SetProtoMethod(channel_wrap, "queryAny", Query<QueryAnyWrap>);
411-
env->SetProtoMethod(channel_wrap, "queryA", Query<QueryAWrap>);
411+
SetProtoMethod(isolate, channel_wrap, "queryAny", Query<QueryAnyWrap>);
412+
SetProtoMethod(isolate, channel_wrap, "queryA", Query<QueryAWrap>);
412413
// ...
413-
env->SetProtoMethod(channel_wrap, "querySoa", Query<QuerySoaWrap>);
414-
env->SetProtoMethod(channel_wrap, "getHostByAddr", Query<GetHostByAddrWrap>);
414+
SetProtoMethod(isolate, channel_wrap, "querySoa", Query<QuerySoaWrap>);
415+
SetProtoMethod(isolate, channel_wrap, "getHostByAddr", Query<GetHostByAddrWrap>);
415416

416-
env->SetProtoMethodNoSideEffect(channel_wrap, "getServers", GetServers);
417+
SetProtoMethodNoSideEffect(isolate, channel_wrap, "getServers", GetServers);
417418

418-
env->SetConstructorFunction(target, "ChannelWrap", channel_wrap);
419+
SetConstructorFunction(context, target, "ChannelWrap", channel_wrap);
419420
}
420421

421422
// Run the `Initialize` function when loading this module through

‎src/async_wrap.cc

+15-13
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,14 @@ void AsyncWrap::SetCallbackTrampoline(const FunctionCallbackInfo<Value>& args) {
337337
Local<FunctionTemplate> AsyncWrap::GetConstructorTemplate(Environment* env) {
338338
Local<FunctionTemplate> tmpl = env->async_wrap_ctor_template();
339339
if (tmpl.IsEmpty()) {
340-
tmpl = env->NewFunctionTemplate(nullptr);
340+
Isolate* isolate = env->isolate();
341+
tmpl = NewFunctionTemplate(isolate, nullptr);
341342
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "AsyncWrap"));
342343
tmpl->Inherit(BaseObject::GetConstructorTemplate(env));
343-
env->SetProtoMethod(tmpl, "getAsyncId", AsyncWrap::GetAsyncId);
344-
env->SetProtoMethod(tmpl, "asyncReset", AsyncWrap::AsyncReset);
345-
env->SetProtoMethod(tmpl, "getProviderType", AsyncWrap::GetProviderType);
344+
SetProtoMethod(isolate, tmpl, "getAsyncId", AsyncWrap::GetAsyncId);
345+
SetProtoMethod(isolate, tmpl, "asyncReset", AsyncWrap::AsyncReset);
346+
SetProtoMethod(
347+
isolate, tmpl, "getProviderType", AsyncWrap::GetProviderType);
346348
env->set_async_wrap_ctor_template(tmpl);
347349
}
348350
return tmpl;
@@ -356,15 +358,15 @@ void AsyncWrap::Initialize(Local<Object> target,
356358
Isolate* isolate = env->isolate();
357359
HandleScope scope(isolate);
358360

359-
env->SetMethod(target, "setupHooks", SetupHooks);
360-
env->SetMethod(target, "setCallbackTrampoline", SetCallbackTrampoline);
361-
env->SetMethod(target, "pushAsyncContext", PushAsyncContext);
362-
env->SetMethod(target, "popAsyncContext", PopAsyncContext);
363-
env->SetMethod(target, "executionAsyncResource", ExecutionAsyncResource);
364-
env->SetMethod(target, "clearAsyncIdStack", ClearAsyncIdStack);
365-
env->SetMethod(target, "queueDestroyAsyncId", QueueDestroyAsyncId);
366-
env->SetMethod(target, "setPromiseHooks", SetPromiseHooks);
367-
env->SetMethod(target, "registerDestroyHook", RegisterDestroyHook);
361+
SetMethod(context, target, "setupHooks", SetupHooks);
362+
SetMethod(context, target, "setCallbackTrampoline", SetCallbackTrampoline);
363+
SetMethod(context, target, "pushAsyncContext", PushAsyncContext);
364+
SetMethod(context, target, "popAsyncContext", PopAsyncContext);
365+
SetMethod(context, target, "executionAsyncResource", ExecutionAsyncResource);
366+
SetMethod(context, target, "clearAsyncIdStack", ClearAsyncIdStack);
367+
SetMethod(context, target, "queueDestroyAsyncId", QueueDestroyAsyncId);
368+
SetMethod(context, target, "setPromiseHooks", SetPromiseHooks);
369+
SetMethod(context, target, "registerDestroyHook", RegisterDestroyHook);
368370

369371
PropertyAttribute ReadOnlyDontDelete =
370372
static_cast<PropertyAttribute>(ReadOnly | DontDelete);

0 commit comments

Comments
 (0)
Please sign in to comment.