Skip to content

Commit

Permalink
src: move ShouldNotAbortOnUncaughtScope out of Environment
Browse files Browse the repository at this point in the history
PR-URL: #26824
Refs: #26776
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung committed Mar 27, 2019
1 parent 9f37d3c commit 9d854fb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
20 changes: 14 additions & 6 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
22 changes: 12 additions & 10 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
column_offset = Integer::New(isolate, 0);
}

Environment::ShouldNotAbortOnUncaughtScope no_abort_scope(env);
ShouldNotAbortOnUncaughtScope no_abort_scope(env);
TryCatchScope try_catch(env);
Local<Module> module;

Expand Down Expand Up @@ -280,7 +280,7 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& 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;
Expand Down
2 changes: 1 addition & 1 deletion src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& 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<UnboundScript> v8_script = ScriptCompiler::CompileUnboundScript(
Expand Down

0 comments on commit 9d854fb

Please sign in to comment.