| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e6f0680 commit 9a73413
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,6 +65,22 @@ inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback( | |||
| 65 | 65 | const v8::Local<v8::String> symbol, | |
| 66 | 66 | int argc, | |
| 67 | 67 | v8::Local<v8::Value>* argv) { | |
| 68 | + return MakeCallback(symbol.As<v8::Name>(), argc, argv); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + | ||
| 72 | + inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback( | ||
| 73 | + const v8::Local<v8::Symbol> symbol, | ||
| 74 | + int argc, | ||
| 75 | + v8::Local<v8::Value>* argv) { | ||
| 76 | + return MakeCallback(symbol.As<v8::Name>(), argc, argv); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + | ||
| 80 | + inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback( | ||
| 81 | + const v8::Local<v8::Name> symbol, | ||
| 82 | + int argc, | ||
| 83 | + v8::Local<v8::Value>* argv) { | ||
| 68 | 84 | v8::Local<v8::Value> cb_v = object()->Get(symbol); | |
| 69 | 85 | CHECK(cb_v->IsFunction()); | |
| 70 | 86 | return MakeCallback(cb_v.As<v8::Function>(), argc, argv); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,10 +158,18 @@ class AsyncWrap : public BaseObject { | |||
| 158 | 158 | v8::MaybeLocal<v8::Value> MakeCallback(const v8::Local<v8::Function> cb, | |
| 159 | 159 | int argc, | |
| 160 | 160 | v8::Local<v8::Value>* argv); | |
| 161 | + inline v8::MaybeLocal<v8::Value> MakeCallback( | ||
| 162 | + const v8::Local<v8::Symbol> symbol, | ||
| 163 | + int argc, | ||
| 164 | + v8::Local<v8::Value>* argv); | ||
| 161 | 165 | inline v8::MaybeLocal<v8::Value> MakeCallback( | |
| 162 | 166 | const v8::Local<v8::String> symbol, | |
| 163 | 167 | int argc, | |
| 164 | 168 | v8::Local<v8::Value>* argv); | |
| 169 | + inline v8::MaybeLocal<v8::Value> MakeCallback( | ||
| 170 | + const v8::Local<v8::Name> symbol, | ||
| 171 | + int argc, | ||
| 172 | + v8::Local<v8::Value>* argv); | ||
| 165 | 173 | inline v8::MaybeLocal<v8::Value> MakeCallback(uint32_t index, | |
| 166 | 174 | int argc, | |
| 167 | 175 | v8::Local<v8::Value>* argv); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ using v8::Object; | |||
| 17 | 17 | using v8::Promise; | |
| 18 | 18 | using v8::PromiseRejectEvent; | |
| 19 | 19 | using v8::PromiseRejectMessage; | |
| 20 | + using v8::String; | ||
| 20 | 21 | using v8::Value; | |
| 21 | 22 | ||
| 22 | 23 | void SetupProcessObject(const FunctionCallbackInfo<Value>& args) { | |
@@ -121,7 +122,7 @@ void SetupBootstrapObject(Environment* env, | |||
| 121 | 122 | BOOTSTRAP_METHOD(_setgroups, SetGroups); | |
| 122 | 123 | #endif // __POSIX__ && !defined(__ANDROID__) && !defined(__CloudABI__) | |
| 123 | 124 | ||
| 124 | - auto should_abort_on_uncaught_toggle = | ||
| 125 | + Local<String> should_abort_on_uncaught_toggle = | ||
| 125 | 126 | FIXED_ONE_BYTE_STRING(env->isolate(), "_shouldAbortOnUncaughtToggle"); | |
| 126 | 127 | CHECK(bootstrapper->Set(env->context(), | |
| 127 | 128 | should_abort_on_uncaught_toggle, | |
@@ -130,4 +131,21 @@ void SetupBootstrapObject(Environment* env, | |||
| 130 | 131 | } | |
| 131 | 132 | #undef BOOTSTRAP_METHOD | |
| 132 | 133 | ||
| 134 | + namespace symbols { | ||
| 135 | + | ||
| 136 | + void Initialize(Local<Object> target, | ||
| 137 | + Local<Value> unused, | ||
| 138 | + Local<Context> context) { | ||
| 139 | + Environment* env = Environment::GetCurrent(context); | ||
| 140 | + #define V(PropertyName, StringValue) \ | ||
| 141 | + target->Set(env->context(), \ | ||
| 142 | + env->PropertyName()->Name(), \ | ||
| 143 | + env->PropertyName()).FromJust(); | ||
| 144 | + PER_ISOLATE_SYMBOL_PROPERTIES(V) | ||
| 145 | + #undef V | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + } // namespace symbols | ||
| 133 | 149 | } // namespace node | |
| 150 | + | ||
| 151 | + NODE_MODULE_CONTEXT_AWARE_INTERNAL(symbols, node::symbols::Initialize) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -706,6 +706,7 @@ bool Environment::CleanupHookCallback::Equal::operator()( | |||
| 706 | 706 | } | |
| 707 | 707 | ||
| 708 | 708 | #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) | |
| 709 | + #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) | ||
| 709 | 710 | #define VS(PropertyName, StringValue) V(v8::String, PropertyName) | |
| 710 | 711 | #define V(TypeName, PropertyName) \ | |
| 711 | 712 | inline \ | |
@@ -714,21 +715,26 @@ bool Environment::CleanupHookCallback::Equal::operator()( | |||
| 714 | 715 | return const_cast<IsolateData*>(this)->PropertyName ## _.Get(isolate); \ | |
| 715 | 716 | } | |
| 716 | 717 | PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) | |
| 718 | + PER_ISOLATE_SYMBOL_PROPERTIES(VY) | ||
| 717 | 719 | PER_ISOLATE_STRING_PROPERTIES(VS) | |
| 718 | 720 | #undef V | |
| 719 | 721 | #undef VS | |
| 722 | + #undef VY | ||
| 720 | 723 | #undef VP | |
| 721 | 724 | ||
| 722 | 725 | #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) | |
| 726 | + #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) | ||
| 723 | 727 | #define VS(PropertyName, StringValue) V(v8::String, PropertyName) | |
| 724 | 728 | #define V(TypeName, PropertyName) \ | |
| 725 | 729 | inline v8::Local<TypeName> Environment::PropertyName() const { \ | |
| 726 | 730 | return isolate_data()->PropertyName(isolate()); \ | |
| 727 | 731 | } | |
| 728 | 732 | PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) | |
| 733 | + PER_ISOLATE_SYMBOL_PROPERTIES(VY) | ||
| 729 | 734 | PER_ISOLATE_STRING_PROPERTIES(VS) | |
| 730 | 735 | #undef V | |
| 731 | 736 | #undef VS | |
| 737 | + #undef VY | ||
| 732 | 738 | #undef VP | |
| 733 | 739 | ||
| 734 | 740 | #define V(PropertyName, TypeName) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ using v8::Private; | |||
| 23 | 23 | using v8::StackFrame; | |
| 24 | 24 | using v8::StackTrace; | |
| 25 | 25 | using v8::String; | |
| 26 | + using v8::Symbol; | ||
| 26 | 27 | using v8::Value; | |
| 27 | 28 | ||
| 28 | 29 | IsolateData::IsolateData(Isolate* isolate, | |
@@ -59,6 +60,18 @@ IsolateData::IsolateData(Isolate* isolate, | |||
| 59 | 60 | sizeof(StringValue) - 1).ToLocalChecked())); | |
| 60 | 61 | PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V) | |
| 61 | 62 | #undef V | |
| 63 | + #define V(PropertyName, StringValue) \ | ||
| 64 | + PropertyName ## _.Set( \ | ||
| 65 | + isolate, \ | ||
| 66 | + Symbol::New( \ | ||
| 67 | + isolate, \ | ||
| 68 | + String::NewFromOneByte( \ | ||
| 69 | + isolate, \ | ||
| 70 | + reinterpret_cast<const uint8_t*>(StringValue), \ | ||
| 71 | + v8::NewStringType::kInternalized, \ | ||
| 72 | + sizeof(StringValue) - 1).ToLocalChecked())); | ||
| 73 | + PER_ISOLATE_SYMBOL_PROPERTIES(V) | ||
| 74 | + #undef V | ||
| 62 | 75 | #define V(PropertyName, StringValue) \ | |
| 63 | 76 | PropertyName ## _.Set( \ | |
| 64 | 77 | isolate, \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -107,6 +107,11 @@ struct PackageConfig { | |||
| 107 | 107 | V(napi_env, "node:napi:env") \ | |
| 108 | 108 | V(napi_wrapper, "node:napi:wrapper") \ | |
| 109 | 109 | ||
| 110 | + // Symbols are per-isolate primitives but Environment proxies them | ||
| 111 | + // for the sake of convenience. | ||
| 112 | + #define PER_ISOLATE_SYMBOL_PROPERTIES(V) \ | ||
| 113 | + V(handle_onclose_symbol, "handle_onclose") \ | ||
| 114 | + | ||
| 110 | 115 | // Strings are per-isolate primitives but Environment proxies them | |
| 111 | 116 | // for the sake of convenience. Strings should be ASCII-only. | |
| 112 | 117 | #define PER_ISOLATE_STRING_PROPERTIES(V) \ | |
@@ -127,7 +132,6 @@ struct PackageConfig { | |||
| 127 | 132 | V(chunks_sent_since_last_write_string, "chunksSentSinceLastWrite") \ | |
| 128 | 133 | V(constants_string, "constants") \ | |
| 129 | 134 | V(oncertcb_string, "oncertcb") \ | |
| 130 | - V(onclose_string, "_onclose") \ | ||
| 131 | 135 | V(code_string, "code") \ | |
| 132 | 136 | V(cwd_string, "cwd") \ | |
| 133 | 137 | V(dest_string, "dest") \ | |
@@ -356,10 +360,12 @@ class IsolateData { | |||
| 356 | 360 | inline MultiIsolatePlatform* platform() const; | |
| 357 | 361 | ||
| 358 | 362 | #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) | |
| 363 | + #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) | ||
| 359 | 364 | #define VS(PropertyName, StringValue) V(v8::String, PropertyName) | |
| 360 | 365 | #define V(TypeName, PropertyName) \ | |
| 361 | 366 | inline v8::Local<TypeName> PropertyName(v8::Isolate* isolate) const; | |
| 362 | 367 | PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) | |
| 368 | + PER_ISOLATE_SYMBOL_PROPERTIES(VY) | ||
| 363 | 369 | PER_ISOLATE_STRING_PROPERTIES(VS) | |
| 364 | 370 | #undef V | |
| 365 | 371 | #undef VS | |
@@ -370,10 +376,12 @@ class IsolateData { | |||
| 370 | 376 | ||
| 371 | 377 | private: | |
| 372 | 378 | #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) | |
| 379 | + #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) | ||
| 373 | 380 | #define VS(PropertyName, StringValue) V(v8::String, PropertyName) | |
| 374 | 381 | #define V(TypeName, PropertyName) \ | |
| 375 | 382 | v8::Eternal<TypeName> PropertyName ## _; | |
| 376 | 383 | PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) | |
| 384 | + PER_ISOLATE_SYMBOL_PROPERTIES(VY) | ||
| 377 | 385 | PER_ISOLATE_STRING_PROPERTIES(VS) | |
| 378 | 386 | #undef V | |
| 379 | 387 | #undef VS | |
@@ -737,13 +745,16 @@ class Environment { | |||
| 737 | 745 | // Strings and private symbols are shared across shared contexts | |
| 738 | 746 | // The getters simply proxy to the per-isolate primitive. | |
| 739 | 747 | #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) | |
| 748 | + #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) | ||
| 740 | 749 | #define VS(PropertyName, StringValue) V(v8::String, PropertyName) | |
| 741 | 750 | #define V(TypeName, PropertyName) \ | |
| 742 | 751 | inline v8::Local<TypeName> PropertyName() const; | |
| 743 | 752 | PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) | |
| 753 | + PER_ISOLATE_SYMBOL_PROPERTIES(VY) | ||
| 744 | 754 | PER_ISOLATE_STRING_PROPERTIES(VS) | |
| 745 | 755 | #undef V | |
| 746 | 756 | #undef VS | |
| 757 | + #undef VY | ||
| 747 | 758 | #undef VP | |
| 748 | 759 | ||
| 749 | 760 | #define V(PropertyName, TypeName) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,7 +76,9 @@ void HandleWrap::Close(Local<Value> close_callback) { | |||
| 76 | 76 | state_ = kClosing; | |
| 77 | 77 | ||
| 78 | 78 | if (!close_callback.IsEmpty() && close_callback->IsFunction()) { | |
| 79 | - object()->Set(env()->context(), env()->onclose_string(), close_callback) | ||
| 79 | + object()->Set(env()->context(), | ||
| 80 | + env()->handle_onclose_symbol(), | ||
| 81 | + close_callback) | ||
| 80 | 82 | .FromMaybe(false); | |
| 81 | 83 | } | |
| 82 | 84 | } | |
@@ -121,9 +123,9 @@ void HandleWrap::OnClose(uv_handle_t* handle) { | |||
| 121 | 123 | ||
| 122 | 124 | wrap->OnClose(); | |
| 123 | 125 | ||
| 124 | - if (wrap->object()->Has(env->context(), env->onclose_string()) | ||
| 126 | + if (wrap->object()->Has(env->context(), env->handle_onclose_symbol()) | ||
| 125 | 127 | .FromMaybe(false)) { | |
| 126 | - wrap->MakeCallback(env->onclose_string(), 0, nullptr); | ||
| 128 | + wrap->MakeCallback(env->handle_onclose_symbol(), 0, nullptr); | ||
| 127 | 129 | } | |
| 128 | 130 | } | |
| 129 | 131 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,6 +125,7 @@ struct sockaddr; | |||
| 125 | 125 | V(stream_pipe) \ | |
| 126 | 126 | V(stream_wrap) \ | |
| 127 | 127 | V(string_decoder) \ | |
| 128 | + V(symbols) \ | ||
| 128 | 129 | V(tcp_wrap) \ | |
| 129 | 130 | V(timer_wrap) \ | |
| 130 | 131 | V(trace_events) \ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments