Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit efd46e3

Browse filesBrowse files
codebytereaddaleax
authored andcommitted
lib: always initialize esm loader callbackMap
PR-URL: #34127 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host>
1 parent 5e28660 commit efd46e3
Copy full SHA for efd46e3

File tree

Expand file treeCollapse file tree

2 files changed

+32
-16
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+32
-16
lines changed
Open diff view settings
Collapse file

‎lib/internal/bootstrap/pre_execution.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/pre_execution.js
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ function prepareMainThreadExecution(expandArgv1 = false) {
6767
initializeDeprecations();
6868
initializeWASI();
6969
initializeCJSLoader();
70-
71-
if (!shouldNotRegisterESMLoader) {
72-
initializeESMLoader();
73-
}
70+
initializeESMLoader();
7471

7572
const CJSLoader = require('internal/modules/cjs/loader');
7673
assert(!CJSLoader.hasLoadedAnyUserCJSModule);
@@ -416,6 +413,8 @@ function initializeESMLoader() {
416413
// Create this WeakMap in js-land because V8 has no C++ API for WeakMap.
417414
internalBinding('module_wrap').callbackMap = new SafeWeakMap();
418415

416+
if (shouldNotRegisterESMLoader) return;
417+
419418
const {
420419
setImportModuleDynamicallyCallback,
421420
setInitializeImportMetaObjectCallback
Collapse file

‎test/cctest/test_environment.cc‎

Copy file name to clipboardExpand all lines: test/cctest/test_environment.cc
+29-12Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,21 @@ TEST_F(EnvironmentTest, EnvironmentWithESMLoader) {
4949
node::LoadEnvironment(
5050
*env,
5151
"const { SourceTextModule } = require('vm');"
52-
"try {"
53-
"new SourceTextModule('export const a = 1;');"
52+
"(async () => {"
53+
"const stmString = 'globalThis.importResult = import(\"\")';"
54+
"const m = new SourceTextModule(stmString, {"
55+
"importModuleDynamically: (async () => {"
56+
"const m = new SourceTextModule('');"
57+
"await m.link(() => 0);"
58+
"await m.evaluate();"
59+
"return m.namespace;"
60+
"}),"
61+
"});"
62+
"await m.link(() => 0);"
63+
"await m.evaluate();"
64+
"delete globalThis.importResult;"
5465
"process.exit(0);"
55-
"} catch {"
56-
"process.exit(42);"
57-
"}");
66+
"})()");
5867
}
5968

6069
TEST_F(EnvironmentTest, EnvironmentWithNoESMLoader) {
@@ -67,19 +76,27 @@ TEST_F(EnvironmentTest, EnvironmentWithNoESMLoader) {
6776

6877
SetProcessExitHandler(*env, [&](node::Environment* env_, int exit_code) {
6978
EXPECT_EQ(*env, env_);
70-
EXPECT_EQ(exit_code, 42);
79+
EXPECT_EQ(exit_code, 1);
7180
node::Stop(*env);
7281
});
7382

7483
node::LoadEnvironment(
7584
*env,
7685
"const { SourceTextModule } = require('vm');"
77-
"try {"
78-
"new SourceTextModule('export const a = 1;');"
79-
"process.exit(0);"
80-
"} catch {"
81-
"process.exit(42);"
82-
"}");
86+
"(async () => {"
87+
"const stmString = 'globalThis.importResult = import(\"\")';"
88+
"const m = new SourceTextModule(stmString, {"
89+
"importModuleDynamically: (async () => {"
90+
"const m = new SourceTextModule('');"
91+
"await m.link(() => 0);"
92+
"await m.evaluate();"
93+
"return m.namespace;"
94+
"}),"
95+
"});"
96+
"await m.link(() => 0);"
97+
"await m.evaluate();"
98+
"delete globalThis.importResult;"
99+
"})()");
83100
}
84101

85102
TEST_F(EnvironmentTest, PreExecutionPreparation) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.