Skip to content

Commit eb85c5c

Browse files
committed
bootstrap: optimize modules loaded in the built-in snapshot
nodejs/node#45849
1 parent 10fa7c0 commit eb85c5c

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

patches/node/chore_expose_importmoduledynamically_and.patch

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,26 @@ its own blended handler between Node and Blink.
1010

1111
Not upstreamable.
1212

13-
diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js
14-
index cbfb6e3620a7e77658c86a4730c50661b8a937f7..ccd48027e3dfebd563fcbe83239174c79c693dd7 100644
15-
--- a/lib/internal/process/pre_execution.js
16-
+++ b/lib/internal/process/pre_execution.js
17-
@@ -567,7 +567,7 @@ function initializeESMLoader() {
18-
// Create this WeakMap in js-land because V8 has no C++ API for WeakMap.
19-
internalBinding('module_wrap').callbackMap = new SafeWeakMap();
20-
21-
- if (getEmbedderOptions().shouldNotRegisterESMLoader) return;
13+
diff --git a/lib/internal/modules/esm/utils.js b/lib/internal/modules/esm/utils.js
14+
index 985784383024450833a8324d45a7af2fe214a09c..524558b6d00969c2b62cd6050fde9de583f14e90 100644
15+
--- a/lib/internal/modules/esm/utils.js
16+
+++ b/lib/internal/modules/esm/utils.js
17+
@@ -148,12 +148,13 @@ async function importModuleDynamicallyCallback(symbol, specifier, assertions) {
18+
// the loader worker in internal/main/worker_thread.js.
19+
let _isLoaderWorker = false;
20+
function initializeESM(isLoaderWorker = false) {
2221
+ const shouldSetOnIsolate = !getEmbedderOptions().shouldNotRegisterESMLoader;
23-
24-
const {
25-
setImportModuleDynamicallyCallback,
26-
@@ -576,8 +576,8 @@ function initializeESMLoader() {
27-
const esm = require('internal/process/esm_loader');
22+
_isLoaderWorker = isLoaderWorker;
23+
initializeDefaultConditions();
2824
// Setup per-isolate callbacks that locate data or callbacks that we keep
2925
// track of for different ESM modules.
30-
- setInitializeImportMetaObjectCallback(esm.initializeImportMetaObject);
31-
- setImportModuleDynamicallyCallback(esm.importModuleDynamicallyCallback);
32-
+ setInitializeImportMetaObjectCallback(esm.initializeImportMetaObject, shouldSetOnIsolate);
33-
+ setImportModuleDynamicallyCallback(esm.importModuleDynamicallyCallback, shouldSetOnIsolate);
26+
- setInitializeImportMetaObjectCallback(initializeImportMetaObject);
27+
- setImportModuleDynamicallyCallback(importModuleDynamicallyCallback);
28+
+ setInitializeImportMetaObjectCallback(initializeImportMetaObject, shouldSetOnIsolate);
29+
+ setImportModuleDynamicallyCallback(importModuleDynamicallyCallback, shouldSetOnIsolate);
30+
}
3431

35-
// Patch the vm module when --experimental-vm-modules is on.
36-
// Please update the comments in vm.js when this block changes.
32+
function isLoaderWorker() {
3733
diff --git a/src/module_wrap.cc b/src/module_wrap.cc
3834
index 0645b3ddf506df2a76f5661f0ec6bb35d5d8b94e..e0f1b2d51f3055b2250f2c0dc1dfd1048b645dd9 100644
3935
--- a/src/module_wrap.cc
@@ -82,11 +78,11 @@ index 0645b3ddf506df2a76f5661f0ec6bb35d5d8b94e..e0f1b2d51f3055b2250f2c0dc1dfd104
8278

8379
MaybeLocal<Value> ModuleWrap::SyntheticModuleEvaluationStepsCallback(
8480
diff --git a/src/module_wrap.h b/src/module_wrap.h
85-
index 58b233d036515c52d9bd5574c776c2ea65d2ecb1..5f7ef75480a76761c6fa62061c8700c812a3fc6f 100644
81+
index 6435bad40936fe235822c0597310b94ab98082f3..c51eb99ce3eb54bc30ae922e0357b637b09d53c6 100644
8682
--- a/src/module_wrap.h
8783
+++ b/src/module_wrap.h
8884
@@ -30,7 +30,14 @@ enum HostDefinedOptions : int {
89-
kLength = 10,
85+
kLength = 9,
9086
};
9187

9288
-class ModuleWrap : public BaseObject {
@@ -100,4 +96,4 @@ index 58b233d036515c52d9bd5574c776c2ea65d2ecb1..5f7ef75480a76761c6fa62061c8700c8
10096
+class NODE_EXTERN ModuleWrap : public BaseObject {
10197
public:
10298
enum InternalFields {
103-
kModuleWrapBaseField = BaseObject::kInternalFieldCount,
99+
kModuleSlot = BaseObject::kInternalFieldCount,

0 commit comments

Comments
 (0)