GeezerVison is showing github.com — src: remove `AddPromiseHook()` · nodejs/node@96c3224
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/api/hooks.cc -6Lines changed: 0 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -65,12 +65,6 @@ int EmitExit(Environment* env) { | 65 | 65 | .ToChecked(); | 66 | 66 | } | 67 | 67 |
| 68 | | -void AddPromiseHook(Isolate* isolate, promise_hook_func fn, void* arg) { | 69 | | - Environment* env = Environment::GetCurrent(isolate); | 70 | | - CHECK_NOT_NULL(env); | 71 | | - env->AddPromiseHook(fn, arg); | 72 | | -} | 73 | | - | 74 | 68 | void AddEnvironmentCleanupHook(Isolate* isolate, | 75 | 69 | void (*fun)(void* arg), | 76 | 70 | void* arg) { | |
Collapse file Copy file name to clipboardExpand all lines: src/async_wrap.cc +17-9Lines changed: 17 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -227,8 +227,14 @@ static PromiseWrap* extractPromiseWrap(Local<Promise> promise) { | 227 | 227 | } | 228 | 228 |
| 229 | 229 | static void PromiseHook(PromiseHookType type, Local<Promise> promise, | 230 | | - Local<Value> parent, void* arg) { | 231 | | - Environment* env = static_cast<Environment*>(arg); | | 230 | + Local<Value> parent) { | | 231 | + Local<Context> context = promise->CreationContext(); | | 232 | + | | 233 | + Environment* env = Environment::GetCurrent(context); | | 234 | + if (env == nullptr) return; | | 235 | + TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment), | | 236 | + "EnvPromiseHook", env); | | 237 | + | 232 | 238 | PromiseWrap* wrap = extractPromiseWrap(promise); | 233 | 239 | if (type == PromiseHookType::kInit || wrap == nullptr) { | 234 | 240 | bool silent = type != PromiseHookType::kInit; | @@ -318,20 +324,22 @@ static void SetupHooks(const FunctionCallbackInfo<Value>& args) { | 318 | 324 |
| 319 | 325 |
| 320 | 326 | static void EnablePromiseHook(const FunctionCallbackInfo<Value>& args) { | 321 | | - Environment* env = Environment::GetCurrent(args); | 322 | | - env->AddPromiseHook(PromiseHook, static_cast<void*>(env)); | | 327 | + args.GetIsolate()->SetPromiseHook(PromiseHook); | 323 | 328 | } | 324 | 329 |
| 325 | 330 |
| 326 | 331 | static void DisablePromiseHook(const FunctionCallbackInfo<Value>& args) { | 327 | | - Environment* env = Environment::GetCurrent(args); | | 332 | + Isolate* isolate = args.GetIsolate(); | 328 | 333 |
| 329 | 334 | // Delay the call to `RemovePromiseHook` because we might currently be | 330 | 335 | // between the `before` and `after` calls of a Promise. | 331 | | - env->isolate()->EnqueueMicrotask([](void* data) { | 332 | | - Environment* env = static_cast<Environment*>(data); | 333 | | - env->RemovePromiseHook(PromiseHook, data); | 334 | | - }, static_cast<void*>(env)); | | 336 | + isolate->EnqueueMicrotask([](void* data) { | | 337 | + // The per-Isolate API provides no way of knowing whether there are multiple | | 338 | + // users of the PromiseHook. That hopefully goes away when V8 introduces | | 339 | + // a per-context API. | | 340 | + Isolate* isolate = static_cast<Isolate*>(data); | | 341 | + isolate->SetPromiseHook(nullptr); | | 342 | + }, static_cast<void*>(isolate)); | 335 | 343 | } | 336 | 344 |
| 337 | 345 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/env-inl.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -286,7 +286,7 @@ inline void Environment::AssignToContext(v8::Local<v8::Context> context, | 286 | 286 | const ContextInfo& info) { | 287 | 287 | context->SetAlignedPointerInEmbedderData( | 288 | 288 | ContextEmbedderIndex::kEnvironment, this); | 289 | | - // Used by EnvPromiseHook to know that we are on a node context. | | 289 | + // Used by Environment::GetCurrent to know that we are on a node context. | 290 | 290 | context->SetAlignedPointerInEmbedderData( | 291 | 291 | ContextEmbedderIndex::kContextTag, Environment::kNodeContextTagPtr); | 292 | 292 | #if HAVE_INSPECTOR | |
Collapse file Copy file name to clipboardExpand all lines: src/env.cc -71Lines changed: 0 additions & 71 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,8 +39,6 @@ using v8::NewStringType; | 39 | 39 | using v8::Number; | 40 | 40 | using v8::Object; | 41 | 41 | using v8::Private; | 42 | | -using v8::Promise; | 43 | | -using v8::PromiseHookType; | 44 | 42 | using v8::StackFrame; | 45 | 43 | using v8::StackTrace; | 46 | 44 | using v8::String; | @@ -50,25 +48,6 @@ using v8::Undefined; | 50 | 48 | using v8::Value; | 51 | 49 | using worker::Worker; | 52 | 50 |
| 53 | | -// TODO(@jasnell): Likely useful to move this to util or node_internal to | 54 | | -// allow reuse. But since we're not reusing it yet... | 55 | | -class TraceEventScope { | 56 | | - public: | 57 | | - TraceEventScope(const char* category, | 58 | | - const char* name, | 59 | | - void* id) : category_(category), name_(name), id_(id) { | 60 | | - TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(category_, name_, id_); | 61 | | - } | 62 | | - ~TraceEventScope() { | 63 | | - TRACE_EVENT_NESTABLE_ASYNC_END0(category_, name_, id_); | 64 | | - } | 65 | | - | 66 | | - private: | 67 | | - const char* category_; | 68 | | - const char* name_; | 69 | | - void* id_; | 70 | | -}; | 71 | | - | 72 | 51 | int const Environment::kNodeContextTag = 0x6e6f64; | 73 | 52 | void* const Environment::kNodeContextTagPtr = const_cast<void*>( | 74 | 53 | static_cast<const void*>(&Environment::kNodeContextTag)); | @@ -590,56 +569,6 @@ void Environment::AtExit(void (*cb)(void* arg), void* arg) { | 590 | 569 | at_exit_functions_.push_back(ExitCallback{cb, arg}); | 591 | 570 | } | 592 | 571 |
| 593 | | -void Environment::AddPromiseHook(promise_hook_func fn, void* arg) { | 594 | | - auto it = std::find_if( | 595 | | - promise_hooks_.begin(), promise_hooks_.end(), | 596 | | - [&](const PromiseHookCallback& hook) { | 597 | | - return hook.cb_ == fn && hook.arg_ == arg; | 598 | | - }); | 599 | | - if (it != promise_hooks_.end()) { | 600 | | - it->enable_count_++; | 601 | | - return; | 602 | | - } | 603 | | - promise_hooks_.push_back(PromiseHookCallback{fn, arg, 1}); | 604 | | - | 605 | | - if (promise_hooks_.size() == 1) { | 606 | | - isolate_->SetPromiseHook(EnvPromiseHook); | 607 | | - } | 608 | | -} | 609 | | - | 610 | | -bool Environment::RemovePromiseHook(promise_hook_func fn, void* arg) { | 611 | | - auto it = std::find_if( | 612 | | - promise_hooks_.begin(), promise_hooks_.end(), | 613 | | - [&](const PromiseHookCallback& hook) { | 614 | | - return hook.cb_ == fn && hook.arg_ == arg; | 615 | | - }); | 616 | | - | 617 | | - if (it == promise_hooks_.end()) return false; | 618 | | - | 619 | | - if (--it->enable_count_ > 0) return true; | 620 | | - | 621 | | - promise_hooks_.erase(it); | 622 | | - if (promise_hooks_.empty()) { | 623 | | - isolate_->SetPromiseHook(nullptr); | 624 | | - } | 625 | | - | 626 | | - return true; | 627 | | -} | 628 | | - | 629 | | -void Environment::EnvPromiseHook(PromiseHookType type, | 630 | | - Local<Promise> promise, | 631 | | - Local<Value> parent) { | 632 | | - Local<Context> context = promise->CreationContext(); | 633 | | - | 634 | | - Environment* env = Environment::GetCurrent(context); | 635 | | - if (env == nullptr) return; | 636 | | - TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment), | 637 | | - "EnvPromiseHook", env); | 638 | | - for (const PromiseHookCallback& hook : env->promise_hooks_) { | 639 | | - hook.cb_(type, promise, parent, hook.arg_); | 640 | | - } | 641 | | -} | 642 | | - | 643 | 572 | void Environment::RunAndClearNativeImmediates() { | 644 | 573 | TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment), | 645 | 574 | "RunAndClearNativeImmediates", this); | |
Collapse file Copy file name to clipboardExpand all lines: src/env.h -13Lines changed: 0 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -959,8 +959,6 @@ class Environment { | 959 | 959 | inline HandleWrapQueue* handle_wrap_queue() { return &handle_wrap_queue_; } | 960 | 960 | inline ReqWrapQueue* req_wrap_queue() { return &req_wrap_queue_; } | 961 | 961 |
| 962 | | - void AddPromiseHook(promise_hook_func fn, void* arg); | 963 | | - bool RemovePromiseHook(promise_hook_func fn, void* arg); | 964 | 962 | inline bool EmitProcessEnvWarning() { | 965 | 963 | bool current_value = emit_env_nonstring_warning_; | 966 | 964 | emit_env_nonstring_warning_ = false; | @@ -1164,13 +1162,6 @@ class Environment { | 1164 | 1162 |
| 1165 | 1163 | std::list<ExitCallback> at_exit_functions_; | 1166 | 1164 |
| 1167 | | - struct PromiseHookCallback { | 1168 | | - promise_hook_func cb_; | 1169 | | - void* arg_; | 1170 | | - size_t enable_count_; | 1171 | | - }; | 1172 | | - std::vector<PromiseHookCallback> promise_hooks_; | 1173 | | - | 1174 | 1165 | struct NativeImmediateCallback { | 1175 | 1166 | native_immediate_callback cb_; | 1176 | 1167 | void* data_; | @@ -1214,10 +1205,6 @@ class Environment { | 1214 | 1205 | // Used by embedders to shutdown running Node instance. | 1215 | 1206 | AsyncRequest thread_stopper_; | 1216 | 1207 |
| 1217 | | - static void EnvPromiseHook(v8::PromiseHookType type, | 1218 | | - v8::Local<v8::Promise> promise, | 1219 | | - v8::Local<v8::Value> parent); | 1220 | | - | 1221 | 1208 | template <typename T> | 1222 | 1209 | void ForEachBaseObject(T&& iterator); | 1223 | 1210 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node.h -12Lines changed: 0 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -639,24 +639,12 @@ NODE_EXTERN void AtExit(Environment* env, | 639 | 639 | void (*cb)(void* arg), | 640 | 640 | void* arg = nullptr); | 641 | 641 |
| 642 | | -typedef void (*promise_hook_func) (v8::PromiseHookType type, | 643 | | - v8::Local<v8::Promise> promise, | 644 | | - v8::Local<v8::Value> parent, | 645 | | - void* arg); | 646 | | - | 647 | 642 | typedef double async_id; | 648 | 643 | struct async_context { | 649 | 644 | ::node::async_id async_id; | 650 | 645 | ::node::async_id trigger_async_id; | 651 | 646 | }; | 652 | 647 |
| 653 | | -/* Registers an additional v8::PromiseHook wrapper. This API exists because V8 | 654 | | - * itself supports only a single PromiseHook. */ | 655 | | -NODE_DEPRECATED("Use async_hooks directly instead", | 656 | | - NODE_EXTERN void AddPromiseHook(v8::Isolate* isolate, | 657 | | - promise_hook_func fn, | 658 | | - void* arg)); | 659 | | - | 660 | 648 | /* This is a lot like node::AtExit, except that the hooks added via this | 661 | 649 | * function are run before the AtExit ones and will always be registered | 662 | 650 | * for the current Environment instance. | |
Collapse file Copy file name to clipboardExpand all lines: src/node_internals.h +17-1Lines changed: 17 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -301,7 +301,6 @@ v8::MaybeLocal<v8::Object> GetPerContextExports(v8::Local<v8::Context> context); | 301 | 301 | namespace profiler { | 302 | 302 | void StartCoverageCollection(Environment* env); | 303 | 303 | } | 304 | | - | 305 | 304 | #ifdef _WIN32 | 306 | 305 | typedef SYSTEMTIME TIME_TYPE; | 307 | 306 | #else // UNIX, OSX | @@ -336,6 +335,23 @@ class DiagnosticFilename { | 336 | 335 | std::string filename_; | 337 | 336 | }; | 338 | 337 |
| | 338 | +class TraceEventScope { | | 339 | + public: | | 340 | + TraceEventScope(const char* category, | | 341 | + const char* name, | | 342 | + void* id) : category_(category), name_(name), id_(id) { | | 343 | + TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(category_, name_, id_); | | 344 | + } | | 345 | + ~TraceEventScope() { | | 346 | + TRACE_EVENT_NESTABLE_ASYNC_END0(category_, name_, id_); | | 347 | + } | | 348 | + | | 349 | + private: | | 350 | + const char* category_; | | 351 | + const char* name_; | | 352 | + void* id_; | | 353 | +}; | | 354 | + | 339 | 355 | } // namespace node | 340 | 356 |
| 341 | 357 | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
|