From b1db13bd7eeb9023706d63a79d6b97c5f152ef2c Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 31 Aug 2020 19:51:09 -0700 Subject: [PATCH] src: add get/set pair for env context awareness PR-URL: https://github.com/nodejs/node/pull/35024 Reviewed-By: Gus Caplan Reviewed-By: Joyee Cheung Reviewed-By: Colin Ihrig --- src/env-inl.h | 8 ++++++++ src/env.h | 3 +++ src/node_binding.cc | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/env-inl.h b/src/env-inl.h index a5b487d02d277e..2acbe464ccaac4 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -509,6 +509,14 @@ inline bool Environment::abort_on_uncaught_exception() const { return options_->abort_on_uncaught_exception; } +inline void Environment::set_force_context_aware(bool value) { + options_->force_context_aware = value; +} + +inline bool Environment::force_context_aware() const { + return options_->force_context_aware; +} + inline void Environment::set_abort_on_uncaught_exception(bool value) { options_->abort_on_uncaught_exception = value; } diff --git a/src/env.h b/src/env.h index 1c1c98f4f606ef..41c93f59d8ab4f 100644 --- a/src/env.h +++ b/src/env.h @@ -973,6 +973,9 @@ class Environment : public MemoryRetainer { void PrintSyncTrace() const; inline void set_trace_sync_io(bool value); + inline void set_force_context_aware(bool value); + inline bool force_context_aware() const; + // This stores whether the --abort-on-uncaught-exception flag was passed // to Node. inline bool abort_on_uncaught_exception() const; diff --git a/src/node_binding.cc b/src/node_binding.cc index 0b5f6cfa038369..6f0e80551223c0 100644 --- a/src/node_binding.cc +++ b/src/node_binding.cc @@ -461,7 +461,7 @@ void DLOpen(const FunctionCallbackInfo& args) { if (mp != nullptr) { if (mp->nm_context_register_func == nullptr) { - if (env->options()->force_context_aware) { + if (env->force_context_aware()) { dlib->Close(); THROW_ERR_NON_CONTEXT_AWARE_DISABLED(env); return false;