mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
lib: always initialize esm loader callbackMap
PR-URL: https://github.com/nodejs/node/pull/34127 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host>
This commit is contained in:
1 parent
e4c7b59665
commit
8bafba2e56
2 files changed
+32
-16
No files matched your search
@@ -67,10 +67,7 @@ function prepareMainThreadExecution(expandArgv1 = false) {
|
||||
initializeDeprecations();
|
||||
initializeWASI();
|
||||
initializeCJSLoader();
|
||||
|
||||
if (!shouldNotRegisterESMLoader) {
|
||||
initializeESMLoader();
|
||||
}
|
||||
initializeESMLoader();
|
||||
|
||||
const CJSLoader = require('internal/modules/cjs/loader');
|
||||
assert(!CJSLoader.hasLoadedAnyUserCJSModule);
|
||||
@@ -414,6 +411,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
|
||||
|
||||
@@ -49,12 +49,21 @@ TEST_F(EnvironmentTest, EnvironmentWithESMLoader) {
|
||||
node::LoadEnvironment(
|
||||
*env,
|
||||
"const { SourceTextModule } = require('vm');"
|
||||
"try {"
|
||||
"new SourceTextModule('export const a = 1;');"
|
||||
"(async () => {"
|
||||
"const stmString = 'globalThis.importResult = import(\"\")';"
|
||||
"const m = new SourceTextModule(stmString, {"
|
||||
"importModuleDynamically: (async () => {"
|
||||
"const m = new SourceTextModule('');"
|
||||
"await m.link(() => 0);"
|
||||
"await m.evaluate();"
|
||||
"return m.namespace;"
|
||||
"}),"
|
||||
"});"
|
||||
"await m.link(() => 0);"
|
||||
"await m.evaluate();"
|
||||
"delete globalThis.importResult;"
|
||||
"process.exit(0);"
|
||||
"} catch {"
|
||||
"process.exit(42);"
|
||||
"}");
|
||||
"})()");
|
||||
}
|
||||
|
||||
TEST_F(EnvironmentTest, EnvironmentWithNoESMLoader) {
|
||||
@@ -67,19 +76,27 @@ TEST_F(EnvironmentTest, EnvironmentWithNoESMLoader) {
|
||||
|
||||
SetProcessExitHandler(*env, [&](node::Environment* env_, int exit_code) {
|
||||
EXPECT_EQ(*env, env_);
|
||||
EXPECT_EQ(exit_code, 42);
|
||||
EXPECT_EQ(exit_code, 1);
|
||||
node::Stop(*env);
|
||||
});
|
||||
|
||||
node::LoadEnvironment(
|
||||
*env,
|
||||
"const { SourceTextModule } = require('vm');"
|
||||
"try {"
|
||||
"new SourceTextModule('export const a = 1;');"
|
||||
"process.exit(0);"
|
||||
"} catch {"
|
||||
"process.exit(42);"
|
||||
"}");
|
||||
"(async () => {"
|
||||
"const stmString = 'globalThis.importResult = import(\"\")';"
|
||||
"const m = new SourceTextModule(stmString, {"
|
||||
"importModuleDynamically: (async () => {"
|
||||
"const m = new SourceTextModule('');"
|
||||
"await m.link(() => 0);"
|
||||
"await m.evaluate();"
|
||||
"return m.namespace;"
|
||||
"}),"
|
||||
"});"
|
||||
"await m.link(() => 0);"
|
||||
"await m.evaluate();"
|
||||
"delete globalThis.importResult;"
|
||||
"})()");
|
||||
}
|
||||
|
||||
TEST_F(EnvironmentTest, PreExecutionPreparation) {
|
||||
|
||||
Reference in new issue
Block a user