@@ -40,7 +40,6 @@ using node::FatalError;
4040
4141using v8::Context;
4242using v8::Function;
43- using v8::Global;
4443using v8::HandleScope;
4544using v8::Isolate;
4645using v8::Local;
@@ -804,8 +803,8 @@ void Agent::PauseOnNextJavascriptStatement(const std::string& reason) {
804803void Agent::RegisterAsyncHook (Isolate* isolate,
805804 Local<Function> enable_function,
806805 Local<Function> disable_function) {
807- enable_async_hook_function_. Reset (isolate, enable_function);
808- disable_async_hook_function_. Reset (isolate, disable_function);
806+ parent_env_-> set_inspector_enable_async_hooks ( enable_function);
807+ parent_env_-> set_inspector_disable_async_hooks ( disable_function);
809808 if (pending_enable_async_hook_) {
810809 CHECK (!pending_disable_async_hook_);
811810 pending_enable_async_hook_ = false ;
@@ -818,8 +817,10 @@ void Agent::RegisterAsyncHook(Isolate* isolate,
818817}
819818
820819void Agent::EnableAsyncHook () {
821- if (!enable_async_hook_function_.IsEmpty ()) {
822- ToggleAsyncHook (parent_env_->isolate (), enable_async_hook_function_);
820+ HandleScope scope (parent_env_->isolate ());
821+ Local<Function> enable = parent_env_->inspector_enable_async_hooks ();
822+ if (!enable.IsEmpty ()) {
823+ ToggleAsyncHook (parent_env_->isolate (), enable);
823824 } else if (pending_disable_async_hook_) {
824825 CHECK (!pending_enable_async_hook_);
825826 pending_disable_async_hook_ = false ;
@@ -829,8 +830,10 @@ void Agent::EnableAsyncHook() {
829830}
830831
831832void Agent::DisableAsyncHook () {
832- if (!disable_async_hook_function_.IsEmpty ()) {
833- ToggleAsyncHook (parent_env_->isolate (), disable_async_hook_function_);
833+ HandleScope scope (parent_env_->isolate ());
834+ Local<Function> disable = parent_env_->inspector_enable_async_hooks ();
835+ if (!disable.IsEmpty ()) {
836+ ToggleAsyncHook (parent_env_->isolate (), disable);
834837 } else if (pending_enable_async_hook_) {
835838 CHECK (!pending_disable_async_hook_);
836839 pending_enable_async_hook_ = false ;
@@ -839,8 +842,7 @@ void Agent::DisableAsyncHook() {
839842 }
840843}
841844
842- void Agent::ToggleAsyncHook (Isolate* isolate,
843- const Global<Function>& fn) {
845+ void Agent::ToggleAsyncHook (Isolate* isolate, Local<Function> fn) {
844846 // Guard against running this during cleanup -- no async events will be
845847 // emitted anyway at that point anymore, and calling into JS is not possible.
846848 // This should probably not be something we're attempting in the first place,
@@ -851,7 +853,7 @@ void Agent::ToggleAsyncHook(Isolate* isolate,
851853 CHECK (!fn.IsEmpty ());
852854 auto context = parent_env_->context ();
853855 v8::TryCatch try_catch (isolate);
854- USE (fn. Get (isolate) ->Call (context, Undefined (isolate), 0 , nullptr ));
856+ USE (fn->Call (context, Undefined (isolate), 0 , nullptr ));
855857 if (try_catch.HasCaught () && !try_catch.HasTerminated ()) {
856858 PrintCaughtException (isolate, context, try_catch);
857859 FatalError (" \n node::inspector::Agent::ToggleAsyncHook" ,
0 commit comments