Skip to content

Commit 54608d8

Browse files
legendecasrichardlau
authored andcommitted
src: split property helpers from node::Environment
PR-URL: #44056 Backport-PR-URL: #44542 Refs: #42528 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Feng Yu <F3n67u@outlook.com>
1 parent e972ff7 commit 54608d8

Some content is hidden

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

78 files changed

+1484
-1271
lines changed

src/README.md

Lines changed: 11 additions & 10 deletions
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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,14 @@ void AsyncWrap::SetCallbackTrampoline(const FunctionCallbackInfo<Value>& args) {
340340
Local<FunctionTemplate> AsyncWrap::GetConstructorTemplate(Environment* env) {
341341
Local<FunctionTemplate> tmpl = env->async_wrap_ctor_template();
342342
if (tmpl.IsEmpty()) {
343-
tmpl = env->NewFunctionTemplate(nullptr);
343+
Isolate* isolate = env->isolate();
344+
tmpl = NewFunctionTemplate(isolate, nullptr);
344345
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "AsyncWrap"));
345346
tmpl->Inherit(BaseObject::GetConstructorTemplate(env));
346-
env->SetProtoMethod(tmpl, "getAsyncId", AsyncWrap::GetAsyncId);
347-
env->SetProtoMethod(tmpl, "asyncReset", AsyncWrap::AsyncReset);
348-
env->SetProtoMethod(tmpl, "getProviderType", AsyncWrap::GetProviderType);
347+
SetProtoMethod(isolate, tmpl, "getAsyncId", AsyncWrap::GetAsyncId);
348+
SetProtoMethod(isolate, tmpl, "asyncReset", AsyncWrap::AsyncReset);
349+
SetProtoMethod(
350+
isolate, tmpl, "getProviderType", AsyncWrap::GetProviderType);
349351
env->set_async_wrap_ctor_template(tmpl);
350352
}
351353
return tmpl;
@@ -359,15 +361,15 @@ void AsyncWrap::Initialize(Local<Object> target,
359361
Isolate* isolate = env->isolate();
360362
HandleScope scope(isolate);
361363

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

372374
PropertyAttribute ReadOnlyDontDelete =
373375
static_cast<PropertyAttribute>(ReadOnly | DontDelete);

src/cares_wrap.cc

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,12 +1876,13 @@ void Initialize(Local<Object> target,
18761876
Local<Context> context,
18771877
void* priv) {
18781878
Environment* env = Environment::GetCurrent(context);
1879+
Isolate* isolate = env->isolate();
18791880

1880-
env->SetMethod(target, "getaddrinfo", GetAddrInfo);
1881-
env->SetMethod(target, "getnameinfo", GetNameInfo);
1882-
env->SetMethodNoSideEffect(target, "canonicalizeIP", CanonicalizeIP);
1881+
SetMethod(context, target, "getaddrinfo", GetAddrInfo);
1882+
SetMethod(context, target, "getnameinfo", GetNameInfo);
1883+
SetMethodNoSideEffect(context, target, "canonicalizeIP", CanonicalizeIP);
18831884

1884-
env->SetMethod(target, "strerror", StrError);
1885+
SetMethod(context, target, "strerror", StrError);
18851886

18861887
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"),
18871888
Integer::New(env->isolate(), AF_INET)).Check();
@@ -1903,44 +1904,45 @@ void Initialize(Local<Object> target,
19031904
Local<FunctionTemplate> aiw =
19041905
BaseObject::MakeLazilyInitializedJSTemplate(env);
19051906
aiw->Inherit(AsyncWrap::GetConstructorTemplate(env));
1906-
env->SetConstructorFunction(target, "GetAddrInfoReqWrap", aiw);
1907+
SetConstructorFunction(context, target, "GetAddrInfoReqWrap", aiw);
19071908

19081909
Local<FunctionTemplate> niw =
19091910
BaseObject::MakeLazilyInitializedJSTemplate(env);
19101911
niw->Inherit(AsyncWrap::GetConstructorTemplate(env));
1911-
env->SetConstructorFunction(target, "GetNameInfoReqWrap", niw);
1912+
SetConstructorFunction(context, target, "GetNameInfoReqWrap", niw);
19121913

19131914
Local<FunctionTemplate> qrw =
19141915
BaseObject::MakeLazilyInitializedJSTemplate(env);
19151916
qrw->Inherit(AsyncWrap::GetConstructorTemplate(env));
1916-
env->SetConstructorFunction(target, "QueryReqWrap", qrw);
1917+
SetConstructorFunction(context, target, "QueryReqWrap", qrw);
19171918

19181919
Local<FunctionTemplate> channel_wrap =
1919-
env->NewFunctionTemplate(ChannelWrap::New);
1920+
NewFunctionTemplate(isolate, ChannelWrap::New);
19201921
channel_wrap->InstanceTemplate()->SetInternalFieldCount(
19211922
ChannelWrap::kInternalFieldCount);
19221923
channel_wrap->Inherit(AsyncWrap::GetConstructorTemplate(env));
19231924

1924-
env->SetProtoMethod(channel_wrap, "queryAny", Query<QueryAnyWrap>);
1925-
env->SetProtoMethod(channel_wrap, "queryA", Query<QueryAWrap>);
1926-
env->SetProtoMethod(channel_wrap, "queryAaaa", Query<QueryAaaaWrap>);
1927-
env->SetProtoMethod(channel_wrap, "queryCaa", Query<QueryCaaWrap>);
1928-
env->SetProtoMethod(channel_wrap, "queryCname", Query<QueryCnameWrap>);
1929-
env->SetProtoMethod(channel_wrap, "queryMx", Query<QueryMxWrap>);
1930-
env->SetProtoMethod(channel_wrap, "queryNs", Query<QueryNsWrap>);
1931-
env->SetProtoMethod(channel_wrap, "queryTxt", Query<QueryTxtWrap>);
1932-
env->SetProtoMethod(channel_wrap, "querySrv", Query<QuerySrvWrap>);
1933-
env->SetProtoMethod(channel_wrap, "queryPtr", Query<QueryPtrWrap>);
1934-
env->SetProtoMethod(channel_wrap, "queryNaptr", Query<QueryNaptrWrap>);
1935-
env->SetProtoMethod(channel_wrap, "querySoa", Query<QuerySoaWrap>);
1936-
env->SetProtoMethod(channel_wrap, "getHostByAddr", Query<GetHostByAddrWrap>);
1937-
1938-
env->SetProtoMethodNoSideEffect(channel_wrap, "getServers", GetServers);
1939-
env->SetProtoMethod(channel_wrap, "setServers", SetServers);
1940-
env->SetProtoMethod(channel_wrap, "setLocalAddress", SetLocalAddress);
1941-
env->SetProtoMethod(channel_wrap, "cancel", Cancel);
1942-
1943-
env->SetConstructorFunction(target, "ChannelWrap", channel_wrap);
1925+
SetProtoMethod(isolate, channel_wrap, "queryAny", Query<QueryAnyWrap>);
1926+
SetProtoMethod(isolate, channel_wrap, "queryA", Query<QueryAWrap>);
1927+
SetProtoMethod(isolate, channel_wrap, "queryAaaa", Query<QueryAaaaWrap>);
1928+
SetProtoMethod(isolate, channel_wrap, "queryCaa", Query<QueryCaaWrap>);
1929+
SetProtoMethod(isolate, channel_wrap, "queryCname", Query<QueryCnameWrap>);
1930+
SetProtoMethod(isolate, channel_wrap, "queryMx", Query<QueryMxWrap>);
1931+
SetProtoMethod(isolate, channel_wrap, "queryNs", Query<QueryNsWrap>);
1932+
SetProtoMethod(isolate, channel_wrap, "queryTxt", Query<QueryTxtWrap>);
1933+
SetProtoMethod(isolate, channel_wrap, "querySrv", Query<QuerySrvWrap>);
1934+
SetProtoMethod(isolate, channel_wrap, "queryPtr", Query<QueryPtrWrap>);
1935+
SetProtoMethod(isolate, channel_wrap, "queryNaptr", Query<QueryNaptrWrap>);
1936+
SetProtoMethod(isolate, channel_wrap, "querySoa", Query<QuerySoaWrap>);
1937+
SetProtoMethod(
1938+
isolate, channel_wrap, "getHostByAddr", Query<GetHostByAddrWrap>);
1939+
1940+
SetProtoMethodNoSideEffect(isolate, channel_wrap, "getServers", GetServers);
1941+
SetProtoMethod(isolate, channel_wrap, "setServers", SetServers);
1942+
SetProtoMethod(isolate, channel_wrap, "setLocalAddress", SetLocalAddress);
1943+
SetProtoMethod(isolate, channel_wrap, "cancel", Cancel);
1944+
1945+
SetConstructorFunction(context, target, "ChannelWrap", channel_wrap);
19441946
}
19451947

19461948
} // namespace cares_wrap

