GeezerVison is showing github.com — src: split property helpers from node::Environment · johnhenry/node@a7e5b41
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/README.md +11-10Lines changed: 11 additions & 10 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -390,32 +390,33 @@ void Initialize(Local<Object> target, | 390 | 390 | void* priv) { | 391 | 391 | Environment* env = Environment::GetCurrent(context); | 392 | 392 |
| 393 | | - env->SetMethod(target, "getaddrinfo", GetAddrInfo); | 394 | | - env->SetMethod(target, "getnameinfo", GetNameInfo); | | 393 | + SetMethod(context, target, "getaddrinfo", GetAddrInfo); | | 394 | + SetMethod(context, target, "getnameinfo", GetNameInfo); | 395 | 395 |
| 396 | 396 | // 'SetMethodNoSideEffect' means that debuggers can safely execute this | 397 | 397 | // function for e.g. previews. | 398 | | - env->SetMethodNoSideEffect(target, "canonicalizeIP", CanonicalizeIP); | | 398 | + SetMethodNoSideEffect(context, target, "canonicalizeIP", CanonicalizeIP); | 399 | 399 |
| 400 | 400 | // ... more code ... | 401 | 401 |
| | 402 | + Isolate* isolate = env->isolate(); | 402 | 403 | // Building the `ChannelWrap` class for JS: | 403 | 404 | Local<FunctionTemplate> channel_wrap = | 404 | | - env->NewFunctionTemplate(ChannelWrap::New); | | 405 | + NewFunctionTemplate(isolate, ChannelWrap::New); | 405 | 406 | // Allow for 1 internal field, see `BaseObject` for details on this: | 406 | 407 | channel_wrap->InstanceTemplate()->SetInternalFieldCount(1); | 407 | 408 | channel_wrap->Inherit(AsyncWrap::GetConstructorTemplate(env)); | 408 | 409 |
| 409 | 410 | // 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>); | 412 | 413 | // ... | 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>); | 415 | 416 |
| 416 | | - env->SetProtoMethodNoSideEffect(channel_wrap, "getServers", GetServers); | | 417 | + SetProtoMethodNoSideEffect(isolate, channel_wrap, "getServers", GetServers); | 417 | 418 |
| 418 | | - env->SetConstructorFunction(target, "ChannelWrap", channel_wrap); | | 419 | + SetConstructorFunction(context, target, "ChannelWrap", channel_wrap); | 419 | 420 | } | 420 | 421 |
| 421 | 422 | // Run the `Initialize` function when loading this module through | |
Collapse file Copy file name to clipboardExpand all lines: src/async_wrap.cc +15-13Lines changed: 15 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -337,12 +337,14 @@ void AsyncWrap::SetCallbackTrampoline(const FunctionCallbackInfo<Value>& args) { | 337 | 337 | Local<FunctionTemplate> AsyncWrap::GetConstructorTemplate(Environment* env) { | 338 | 338 | Local<FunctionTemplate> tmpl = env->async_wrap_ctor_template(); | 339 | 339 | if (tmpl.IsEmpty()) { | 340 | | - tmpl = env->NewFunctionTemplate(nullptr); | | 340 | + Isolate* isolate = env->isolate(); | | 341 | + tmpl = NewFunctionTemplate(isolate, nullptr); | 341 | 342 | tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "AsyncWrap")); | 342 | 343 | 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); | 346 | 348 | env->set_async_wrap_ctor_template(tmpl); | 347 | 349 | } | 348 | 350 | return tmpl; | @@ -356,15 +358,15 @@ void AsyncWrap::Initialize(Local<Object> target, | 356 | 358 | Isolate* isolate = env->isolate(); | 357 | 359 | HandleScope scope(isolate); | 358 | 360 |
| 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); | 368 | 370 |
| 369 | 371 | PropertyAttribute ReadOnlyDontDelete = | 370 | 372 | static_cast<PropertyAttribute>(ReadOnly | DontDelete); | |
Collapse file Copy file name to clipboardExpand all lines: src/cares_wrap.cc +30-28Lines changed: 30 additions & 28 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1886,12 +1886,13 @@ void Initialize(Local<Object> target, | 1886 | 1886 | Local<Context> context, | 1887 | 1887 | void* priv) { | 1888 | 1888 | Environment* env = Environment::GetCurrent(context); | | 1889 | + Isolate* isolate = env->isolate(); | 1889 | 1890 |
| 1890 | | - env->SetMethod(target, "getaddrinfo", GetAddrInfo); | 1891 | | - env->SetMethod(target, "getnameinfo", GetNameInfo); | 1892 | | - env->SetMethodNoSideEffect(target, "canonicalizeIP", CanonicalizeIP); | | 1891 | + SetMethod(context, target, "getaddrinfo", GetAddrInfo); | | 1892 | + SetMethod(context, target, "getnameinfo", GetNameInfo); | | 1893 | + SetMethodNoSideEffect(context, target, "canonicalizeIP", CanonicalizeIP); | 1893 | 1894 |
| 1894 | | - env->SetMethod(target, "strerror", StrError); | | 1895 | + SetMethod(context, target, "strerror", StrError); | 1895 | 1896 |
| 1896 | 1897 | target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"), | 1897 | 1898 | Integer::New(env->isolate(), AF_INET)).Check(); | @@ -1913,44 +1914,45 @@ void Initialize(Local<Object> target, | 1913 | 1914 | Local<FunctionTemplate> aiw = | 1914 | 1915 | BaseObject::MakeLazilyInitializedJSTemplate(env); | 1915 | 1916 | aiw->Inherit(AsyncWrap::GetConstructorTemplate(env)); | 1916 | | - env->SetConstructorFunction(target, "GetAddrInfoReqWrap", aiw); | | 1917 | + SetConstructorFunction(context, target, "GetAddrInfoReqWrap", aiw); | 1917 | 1918 |
| 1918 | 1919 | Local<FunctionTemplate> niw = | 1919 | 1920 | BaseObject::MakeLazilyInitializedJSTemplate(env); | 1920 | 1921 | niw->Inherit(AsyncWrap::GetConstructorTemplate(env)); | 1921 | | - env->SetConstructorFunction(target, "GetNameInfoReqWrap", niw); | | 1922 | + SetConstructorFunction(context, target, "GetNameInfoReqWrap", niw); | 1922 | 1923 |
| 1923 | 1924 | Local<FunctionTemplate> qrw = | 1924 | 1925 | BaseObject::MakeLazilyInitializedJSTemplate(env); | 1925 | 1926 | qrw->Inherit(AsyncWrap::GetConstructorTemplate(env)); | 1926 | | - env->SetConstructorFunction(target, "QueryReqWrap", qrw); | | 1927 | + SetConstructorFunction(context, target, "QueryReqWrap", qrw); | 1927 | 1928 |
| 1928 | 1929 | Local<FunctionTemplate> channel_wrap = | 1929 | | - env->NewFunctionTemplate(ChannelWrap::New); | | 1930 | + NewFunctionTemplate(isolate, ChannelWrap::New); | 1930 | 1931 | channel_wrap->InstanceTemplate()->SetInternalFieldCount( | 1931 | 1932 | ChannelWrap::kInternalFieldCount); | 1932 | 1933 | channel_wrap->Inherit(AsyncWrap::GetConstructorTemplate(env)); | 1933 | 1934 |
| 1934 | | - env->SetProtoMethod(channel_wrap, "queryAny", Query<QueryAnyWrap>); | 1935 | | - env->SetProtoMethod(channel_wrap, "queryA", Query<QueryAWrap>); | 1936 | | - env->SetProtoMethod(channel_wrap, "queryAaaa", Query<QueryAaaaWrap>); | 1937 | | - env->SetProtoMethod(channel_wrap, "queryCaa", Query<QueryCaaWrap>); | 1938 | | - env->SetProtoMethod(channel_wrap, "queryCname", Query<QueryCnameWrap>); | 1939 | | - env->SetProtoMethod(channel_wrap, "queryMx", Query<QueryMxWrap>); | 1940 | | - env->SetProtoMethod(channel_wrap, "queryNs", Query<QueryNsWrap>); | 1941 | | - env->SetProtoMethod(channel_wrap, "queryTxt", Query<QueryTxtWrap>); | 1942 | | - env->SetProtoMethod(channel_wrap, "querySrv", Query<QuerySrvWrap>); | 1943 | | - env->SetProtoMethod(channel_wrap, "queryPtr", Query<QueryPtrWrap>); | 1944 | | - env->SetProtoMethod(channel_wrap, "queryNaptr", Query<QueryNaptrWrap>); | 1945 | | - env->SetProtoMethod(channel_wrap, "querySoa", Query<QuerySoaWrap>); | 1946 | | - env->SetProtoMethod(channel_wrap, "getHostByAddr", Query<GetHostByAddrWrap>); | 1947 | | - | 1948 | | - env->SetProtoMethodNoSideEffect(channel_wrap, "getServers", GetServers); | 1949 | | - env->SetProtoMethod(channel_wrap, "setServers", SetServers); | 1950 | | - env->SetProtoMethod(channel_wrap, "setLocalAddress", SetLocalAddress); | 1951 | | - env->SetProtoMethod(channel_wrap, "cancel", Cancel); | 1952 | | - | 1953 | | - env->SetConstructorFunction(target, "ChannelWrap", channel_wrap); | | 1935 | + SetProtoMethod(isolate, channel_wrap, "queryAny", Query<QueryAnyWrap>); | | 1936 | + SetProtoMethod(isolate, channel_wrap, "queryA", Query<QueryAWrap>); | | 1937 | + SetProtoMethod(isolate, channel_wrap, "queryAaaa", Query<QueryAaaaWrap>); | | 1938 | + SetProtoMethod(isolate, channel_wrap, "queryCaa", Query<QueryCaaWrap>); | | 1939 | + SetProtoMethod(isolate, channel_wrap, "queryCname", Query<QueryCnameWrap>); | | 1940 | + SetProtoMethod(isolate, channel_wrap, "queryMx", Query<QueryMxWrap>); | | 1941 | + SetProtoMethod(isolate, channel_wrap, "queryNs", Query<QueryNsWrap>); | | 1942 | + SetProtoMethod(isolate, channel_wrap, "queryTxt", Query<QueryTxtWrap>); | | 1943 | + SetProtoMethod(isolate, channel_wrap, "querySrv", Query<QuerySrvWrap>); | | 1944 | + SetProtoMethod(isolate, channel_wrap, "queryPtr", Query<QueryPtrWrap>); | | 1945 | + SetProtoMethod(isolate, channel_wrap, "queryNaptr", Query<QueryNaptrWrap>); | | 1946 | + SetProtoMethod(isolate, channel_wrap, "querySoa", Query<QuerySoaWrap>); | | 1947 | + SetProtoMethod( | | 1948 | + isolate, channel_wrap, "getHostByAddr", Query<GetHostByAddrWrap>); | | 1949 | + | | 1950 | + SetProtoMethodNoSideEffect(isolate, channel_wrap, "getServers", GetServers); | | 1951 | + SetProtoMethod(isolate, channel_wrap, "setServers", SetServers); | | 1952 | + SetProtoMethod(isolate, channel_wrap, "setLocalAddress", SetLocalAddress); | | 1953 | + SetProtoMethod(isolate, channel_wrap, "cancel", Cancel); | | 1954 | + | | 1955 | + SetConstructorFunction(context, target, "ChannelWrap", channel_wrap); | 1954 | 1956 | } | 1955 | 1957 |
| 1956 | 1958 | } // namespace cares_wrap | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_cipher.cc +45-32Lines changed: 45 additions & 32 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,10 +13,12 @@ namespace node { | 13 | 13 | using v8::Array; | 14 | 14 | using v8::ArrayBuffer; | 15 | 15 | using v8::BackingStore; | | 16 | +using v8::Context; | 16 | 17 | using v8::FunctionCallbackInfo; | 17 | 18 | using v8::FunctionTemplate; | 18 | 19 | using v8::HandleScope; | 19 | 20 | using v8::Int32; | | 21 | +using v8::Isolate; | 20 | 22 | using v8::Local; | 21 | 23 | using v8::Object; | 22 | 24 | using v8::Uint32; | @@ -270,43 +272,54 @@ void CipherBase::MemoryInfo(MemoryTracker* tracker) const { | 270 | 272 | } | 271 | 273 |
| 272 | 274 | 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); | 274 | 279 |
| 275 | 280 | t->InstanceTemplate()->SetInternalFieldCount( | 276 | 281 | CipherBase::kInternalFieldCount); | 277 | 282 | t->Inherit(BaseObject::GetConstructorTemplate(env)); | 278 | 283 |
| 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); | 310 | 323 |
| 311 | 324 | NODE_DEFINE_CONSTANT(target, kWebCryptoCipherEncrypt); | 312 | 325 | NODE_DEFINE_CONSTANT(target, kWebCryptoCipherDecrypt); | |
|