| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9aba288 commit d73181f
33 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -405,11 +405,7 @@ void Initialize(Local<Object> target, | |||
| 405 | 405 | ||
| 406 | 406 | env->SetProtoMethodNoSideEffect(channel_wrap, "getServers", GetServers); | |
| 407 | 407 | ||
| 408 | - Local<String> channel_wrap_string = | ||
| 409 | - FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap"); | ||
| 410 | - channel_wrap->SetClassName(channel_wrap_string); | ||
| 411 | - target->Set(env->context(), channel_wrap_string, | ||
| 412 | - channel_wrap->GetFunction(context).ToLocalChecked()).Check(); | ||
| 408 | + env->SetConstructorFunction(target, "ChannelWrap", channel_wrap); | ||
| 413 | 409 | } | |
| 414 | 410 | ||
| 415 | 411 | // Run the `Initialize` function when loading this module through | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1898,32 +1898,17 @@ void Initialize(Local<Object> target, | |||
| 1898 | 1898 | Local<FunctionTemplate> aiw = | |
| 1899 | 1899 | BaseObject::MakeLazilyInitializedJSTemplate(env); | |
| 1900 | 1900 | aiw->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
| 1901 | - Local<String> addrInfoWrapString = | ||
| 1902 | - FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap"); | ||
| 1903 | - aiw->SetClassName(addrInfoWrapString); | ||
| 1904 | - target->Set(env->context(), | ||
| 1905 | - addrInfoWrapString, | ||
| 1906 | - aiw->GetFunction(context).ToLocalChecked()).Check(); | ||
| 1901 | + env->SetConstructorFunction(target, "GetAddrInfoReqWrap", aiw); | ||
| 1907 | 1902 | ||
| 1908 | 1903 | Local<FunctionTemplate> niw = | |
| 1909 | 1904 | BaseObject::MakeLazilyInitializedJSTemplate(env); | |
| 1910 | 1905 | niw->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
| 1911 | - Local<String> nameInfoWrapString = | ||
| 1912 | - FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap"); | ||
| 1913 | - niw->SetClassName(nameInfoWrapString); | ||
| 1914 | - target->Set(env->context(), | ||
| 1915 | - nameInfoWrapString, | ||
| 1916 | - niw->GetFunction(context).ToLocalChecked()).Check(); | ||
| 1906 | + env->SetConstructorFunction(target, "GetNameInfoReqWrap", niw); | ||
| 1917 | 1907 | ||
| 1918 | 1908 | Local<FunctionTemplate> qrw = | |
| 1919 | 1909 | BaseObject::MakeLazilyInitializedJSTemplate(env); | |
| 1920 | 1910 | qrw->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
| 1921 | - Local<String> queryWrapString = | ||
| 1922 | - FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap"); | ||
| 1923 | - qrw->SetClassName(queryWrapString); | ||
| 1924 | - target->Set(env->context(), | ||
| 1925 | - queryWrapString, | ||
| 1926 | - qrw->GetFunction(context).ToLocalChecked()).Check(); | ||
| 1911 | + env->SetConstructorFunction(target, "QueryReqWrap", qrw); | ||
| 1927 | 1912 | ||
| 1928 | 1913 | Local<FunctionTemplate> channel_wrap = | |
| 1929 | 1914 | env->NewFunctionTemplate(ChannelWrap::New); | |
@@ -1950,11 +1935,7 @@ void Initialize(Local<Object> target, | |||
| 1950 | 1935 | env->SetProtoMethod(channel_wrap, "setLocalAddress", SetLocalAddress); | |
| 1951 | 1936 | env->SetProtoMethod(channel_wrap, "cancel", Cancel); | |
| 1952 | 1937 | ||
| 1953 | - Local<String> channelWrapString = | ||
| 1954 | - FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap"); | ||
| 1955 | - channel_wrap->SetClassName(channelWrapString); | ||
| 1956 | - target->Set(env->context(), channelWrapString, | ||
| 1957 | - channel_wrap->GetFunction(context).ToLocalChecked()).Check(); | ||
| 1938 | + env->SetConstructorFunction(target, "ChannelWrap", channel_wrap); | ||
| 1958 | 1939 | } | |
| 1959 | 1940 | ||
| 1960 | 1941 | } // namespace cares_wrap | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1107,6 +1107,24 @@ inline void Environment::SetInstanceMethod(v8::Local<v8::FunctionTemplate> that, | |||
| 1107 | 1107 | t->SetClassName(name_string); | |
| 1108 | 1108 | } | |
| 1109 | 1109 | ||
| 1110 | + inline void Environment::SetConstructorFunction( | ||
| 1111 | + v8::Local<v8::Object> that, | ||
| 1112 | + const char* name, | ||
| 1113 | + v8::Local<v8::FunctionTemplate> tmpl) { | ||
| 1114 | + SetConstructorFunction(that, OneByteString(isolate(), name), tmpl); | ||
| 1115 | + } | ||
| 1116 | + | ||
| 1117 | + inline void Environment::SetConstructorFunction( | ||
| 1118 | + v8::Local<v8::Object> that, | ||
| 1119 | + v8::Local<v8::String> name, | ||
| 1120 | + v8::Local<v8::FunctionTemplate> tmpl) { | ||
| 1121 | + tmpl->SetClassName(name); | ||
| 1122 | + that->Set( | ||
| 1123 | + context(), | ||
| 1124 | + name, | ||
| 1125 | + tmpl->GetFunction(context()).ToLocalChecked()).Check(); | ||
| 1126 | + } | ||
| 1127 | + | ||
| 1110 | 1128 | void Environment::AddCleanupHook(CleanupCallback fn, void* arg) { | |
| 1111 | 1129 | auto insertion_info = cleanup_hooks_.emplace(CleanupHookCallback { | |
| 1112 | 1130 | fn, arg, cleanup_hook_counter_++ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1111,6 +1111,14 @@ class Environment : public MemoryRetainer { | |||
| 1111 | 1111 | const char* name, | |
| 1112 | 1112 | v8::FunctionCallback callback); | |
| 1113 | 1113 | ||
| 1114 | + inline void SetConstructorFunction(v8::Local<v8::Object> that, | ||
| 1115 | + const char* name, | ||
| 1116 | + v8::Local<v8::FunctionTemplate> tmpl); | ||
| 1117 | + | ||
| 1118 | + inline void SetConstructorFunction(v8::Local<v8::Object> that, | ||
| 1119 | + v8::Local<v8::String> name, | ||
| 1120 | + v8::Local<v8::FunctionTemplate> tmpl); | ||
| 1121 | + | ||
| 1114 | 1122 | void AtExit(void (*cb)(void* arg), void* arg); | |
| 1115 | 1123 | void RunAtExitCallbacks(); | |
| 1116 | 1124 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,11 +95,9 @@ void FSEventWrap::Initialize(Local<Object> target, | |||
| 95 | 95 | void* priv) { | |
| 96 | 96 | Environment* env = Environment::GetCurrent(context); | |
| 97 | 97 | ||
| 98 | - auto fsevent_string = FIXED_ONE_BYTE_STRING(env->isolate(), "FSEvent"); | ||
| 99 | 98 | Local<FunctionTemplate> t = env->NewFunctionTemplate(New); | |
| 100 | 99 | t->InstanceTemplate()->SetInternalFieldCount( | |
| 101 | 100 | FSEventWrap::kInternalFieldCount); | |
| 102 | - t->SetClassName(fsevent_string); | ||
| 103 | 101 | ||
| 104 | 102 | t->Inherit(HandleWrap::GetConstructorTemplate(env)); | |
| 105 | 103 | env->SetProtoMethod(t, "start", Start); | |
@@ -116,9 +114,7 @@ void FSEventWrap::Initialize(Local<Object> target, | |||
| 116 | 114 | Local<FunctionTemplate>(), | |
| 117 | 115 | static_cast<PropertyAttribute>(ReadOnly | DontDelete | DontEnum)); | |
| 118 | 116 | ||
| 119 | - target->Set(env->context(), | ||
| 120 | - fsevent_string, | ||
| 121 | - t->GetFunction(context).ToLocalChecked()).Check(); | ||
| 117 | + env->SetConstructorFunction(target, "FSEvent", t); | ||
| 122 | 118 | } | |
| 123 | 119 | ||
| 124 | 120 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,19 +101,17 @@ class JSBindingsConnection : public AsyncWrap { | |||
| 101 | 101 | } | |
| 102 | 102 | ||
| 103 | 103 | static void Bind(Environment* env, Local<Object> target) { | |
| 104 | - Local<String> class_name = ConnectionType::GetClassName(env); | ||
| 105 | 104 | Local<FunctionTemplate> tmpl = | |
| 106 | 105 | env->NewFunctionTemplate(JSBindingsConnection::New); | |
| 107 | 106 | tmpl->InstanceTemplate()->SetInternalFieldCount( | |
| 108 | 107 | JSBindingsConnection::kInternalFieldCount); | |
| 109 | - tmpl->SetClassName(class_name); | ||
| 110 | 108 | tmpl->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
| 111 | 109 | env->SetProtoMethod(tmpl, "dispatch", JSBindingsConnection::Dispatch); | |
| 112 | 110 | env->SetProtoMethod(tmpl, "disconnect", JSBindingsConnection::Disconnect); | |
| 113 | - target->Set(env->context(), | ||
| 114 | - class_name, | ||
| 115 | - tmpl->GetFunction(env->context()).ToLocalChecked()) | ||
| 116 | - .ToChecked(); | ||
| 111 | + env->SetConstructorFunction( | ||
| 112 | + target, | ||
| 113 | + ConnectionType::GetClassName(env), | ||
| 114 | + tmpl); | ||
| 117 | 115 | } | |
| 118 | 116 | ||
| 119 | 117 | static void New(const FunctionCallbackInfo<Value>& info) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,6 @@ using v8::HandleScope; | |||
| 19 | 19 | using v8::Int32; | |
| 20 | 20 | using v8::Local; | |
| 21 | 21 | using v8::Object; | |
| 22 | - using v8::String; | ||
| 23 | 22 | using v8::Value; | |
| 24 | 23 | ||
| 25 | 24 | ||
@@ -200,9 +199,6 @@ void JSStream::Initialize(Local<Object> target, | |||
| 200 | 199 | Environment* env = Environment::GetCurrent(context); | |
| 201 | 200 | ||
| 202 | 201 | Local<FunctionTemplate> t = env->NewFunctionTemplate(New); | |
| 203 | - Local<String> jsStreamString = | ||
| 204 | - FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream"); | ||
| 205 | - t->SetClassName(jsStreamString); | ||
| 206 | 202 | t->InstanceTemplate() | |
| 207 | 203 | ->SetInternalFieldCount(StreamBase::kInternalFieldCount); | |
| 208 | 204 | t->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
@@ -213,9 +209,7 @@ void JSStream::Initialize(Local<Object> target, | |||
| 213 | 209 | env->SetProtoMethod(t, "emitEOF", EmitEOF); | |
| 214 | 210 | ||
| 215 | 211 | StreamBase::AddMethods(env, t); | |
| 216 | - target->Set(env->context(), | ||
| 217 | - jsStreamString, | ||
| 218 | - t->GetFunction(context).ToLocalChecked()).Check(); | ||
| 212 | + env->SetConstructorFunction(target, "JSStream", t); | ||
| 219 | 213 | } | |
| 220 | 214 | ||
| 221 | 215 | } // namespace node | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,6 @@ using v8::HandleScope; | |||
| 16 | 16 | using v8::Int32; | |
| 17 | 17 | using v8::Local; | |
| 18 | 18 | using v8::Object; | |
| 19 | - using v8::String; | ||
| 20 | 19 | using v8::Value; | |
| 21 | 20 | ||
| 22 | 21 | // JSUDPWrap is a testing utility used by test/common/udppair.js | |
@@ -195,9 +194,6 @@ void JSUDPWrap::Initialize(Local<Object> target, | |||
| 195 | 194 | Environment* env = Environment::GetCurrent(context); | |
| 196 | 195 | ||
| 197 | 196 | Local<FunctionTemplate> t = env->NewFunctionTemplate(New); | |
| 198 | - Local<String> js_udp_wrap_string = | ||
| 199 | - FIXED_ONE_BYTE_STRING(env->isolate(), "JSUDPWrap"); | ||
| 200 | - t->SetClassName(js_udp_wrap_string); | ||
| 201 | 197 | t->InstanceTemplate() | |
| 202 | 198 | ->SetInternalFieldCount(UDPWrapBase::kUDPWrapBaseField + 1); | |
| 203 | 199 | t->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
@@ -207,9 +203,7 @@ void JSUDPWrap::Initialize(Local<Object> target, | |||
| 207 | 203 | env->SetProtoMethod(t, "onSendDone", OnSendDone); | |
| 208 | 204 | env->SetProtoMethod(t, "onAfterBind", OnAfterBind); | |
| 209 | 205 | ||
| 210 | - target->Set(env->context(), | ||
| 211 | - js_udp_wrap_string, | ||
| 212 | - t->GetFunction(context).ToLocalChecked()).Check(); | ||
| 206 | + env->SetConstructorFunction(target, "JSUDPWrap", t); | ||
| 213 | 207 | } | |
| 214 | 208 | ||
| 215 | 209 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -733,10 +733,8 @@ void ModuleWrap::Initialize(Local<Object> target, | |||
| 733 | 733 | Local<Context> context, | |
| 734 | 734 | void* priv) { | |
| 735 | 735 | Environment* env = Environment::GetCurrent(context); | |
| 736 | - Isolate* isolate = env->isolate(); | ||
| 737 | 736 | ||
| 738 | 737 | Local<FunctionTemplate> tpl = env->NewFunctionTemplate(New); | |
| 739 | - tpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap")); | ||
| 740 | 738 | tpl->InstanceTemplate()->SetInternalFieldCount( | |
| 741 | 739 | ModuleWrap::kInternalFieldCount); | |
| 742 | 740 | tpl->Inherit(BaseObject::GetConstructorTemplate(env)); | |
@@ -752,8 +750,8 @@ void ModuleWrap::Initialize(Local<Object> target, | |||
| 752 | 750 | env->SetProtoMethodNoSideEffect(tpl, "getStaticDependencySpecifiers", | |
| 753 | 751 | GetStaticDependencySpecifiers); | |
| 754 | 752 | ||
| 755 | - target->Set(env->context(), FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"), | ||
| 756 | - tpl->GetFunction(context).ToLocalChecked()).Check(); | ||
| 753 | + env->SetConstructorFunction(target, "ModuleWrap", tpl); | ||
| 754 | + | ||
| 757 | 755 | env->SetMethod(target, | |
| 758 | 756 | "setImportModuleDynamicallyCallback", | |
| 759 | 757 | SetImportModuleDynamicallyCallback); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1292,21 +1292,11 @@ void MicrotaskQueueWrap::New(const FunctionCallbackInfo<Value>& args) { | |||
| 1292 | 1292 | ||
| 1293 | 1293 | void MicrotaskQueueWrap::Init(Environment* env, Local<Object> target) { | |
| 1294 | 1294 | HandleScope scope(env->isolate()); | |
| 1295 | - Local<String> class_name = | ||
| 1296 | - FIXED_ONE_BYTE_STRING(env->isolate(), "MicrotaskQueue"); | ||
| 1297 | - | ||
| 1298 | 1295 | Local<FunctionTemplate> tmpl = env->NewFunctionTemplate(New); | |
| 1299 | 1296 | tmpl->InstanceTemplate()->SetInternalFieldCount( | |
| 1300 | 1297 | ContextifyScript::kInternalFieldCount); | |
| 1301 | - tmpl->SetClassName(class_name); | ||
| 1302 | - | ||
| 1303 | - if (target->Set(env->context(), | ||
| 1304 | - class_name, | ||
| 1305 | - tmpl->GetFunction(env->context()).ToLocalChecked()) | ||
| 1306 | - .IsNothing()) { | ||
| 1307 | - return; | ||
| 1308 | - } | ||
| 1309 | 1298 | env->set_microtask_queue_ctor_template(tmpl); | |
| 1299 | + env->SetConstructorFunction(target, "MicrotaskQueue", tmpl); | ||
| 1310 | 1300 | } | |
| 1311 | 1301 | ||
| 1312 | 1302 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments