diff options
author | Shelley Vohr <shelley.vohr@gmail.com> | 2020-06-25 18:07:37 -0700 |
---|---|---|
committer | Shelley Vohr <shelley.vohr@gmail.com> | 2020-06-29 09:12:11 -0700 |
commit | c23d2fd3f8a018bcc624f1468a9ce176f6ce93f2 (patch) | |
tree | 4f868038dc77b7eb64d091ee55ae59729293a0b8 /src | |
parent | 9e135accbb045d52eb65de602c81b5090daae1c4 (diff) | |
download | node-new-c23d2fd3f8a018bcc624f1468a9ce176f6ce93f2.tar.gz |
src: allow embedders to disable esm loader
PR-URL: https://github.com/nodejs/node/pull/34060
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'src')
-rw-r--r-- | src/env-inl.h | 4 | ||||
-rw-r--r-- | src/env.h | 1 | ||||
-rw-r--r-- | src/node.h | 6 | ||||
-rw-r--r-- | src/node_options.cc | 6 |
4 files changed, 16 insertions, 1 deletions
diff --git a/src/env-inl.h b/src/env-inl.h index 5cbb2cd60b..690e797043 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -767,6 +767,10 @@ inline bool Environment::is_main_thread() const { return worker_context() == nullptr; } +inline bool Environment::should_not_register_esm_loader() const { + return flags_ & EnvironmentFlags::kNoRegisterESMLoader; +} + inline bool Environment::owns_process_state() const { return flags_ & EnvironmentFlags::kOwnsProcessState; } @@ -1054,6 +1054,7 @@ class Environment : public MemoryRetainer { inline void set_has_serialized_options(bool has_serialized_options); inline bool is_main_thread() const; + inline bool should_not_register_esm_loader() const; inline bool owns_process_state() const; inline bool owns_inspector() const; inline uint64_t thread_id() const; diff --git a/src/node.h b/src/node.h index b3b7c0c169..6a6a40113b 100644 --- a/src/node.h +++ b/src/node.h @@ -408,7 +408,11 @@ enum Flags : uint64_t { // Set if this Environment instance is associated with the global inspector // handling code (i.e. listening on SIGUSR1). // This is set when using kDefaultFlags. - kOwnsInspector = 1 << 2 + kOwnsInspector = 1 << 2, + // Set if Node.js should not run its own esm loader. This is needed by some + // embedders, because it's possible for the Node.js esm loader to conflict + // with another one in an embedder environment, e.g. Blink's in Chromium. + kNoRegisterESMLoader = 1 << 3 }; } // namespace EnvironmentFlags diff --git a/src/node_options.cc b/src/node_options.cc index d7434b4b12..913366b350 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -979,6 +979,12 @@ void Initialize(Local<Object> target, context, FIXED_ONE_BYTE_STRING(isolate, "envSettings"), env_settings) .Check(); + target + ->Set(context, + FIXED_ONE_BYTE_STRING(env->isolate(), "shouldNotRegisterESMLoader"), + Boolean::New(isolate, env->should_not_register_esm_loader())) + .Check(); + Local<Object> types = Object::New(isolate); NODE_DEFINE_CONSTANT(types, kNoOp); NODE_DEFINE_CONSTANT(types, kV8Option); |