-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
domain: re-implement domain over async_hook #16222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -309,7 +309,6 @@ class ModuleWrap; | |||
| V(internal_binding_cache_object, v8::Object) \ | ||||
| V(buffer_prototype_object, v8::Object) \ | ||||
| V(context, v8::Context) \ | ||||
| V(domain_array, v8::Array) \ | ||||
| V(domains_stack_array, v8::Array) \ | ||||
| V(inspector_console_api_object, v8::Object) \ | ||||
| V(module_load_list_array, v8::Array) \ | ||||
|
|
@@ -472,26 +471,6 @@ class Environment { | |||
| DISALLOW_COPY_AND_ASSIGN(AsyncCallbackScope); | ||||
| }; | ||||
|
|
||||
| class DomainFlag { | ||||
| public: | ||||
| inline uint32_t* fields(); | ||||
| inline int fields_count() const; | ||||
| inline uint32_t count() const; | ||||
|
|
||||
| private: | ||||
| friend class Environment; // So we can call the constructor. | ||||
| inline DomainFlag(); | ||||
|
|
||||
| enum Fields { | ||||
| kCount, | ||||
| kFieldsCount | ||||
| }; | ||||
|
|
||||
| uint32_t fields_[kFieldsCount]; | ||||
|
|
||||
| DISALLOW_COPY_AND_ASSIGN(DomainFlag); | ||||
| }; | ||||
|
|
||||
| class TickInfo { | ||||
| public: | ||||
| inline uint32_t* fields(); | ||||
|
|
@@ -560,7 +539,6 @@ class Environment { | |||
|
|
||||
| inline v8::Isolate* isolate() const; | ||||
| inline uv_loop_t* event_loop() const; | ||||
| inline bool in_domain() const; | ||||
| inline uint32_t watched_providers() const; | ||||
|
|
||||
| static inline Environment* from_immediate_check_handle(uv_check_t* handle); | ||||
|
|
@@ -577,7 +555,6 @@ class Environment { | |||
| inline void FinishHandleCleanup(uv_handle_t* handle); | ||||
|
|
||||
| inline AsyncHooks* async_hooks(); | ||||
| inline DomainFlag* domain_flag(); | ||||
|
||||
| class DomainFlag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,7 +160,6 @@ using v8::Number; | |
| using v8::Object; | ||
| using v8::ObjectTemplate; | ||
| using v8::Promise; | ||
| using v8::PromiseHookType; | ||
| using v8::PromiseRejectMessage; | ||
| using v8::PropertyCallbackInfo; | ||
| using v8::ScriptOrigin; | ||
|
|
@@ -842,7 +841,6 @@ bool ShouldAbortOnUncaughtException(Isolate* isolate) { | |
| return isEmittingTopLevelDomainError || !DomainsStackHasErrorHandler(env); | ||
|
||
| } | ||
|
|
||
|
|
||
| Local<Value> GetDomainProperty(Environment* env, Local<Object> object) { | ||
| Local<Value> domain_v = | ||
| object->GetPrivate(env->context(), env->domain_private_symbol()) | ||
|
|
@@ -883,36 +881,6 @@ void DomainExit(Environment* env, v8::Local<v8::Object> object) { | |
| } | ||
| } | ||
|
|
||
|
|
||
| void DomainPromiseHook(PromiseHookType type, | ||
| Local<Promise> promise, | ||
| Local<Value> parent, | ||
| void* arg) { | ||
| Environment* env = static_cast<Environment*>(arg); | ||
| Local<Context> context = env->context(); | ||
|
|
||
| if (type == PromiseHookType::kInit && env->in_domain()) { | ||
| Local<Value> domain_obj = | ||
| env->domain_array()->Get(context, 0).ToLocalChecked(); | ||
| if (promise->CreationContext() == context) { | ||
| promise->Set(context, env->domain_string(), domain_obj).FromJust(); | ||
| } else { | ||
| // Do not expose object from another context publicly in promises created | ||
| // in non-main contexts. | ||
| promise->SetPrivate(context, env->domain_private_symbol(), domain_obj) | ||
| .FromJust(); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| if (type == PromiseHookType::kBefore) { | ||
| DomainEnter(env, promise); | ||
| } else if (type == PromiseHookType::kAfter) { | ||
| DomainExit(env, promise); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| void SetupDomainUse(const FunctionCallbackInfo<Value>& args) { | ||
| Environment* env = Environment::GetCurrent(args); | ||
|
|
||
|
|
@@ -923,38 +891,13 @@ void SetupDomainUse(const FunctionCallbackInfo<Value>& args) { | |
| HandleScope scope(env->isolate()); | ||
| Local<Object> process_object = env->process_object(); | ||
|
|
||
| Local<String> tick_callback_function_key = env->tick_domain_cb_string(); | ||
| Local<Function> tick_callback_function = | ||
| process_object->Get(tick_callback_function_key).As<Function>(); | ||
|
|
||
| if (!tick_callback_function->IsFunction()) { | ||
| fprintf(stderr, "process._tickDomainCallback assigned to non-function\n"); | ||
| ABORT(); | ||
| } | ||
|
|
||
| process_object->Set(env->tick_callback_string(), tick_callback_function); | ||
| env->set_tick_callback_function(tick_callback_function); | ||
|
|
||
| CHECK(args[0]->IsArray()); | ||
| env->set_domain_array(args[0].As<Array>()); | ||
|
||
|
|
||
| CHECK(args[1]->IsArray()); | ||
| env->set_domains_stack_array(args[1].As<Array>()); | ||
| env->set_domains_stack_array(args[0].As<Array>()); | ||
|
|
||
| // Do a little housekeeping. | ||
| env->process_object()->Delete( | ||
| env->context(), | ||
| FIXED_ONE_BYTE_STRING(args.GetIsolate(), "_setupDomainUse")).FromJust(); | ||
|
|
||
| uint32_t* const fields = env->domain_flag()->fields(); | ||
|
||
| uint32_t const fields_count = env->domain_flag()->fields_count(); | ||
|
|
||
| Local<ArrayBuffer> array_buffer = | ||
|
||
| ArrayBuffer::New(env->isolate(), fields, sizeof(*fields) * fields_count); | ||
|
|
||
| env->AddPromiseHook(DomainPromiseHook, static_cast<void*>(env)); | ||
|
|
||
| args.GetReturnValue().Set(Uint32Array::New(array_buffer, 0, fields_count)); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -1078,7 +1021,8 @@ InternalCallbackScope::InternalCallbackScope(Environment* env, | |
| // If you hit this assertion, you forgot to enter the v8::Context first. | ||
| CHECK_EQ(Environment::GetCurrent(env->isolate()), env); | ||
|
|
||
| if (env->using_domains() && !object_.IsEmpty()) { | ||
| if (asyncContext.async_id == 0 && env->using_domains() && | ||
| !object_.IsEmpty()) { | ||
| DomainEnter(env, object_); | ||
| } | ||
|
|
||
|
|
@@ -1111,7 +1055,8 @@ void InternalCallbackScope::Close() { | |
| AsyncWrap::EmitAfter(env_, async_context_.async_id); | ||
| } | ||
|
|
||
| if (env_->using_domains() && !object_.IsEmpty()) { | ||
| if (async_context_.async_id == 0 && env_->using_domains() && | ||
| !object_.IsEmpty()) { | ||
| DomainExit(env_, object_); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically changing this to ES6 style classes is API breaking. We are likely going to land this in node 9 anyway so it shouldn't be a problem. Just as a note.