diff --git a/src/env-inl.h b/src/env-inl.h index f379660004fed9..69c70804c8a750 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -487,24 +487,32 @@ inline uint32_t Environment::get_next_function_id() { return function_id_counter_++; } -Environment::ShouldNotAbortOnUncaughtScope::ShouldNotAbortOnUncaughtScope( +ShouldNotAbortOnUncaughtScope::ShouldNotAbortOnUncaughtScope( Environment* env) : env_(env) { - env_->should_not_abort_scope_counter_++; + env_->PushShouldNotAbortOnUncaughtScope(); } -Environment::ShouldNotAbortOnUncaughtScope::~ShouldNotAbortOnUncaughtScope() { +ShouldNotAbortOnUncaughtScope::~ShouldNotAbortOnUncaughtScope() { Close(); } -void Environment::ShouldNotAbortOnUncaughtScope::Close() { +void ShouldNotAbortOnUncaughtScope::Close() { if (env_ != nullptr) { - env_->should_not_abort_scope_counter_--; + env_->PopShouldNotAbortOnUncaughtScope(); env_ = nullptr; } } -bool Environment::inside_should_not_abort_on_uncaught_scope() const { +inline void Environment::PushShouldNotAbortOnUncaughtScope() { + should_not_abort_scope_counter_++; +} + +inline void Environment::PopShouldNotAbortOnUncaughtScope() { + should_not_abort_scope_counter_--; +} + +inline bool Environment::inside_should_not_abort_on_uncaught_scope() const { return should_not_abort_scope_counter_ > 0; } diff --git a/src/env.h b/src/env.h index 0206330391001c..55018b6d40d1ca 100644 --- a/src/env.h +++ b/src/env.h @@ -684,6 +684,16 @@ class TrackingTraceStateObserver : Environment* env_; }; +class ShouldNotAbortOnUncaughtScope { + public: + explicit inline ShouldNotAbortOnUncaughtScope(Environment* env); + inline void Close(); + inline ~ShouldNotAbortOnUncaughtScope(); + + private: + Environment* env_; +}; + class Environment { public: Environment(const Environment&) = delete; @@ -998,16 +1008,8 @@ class Environment { // This needs to be available for the JS-land setImmediate(). void ToggleImmediateRef(bool ref); - class ShouldNotAbortOnUncaughtScope { - public: - explicit inline ShouldNotAbortOnUncaughtScope(Environment* env); - inline void Close(); - inline ~ShouldNotAbortOnUncaughtScope(); - - private: - Environment* env_; - }; - + inline void PushShouldNotAbortOnUncaughtScope(); + inline void PopShouldNotAbortOnUncaughtScope(); inline bool inside_should_not_abort_on_uncaught_scope() const; static inline Environment* ForAsyncHooks(AsyncHooks* hooks); diff --git a/src/module_wrap.cc b/src/module_wrap.cc index ac5d28fb2352ba..56149d0cc759c9 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -136,7 +136,7 @@ void ModuleWrap::New(const FunctionCallbackInfo& args) { column_offset = Integer::New(isolate, 0); } - Environment::ShouldNotAbortOnUncaughtScope no_abort_scope(env); + ShouldNotAbortOnUncaughtScope no_abort_scope(env); TryCatchScope try_catch(env); Local module; @@ -280,7 +280,7 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo& args) { CHECK(args[1]->IsBoolean()); bool break_on_sigint = args[1]->IsTrue(); - Environment::ShouldNotAbortOnUncaughtScope no_abort_scope(env); + ShouldNotAbortOnUncaughtScope no_abort_scope(env); TryCatchScope try_catch(env); bool timed_out = false; diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 621fa7eb16fe79..087727d93a9837 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -719,7 +719,7 @@ void ContextifyScript::New(const FunctionCallbackInfo& args) { compile_options = ScriptCompiler::kConsumeCodeCache; TryCatchScope try_catch(env); - Environment::ShouldNotAbortOnUncaughtScope no_abort_scope(env); + ShouldNotAbortOnUncaughtScope no_abort_scope(env); Context::Scope scope(parsing_context); MaybeLocal v8_script = ScriptCompiler::CompileUnboundScript(