-
Notifications
You must be signed in to change notification settings - Fork 15k
/
src_allow_embedders_to_disable_esm_loader.patch
113 lines (101 loc) · 4.18 KB
/
src_allow_embedders_to_disable_esm_loader.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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);