src/crypto/crypto_cipher.cc

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ namespace node {
1313
using v8::Array;
1414
using v8::ArrayBuffer;
1515
using v8::BackingStore;
16+
using v8::Context;
1617
using v8::FunctionCallbackInfo;
1718
using v8::FunctionTemplate;
1819
using v8::HandleScope;
1920
using v8::Int32;
21+
using v8::Isolate;
2022
using v8::Local;
2123
using v8::Object;
2224
using v8::Uint32;
@@ -270,43 +272,54 @@ void CipherBase::MemoryInfo(MemoryTracker* tracker) const {
270272
}
271273

272274
void CipherBase::Initialize(Environment* env, Local<Object> target) {
273-
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
275+
Isolate* isolate = env->isolate();
276+
Local<Context> context = env->context();
277+
278+
Local<FunctionTemplate> t = NewFunctionTemplate(isolate, New);
274279

275280
t->InstanceTemplate()->SetInternalFieldCount(
276281
CipherBase::kInternalFieldCount);
277282
t->Inherit(BaseObject::GetConstructorTemplate(env));
278283

279-
env->SetProtoMethod(t, "init", Init);
280-
env->SetProtoMethod(t, "initiv", InitIv);
281-
env->SetProtoMethod(t, "update", Update);
282-
env->SetProtoMethod(t, "final", Final);
283-
env->SetProtoMethod(t, "setAutoPadding", SetAutoPadding);
284-
env->SetProtoMethodNoSideEffect(t, "getAuthTag", GetAuthTag);
285-
env->SetProtoMethod(t, "setAuthTag", SetAuthTag);
286-
env->SetProtoMethod(t, "setAAD", SetAAD);
287-
env->SetConstructorFunction(target, "CipherBase", t);
288-
289-
env->SetMethodNoSideEffect(target, "getSSLCiphers", GetSSLCiphers);
290-
env->SetMethodNoSideEffect(target, "getCiphers", GetCiphers);
291-
292-
env->SetMethod(target, "publicEncrypt",
293-
PublicKeyCipher::Cipher<PublicKeyCipher::kPublic,
294-
EVP_PKEY_encrypt_init,
295-
EVP_PKEY_encrypt>);
296-
env->SetMethod(target, "privateDecrypt",
297-
PublicKeyCipher::Cipher<PublicKeyCipher::kPrivate,
298-
EVP_PKEY_decrypt_init,
299-
EVP_PKEY_decrypt>);
300-
env->SetMethod(target, "privateEncrypt",
301-
PublicKeyCipher::Cipher<PublicKeyCipher::kPrivate,
302-
EVP_PKEY_sign_init,
303-
EVP_PKEY_sign>);
304-
env->SetMethod(target, "publicDecrypt",
305-
PublicKeyCipher::Cipher<PublicKeyCipher::kPublic,
306-
EVP_PKEY_verify_recover_init,
307-
EVP_PKEY_verify_recover>);
308-
309-
env->SetMethodNoSideEffect(target, "getCipherInfo", GetCipherInfo);
284+
SetProtoMethod(isolate, t, "init", Init);
285+
SetProtoMethod(isolate, t, "initiv", InitIv);
286+
SetProtoMethod(isolate, t, "update", Update);
287+
SetProtoMethod(isolate, t, "final", Final);
288+
SetProtoMethod(isolate, t, "setAutoPadding", SetAutoPadding);
289+
SetProtoMethodNoSideEffect(isolate, t, "getAuthTag", GetAuthTag);
290+
SetProtoMethod(isolate, t, "setAuthTag", SetAuthTag);
291+
SetProtoMethod(isolate, t, "setAAD", SetAAD);
292+
SetConstructorFunction(context, target, "CipherBase", t);
293+
294+
SetMethodNoSideEffect(context, target, "getSSLCiphers", GetSSLCiphers);
295+
SetMethodNoSideEffect(context, target, "getCiphers", GetCiphers);
296+
297+
SetMethod(context,
298+
target,
299+
"publicEncrypt",
300+
PublicKeyCipher::Cipher<PublicKeyCipher::kPublic,
301+
EVP_PKEY_encrypt_init,
302+
EVP_PKEY_encrypt>);
303+
SetMethod(context,
304+
target,
305+
"privateDecrypt",
306+
PublicKeyCipher::Cipher<PublicKeyCipher::kPrivate,
307+
EVP_PKEY_decrypt_init,
308+
EVP_PKEY_decrypt>);
309+
SetMethod(context,
310+
target,
311+
"privateEncrypt",
312+
PublicKeyCipher::Cipher<PublicKeyCipher::kPrivate,
313+
EVP_PKEY_sign_init,
314+
EVP_PKEY_sign>);
315+
SetMethod(context,
316+
target,
317+
"publicDecrypt",
318+
PublicKeyCipher::Cipher<PublicKeyCipher::kPublic,
319+
EVP_PKEY_verify_recover_init,
320+
EVP_PKEY_verify_recover>);
321+
322+
SetMethodNoSideEffect(context, target, "getCipherInfo", GetCipherInfo);
310323

311324
NODE_DEFINE_CONSTANT(target, kWebCryptoCipherEncrypt);
312325
NODE_DEFINE_CONSTANT(target, kWebCryptoCipherDecrypt);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy