| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d764039 commit 44bf0f4
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -94,11 +94,21 @@ process.setUncaughtExceptionCaptureCallback = function(fn) { | |||
| 94 | 94 | throw err; | |
| 95 | 95 | }; | |
| 96 | 96 | ||
| 97 | + function topLevelDomainCallback(cb, ...args) { | ||
| 98 | + const domain = this.domain; | ||
| 99 | + if (domain) | ||
| 100 | + domain.enter(); | ||
| 101 | + const ret = Reflect.apply(cb, this, args); | ||
| 102 | + if (domain) | ||
| 103 | + domain.exit(); | ||
| 104 | + return ret; | ||
| 105 | + } | ||
| 106 | + | ||
| 97 | 107 | // It's possible to enter one domain while already inside | |
| 98 | 108 | // another one. The stack is each entered domain. | |
| 99 | 109 | const stack = []; | |
| 100 | 110 | exports._stack = stack; | |
| 101 | - process._setupDomainUse(); | ||
| 111 | + internalBinding('domain').enable(topLevelDomainCallback); | ||
| 102 | 112 | ||
| 103 | 113 | function updateExceptionCapture() { | |
| 104 | 114 | if (stack.every((domain) => domain.listenerCount('error') === 0)) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -293,6 +293,7 @@ | |||
| 293 | 293 | 'src/node_constants.cc', | |
| 294 | 294 | 'src/node_contextify.cc', | |
| 295 | 295 | 'src/node_debug_options.cc', | |
| 296 | + 'src/node_domain.cc', | ||
| 296 | 297 | 'src/node_file.cc', | |
| 297 | 298 | 'src/node_http2.cc', | |
| 298 | 299 | 'src/node_http_parser.cc', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -278,7 +278,6 @@ inline Environment::Environment(IsolateData* isolate_data, | |||
| 278 | 278 | : isolate_(context->GetIsolate()), | |
| 279 | 279 | isolate_data_(isolate_data), | |
| 280 | 280 | timer_base_(uv_now(isolate_data->event_loop())), | |
| 281 | - using_domains_(false), | ||
| 282 | 281 | printed_error_(false), | |
| 283 | 282 | trace_sync_io_(false), | |
| 284 | 283 | abort_on_uncaught_exception_(false), | |
@@ -379,14 +378,6 @@ inline uint64_t Environment::timer_base() const { | |||
| 379 | 378 | return timer_base_; | |
| 380 | 379 | } | |
| 381 | 380 | ||
| 382 | - inline bool Environment::using_domains() const { | ||
| 383 | - return using_domains_; | ||
| 384 | - } | ||
| 385 | - | ||
| 386 | - inline void Environment::set_using_domains(bool value) { | ||
| 387 | - using_domains_ = value; | ||
| 388 | - } | ||
| 389 | - | ||
| 390 | 381 | inline bool Environment::printed_error() const { | |
| 391 | 382 | return printed_error_; | |
| 392 | 383 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,7 +91,6 @@ class ModuleWrap; | |||
| 91 | 91 | V(decorated_private_symbol, "node:decorated") \ | |
| 92 | 92 | V(npn_buffer_private_symbol, "node:npnBuffer") \ | |
| 93 | 93 | V(selected_npn_buffer_private_symbol, "node:selectedNpnBuffer") \ | |
| 94 | - V(domain_private_symbol, "node:domain") \ | ||
| 95 | 94 | ||
| 96 | 95 | // Strings are per-isolate primitives but Environment proxies them | |
| 97 | 96 | // for the sake of convenience. Strings should be ASCII-only. | |
@@ -128,7 +127,6 @@ class ModuleWrap; | |||
| 128 | 127 | V(dns_soa_string, "SOA") \ | |
| 129 | 128 | V(dns_srv_string, "SRV") \ | |
| 130 | 129 | V(dns_txt_string, "TXT") \ | |
| 131 | - V(domain_string, "domain") \ | ||
| 132 | 130 | V(emit_warning_string, "emitWarning") \ | |
| 133 | 131 | V(exchange_string, "exchange") \ | |
| 134 | 132 | V(encoding_string, "encoding") \ | |
@@ -283,6 +281,7 @@ class ModuleWrap; | |||
| 283 | 281 | V(async_hooks_binding, v8::Object) \ | |
| 284 | 282 | V(buffer_prototype_object, v8::Object) \ | |
| 285 | 283 | V(context, v8::Context) \ | |
| 284 | + V(domain_callback, v8::Function) \ | ||
| 286 | 285 | V(host_import_module_dynamically_callback, v8::Function) \ | |
| 287 | 286 | V(http2ping_constructor_template, v8::ObjectTemplate) \ | |
| 288 | 287 | V(http2stream_constructor_template, v8::ObjectTemplate) \ | |
@@ -537,9 +536,6 @@ class Environment { | |||
| 537 | 536 | ||
| 538 | 537 | inline IsolateData* isolate_data() const; | |
| 539 | 538 | ||
| 540 | - inline bool using_domains() const; | ||
| 541 | - inline void set_using_domains(bool value); | ||
| 542 | - | ||
| 543 | 539 | inline bool printed_error() const; | |
| 544 | 540 | inline void set_printed_error(bool value); | |
| 545 | 541 | ||
@@ -693,7 +689,6 @@ class Environment { | |||
| 693 | 689 | AsyncHooks async_hooks_; | |
| 694 | 690 | TickInfo tick_info_; | |
| 695 | 691 | const uint64_t timer_base_; | |
| 696 | - bool using_domains_; | ||
| 697 | 692 | bool printed_error_; | |
| 698 | 693 | bool trace_sync_io_; | |
| 699 | 694 | bool abort_on_uncaught_exception_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1118,62 +1118,6 @@ bool ShouldAbortOnUncaughtException(Isolate* isolate) { | |||
| 1118 | 1118 | } | |
| 1119 | 1119 | ||
| 1120 | 1120 | ||
| 1121 | - Local<Value> GetDomainProperty(Environment* env, Local<Object> object) { | ||
| 1122 | - Local<Value> domain_v = | ||
| 1123 | - object->GetPrivate(env->context(), env->domain_private_symbol()) | ||
| 1124 | - .ToLocalChecked(); | ||
| 1125 | - if (domain_v->IsObject()) { | ||
| 1126 | - return domain_v; | ||
| 1127 | - } | ||
| 1128 | - return object->Get(env->context(), env->domain_string()).ToLocalChecked(); | ||
| 1129 | - } | ||
| 1130 | - | ||
| 1131 | - | ||
| 1132 | - void DomainEnter(Environment* env, Local<Object> object) { | ||
| 1133 | - Local<Value> domain_v = GetDomainProperty(env, object); | ||
| 1134 | - if (domain_v->IsObject()) { | ||
| 1135 | - Local<Object> domain = domain_v.As<Object>(); | ||
| 1136 | - Local<Value> enter_v = domain->Get(env->enter_string()); | ||
| 1137 | - if (enter_v->IsFunction()) { | ||
| 1138 | - if (enter_v.As<Function>()->Call(domain, 0, nullptr).IsEmpty()) { | ||
| 1139 | - FatalError("node::AsyncWrap::MakeCallback", | ||
| 1140 | - "domain enter callback threw, please report this"); | ||
| 1141 | - } | ||
| 1142 | - } | ||
| 1143 | - } | ||
| 1144 | - } | ||
| 1145 | - | ||
| 1146 | - | ||
| 1147 | - void DomainExit(Environment* env, v8::Local<v8::Object> object) { | ||
| 1148 | - Local<Value> domain_v = GetDomainProperty(env, object); | ||
| 1149 | - if (domain_v->IsObject()) { | ||
| 1150 | - Local<Object> domain = domain_v.As<Object>(); | ||
| 1151 | - Local<Value> exit_v = domain->Get(env->exit_string()); | ||
| 1152 | - if (exit_v->IsFunction()) { | ||
| 1153 | - if (exit_v.As<Function>()->Call(domain, 0, nullptr).IsEmpty()) { | ||
| 1154 | - FatalError("node::AsyncWrap::MakeCallback", | ||
| 1155 | - "domain exit callback threw, please report this"); | ||
| 1156 | - } | ||
| 1157 | - } | ||
| 1158 | - } | ||
| 1159 | - } | ||
| 1160 | - | ||
| 1161 | - void SetupDomainUse(const FunctionCallbackInfo<Value>& args) { | ||
| 1162 | - Environment* env = Environment::GetCurrent(args); | ||
| 1163 | - | ||
| 1164 | - if (env->using_domains()) | ||
| 1165 | - return; | ||
| 1166 | - env->set_using_domains(true); | ||
| 1167 | - | ||
| 1168 | - HandleScope scope(env->isolate()); | ||
| 1169 | - | ||
| 1170 | - // Do a little housekeeping. | ||
| 1171 | - env->process_object()->Delete( | ||
| 1172 | - env->context(), | ||
| 1173 | - FIXED_ONE_BYTE_STRING(args.GetIsolate(), "_setupDomainUse")).FromJust(); | ||
| 1174 | - } | ||
| 1175 | - | ||
| 1176 | - | ||
| 1177 | 1121 | void RunMicrotasks(const FunctionCallbackInfo<Value>& args) { | |
| 1178 | 1122 | args.GetIsolate()->RunMicrotasks(); | |
| 1179 | 1123 | } | |
@@ -1294,11 +1238,6 @@ InternalCallbackScope::InternalCallbackScope(Environment* env, | |||
| 1294 | 1238 | // If you hit this assertion, you forgot to enter the v8::Context first. | |
| 1295 | 1239 | CHECK_EQ(Environment::GetCurrent(env->isolate()), env); | |
| 1296 | 1240 | ||
| 1297 | - if (asyncContext.async_id == 0 && env->using_domains() && | ||
| 1298 | - !object_.IsEmpty()) { | ||
| 1299 | - DomainEnter(env, object_); | ||
| 1300 | - } | ||
| 1301 | - | ||
| 1302 | 1241 | if (asyncContext.async_id != 0) { | |
| 1303 | 1242 | // No need to check a return value because the application will exit if | |
| 1304 | 1243 | // an exception occurs. | |
@@ -1328,11 +1267,6 @@ void InternalCallbackScope::Close() { | |||
| 1328 | 1267 | AsyncWrap::EmitAfter(env_, async_context_.async_id); | |
| 1329 | 1268 | } | |
| 1330 | 1269 | ||
| 1331 | - if (async_context_.async_id == 0 && env_->using_domains() && | ||
| 1332 | - !object_.IsEmpty()) { | ||
| 1333 | - DomainExit(env_, object_); | ||
| 1334 | - } | ||
| 1335 | - | ||
| 1336 | 1270 | if (IsInnerMakeCallback()) { | |
| 1337 | 1271 | return; | |
| 1338 | 1272 | } | |
@@ -1379,7 +1313,16 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env, | |||
| 1379 | 1313 | return Undefined(env->isolate()); | |
| 1380 | 1314 | } | |
| 1381 | 1315 | ||
| 1382 | - MaybeLocal<Value> ret = callback->Call(env->context(), recv, argc, argv); | ||
| 1316 | + Local<Function> domain_cb = env->domain_callback(); | ||
| 1317 | + MaybeLocal<Value> ret; | ||
| 1318 | + if (asyncContext.async_id != 0 || domain_cb.IsEmpty() || recv.IsEmpty()) { | ||
| 1319 | + ret = callback->Call(env->context(), recv, argc, argv); | ||
| 1320 | + } else { | ||
| 1321 | + std::vector<Local<Value>> args(1 + argc); | ||
| 1322 | + args[0] = callback; | ||
| 1323 | + std::copy(&argv[0], &argv[argc], &args[1]); | ||
| 1324 | + ret = domain_cb->Call(env->context(), recv, args.size(), &args[0]); | ||
| 1325 | + } | ||
| 1383 | 1326 | ||
| 1384 | 1327 | if (ret.IsEmpty()) { | |
| 1385 | 1328 | // NOTE: For backwards compatibility with public API we return Undefined() | |
@@ -3635,7 +3578,6 @@ void SetupProcessObject(Environment* env, | |||
| 3635 | 3578 | env->SetMethod(process, "_setupProcessObject", SetupProcessObject); | |
| 3636 | 3579 | env->SetMethod(process, "_setupNextTick", SetupNextTick); | |
| 3637 | 3580 | env->SetMethod(process, "_setupPromises", SetupPromises); | |
| 3638 | - env->SetMethod(process, "_setupDomainUse", SetupDomainUse); | ||
| 3639 | 3581 | } | |
| 3640 | 3582 | ||
| 3641 | 3583 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,34 @@ | |||
| 1 | + #include "v8.h" | ||
| 2 | + #include "node_internals.h" | ||
| 3 | + | ||
| 4 | + namespace node { | ||
| 5 | + namespace domain { | ||
| 6 | + | ||
| 7 | + using v8::Context; | ||
| 8 | + using v8::Function; | ||
| 9 | + using v8::FunctionCallbackInfo; | ||
| 10 | + using v8::Local; | ||
| 11 | + using v8::Object; | ||
| 12 | + using v8::Value; | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + void Enable(const FunctionCallbackInfo<Value>& args) { | ||
| 16 | + Environment* env = Environment::GetCurrent(args); | ||
| 17 | + | ||
| 18 | + CHECK(args[0]->IsFunction()); | ||
| 19 | + | ||
| 20 | + env->set_domain_callback(args[0].As<Function>()); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + void Initialize(Local<Object> target, | ||
| 24 | + Local<Value> unused, | ||
| 25 | + Local<Context> context) { | ||
| 26 | + Environment* env = Environment::GetCurrent(context); | ||
| 27 | + | ||
| 28 | + env->SetMethod(target, "enable", Enable); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + } // namespace domain | ||
| 32 | + } // namespace node | ||
| 33 | + | ||
| 34 | + NODE_MODULE_CONTEXT_AWARE_INTERNAL(domain, node::domain::Initialize) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -104,6 +104,7 @@ struct sockaddr; | |||
| 104 | 104 | V(cares_wrap) \ | |
| 105 | 105 | V(config) \ | |
| 106 | 106 | V(contextify) \ | |
| 107 | + V(domain) \ | ||
| 107 | 108 | V(fs) \ | |
| 108 | 109 | V(fs_event_wrap) \ | |
| 109 | 110 | V(http2) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ | |||
| 22 | 22 | #include <node.h> | |
| 23 | 23 | #include <v8.h> | |
| 24 | 24 | ||
| 25 | + using v8::Boolean; | ||
| 25 | 26 | using v8::Function; | |
| 26 | 27 | using v8::FunctionCallbackInfo; | |
| 27 | 28 | using v8::Local; | |
@@ -31,11 +32,16 @@ using v8::Value; | |||
| 31 | 32 | ||
| 32 | 33 | void Method(const FunctionCallbackInfo<Value>& args) { | |
| 33 | 34 | Isolate* isolate = args.GetIsolate(); | |
| 34 | - node::MakeCallback(isolate, | ||
| 35 | - isolate->GetCurrentContext()->Global(), | ||
| 36 | - args[0].As<Function>(), | ||
| 37 | - 0, | ||
| 38 | - nullptr); | ||
| 35 | + Local<Value> params[] = { | ||
| 36 | + Boolean::New(isolate, true), | ||
| 37 | + Boolean::New(isolate, false) | ||
| 38 | + }; | ||
| 39 | + Local<Value> ret = node::MakeCallback(isolate, | ||
| 40 | + isolate->GetCurrentContext()->Global(), | ||
| 41 | + args[0].As<Function>(), | ||
| 42 | + 2, | ||
| 43 | + params); | ||
| 44 | + assert(ret->IsTrue()); | ||
| 39 | 45 | } | |
| 40 | 46 | ||
| 41 | 47 | void init(Local<Object> exports) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,7 +40,8 @@ const lines = [ | |||
| 40 | 40 | // This line shouldn't cause an assertion error. | |
| 41 | 41 | `require('${buildPath}')` + | |
| 42 | 42 | // Log output to double check callback ran. | |
| 43 | - '.method(function() { console.log(\'cb_ran\'); });', | ||
| 43 | + '.method(function(v1, v2) {' + | ||
| 44 | + 'console.log(\'cb_ran\'); return v1 === true && v2 === false; });', | ||
| 44 | 45 | ]; | |
| 45 | 46 | ||
| 46 | 47 | const dInput = new stream.Readable(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | void _register_cares_wrap() {} | |
| 6 | 6 | void _register_config() {} | |
| 7 | 7 | void _register_contextify() {} | |
| 8 | + void _register_domain() {} | ||
| 8 | 9 | void _register_fs() {} | |
| 9 | 10 | void _register_fs_event_wrap() {} | |
| 10 | 11 | void _register_http2() {} | |
| Back | FazBrowse Home | New Git URL |
0 commit comments