Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bec5073
commit b55147b
Showing
8 changed files
with
128 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
patches/node/fix_do_not_register_the_esm_loader_in_renderer_processes.patch
This file was deleted.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
patches/node/src_allow_embedders_to_disable_esm_loader.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Shelley Vohr <shelley.vohr@gmail.com> | ||
Date: Tue, 14 Jul 2020 16:57:36 -0700 | ||
Subject: src: allow embedders to disable esm loader | ||
|
||
Blink has its own independent ESM loader, which is set up in the | ||
renderer process of Electron. When ESM was unilaterally unflagged, | ||
this meant that there would be two competing ESM loaders in the same process, | ||
both of which made assumptions about code being run. | ||
|
||
Thus, it makes more sense to allow embedders to specify that we don't | ||
want to register the ESM loader when creating an Environment via flag. | ||
|
||
This has already been upstreamed and merged upstream. | ||
|
||
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js | ||
index b4a0f71af5853f427a10449b52509052fbe3facd..6f1c56af89626ae47a31995ee3d7c6fa96c71b86 100644 | ||
--- a/lib/internal/bootstrap/pre_execution.js | ||
+++ b/lib/internal/bootstrap/pre_execution.js | ||
@@ -6,7 +6,10 @@ const { | ||
SafeWeakMap, | ||
} = primordials; | ||
|
||
-const { getOptionValue } = require('internal/options'); | ||
+const { | ||
+ getOptionValue, | ||
+ shouldNotRegisterESMLoader | ||
+} = require('internal/options'); | ||
const { Buffer } = require('buffer'); | ||
const { ERR_MANIFEST_ASSERT_INTEGRITY } = require('internal/errors').codes; | ||
const assert = require('internal/assert'); | ||
@@ -411,6 +414,8 @@ function initializeESMLoader() { | ||
// Create this WeakMap in js-land because V8 has no C++ API for WeakMap. | ||
internalBinding('module_wrap').callbackMap = new SafeWeakMap(); | ||
|
||
+ if (shouldNotRegisterESMLoader) return; | ||
+ | ||
const { | ||
setImportModuleDynamicallyCallback, | ||
setInitializeImportMetaObjectCallback | ||
diff --git a/lib/internal/options.js b/lib/internal/options.js | ||
index 03586f9dae6d7690acd7e5e22b6ccbd28dd0752b..10c6aa2d9a0978abcde10477276be6f7a0404219 100644 | ||
--- a/lib/internal/options.js | ||
+++ b/lib/internal/options.js | ||
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
-const { getOptions } = internalBinding('options'); | ||
+const { getOptions, shouldNotRegisterESMLoader } = internalBinding('options'); | ||
const { options, aliases } = getOptions(); | ||
|
||
let warnOnAllowUnauthorized = true; | ||
@@ -32,4 +32,5 @@ module.exports = { | ||
aliases, | ||
getOptionValue, | ||
getAllowUnauthorized, | ||
+ shouldNotRegisterESMLoader | ||
}; | ||
diff --git a/src/env-inl.h b/src/env-inl.h | ||
index 222555831aa1bf0b7b29b4b46e235c98a5dd4ac5..eaebe683b3308ca0e5475b761eb5b32aa85609ff 100644 | ||
--- a/src/env-inl.h | ||
+++ b/src/env-inl.h | ||
@@ -802,6 +802,14 @@ inline bool Environment::is_main_thread() const { | ||
return flags_ & kIsMainThread; | ||
} | ||
|
||
+inline bool Environment::should_not_register_esm_loader() const { | ||
+ return flags_ & kNoRegisterESMLoader; | ||
+} | ||
+ | ||
+inline bool Environment::set_should_not_register_esm_loader() const { | ||
+ flags_ |= kNoRegisterESMLoader; | ||
+} | ||
+ | ||
inline bool Environment::owns_process_state() const { | ||
return flags_ & kOwnsProcessState; | ||
} | ||
diff --git a/src/env.h b/src/env.h | ||
index c1966a9f55126bdd65d8c9d529d934977bb4ad65..7a5ff132a75763d1cf256d34e4dcee105cf44007 100644 | ||
--- a/src/env.h | ||
+++ b/src/env.h | ||
@@ -866,6 +866,7 @@ class Environment : public MemoryRetainer { | ||
kIsMainThread = 1 << 0, | ||
kOwnsProcessState = 1 << 1, | ||
kOwnsInspector = 1 << 2, | ||
+ kNoRegisterESMLoader = 1 << 3 | ||
}; | ||
|
||
static inline Environment* GetCurrent(v8::Isolate* isolate); | ||
@@ -1066,6 +1067,7 @@ class Environment : public MemoryRetainer { | ||
static constexpr uint64_t kNoThreadId = -1; | ||
|
||
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_options.cc b/src/node_options.cc | ||
index 8b3a161c2d2f83d6c061fb05f854e06f6f0294ab..34d16e6ac36182f2edc335c26c134bf056864c85 100644 | ||
--- a/src/node_options.cc | ||
+++ b/src/node_options.cc | ||
@@ -978,6 +978,11 @@ void Initialize(Local<Object> target, | ||
->Set( | ||
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters