Dynamic import() is broken: not-yet-loaded modules reject with "module record has unexpected status: New", and import() from a classic script rejects with undefined
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 44/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c, javascript, wasm
Direzione di ricerca
Start with runtime/script_loader.cpp and trace module_load_hook, especially how static and dynamic loads handle the payload and referrer. Reproduce with the supplied module and classic-script examples, then run the listed test262 dynamic-import tests. Done means dynamic imports resolve for unloaded and evaluating modules, work from classic scripts, and reject missing modules with an error value.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
import() only works if the target module was already linked and evaluated by a static import:
- From a module, importing a module that is not loaded yet rejects with
InternalError: module record has unexpected status: New. - A module that imports itself while evaluating (the normal cycle case) rejects with
… unexpected status: Evaluating. - From a classic script (
--legacy-script), the promise rejects withundefined.
Environment
- StarlingMonkey v0.4.0 release
starling.wasm, wasmtime 50.0.1 (wasmtime run -S http --dir . starling.wasm main.js). runtime/script_loader.cppis unchanged onmain(54b3329b).- Checked on 2026-11-03. Reference: SpiderMonkey jsshell 147.0.4 (the SpiderMonkey version StarlingMonkey v0.4.0 embeds),
js -m.
Reproduction
b.js:
export const y = 2;
main.js:
import("./b.js").then(
ns => console.log("b ok", ns.y),
e => console.log("b rejected", e && e.name, e && e.message));
| case | StarlingMonkey | jsshell 147.0.4 |
|---|---|---|
main.js as above |
b rejected InternalError module record has unexpected status: New |
b ok 2 |
same with top-level await import("./b.js") |
rejects with the same InternalError | resolves |
import { y } from "./b.js" first, then await import("./b.js") |
works | works |
self.js: export const v = 1; import("./self.js").then(...) |
rejects: InternalError: module record has unexpected status: Evaluating |
self import ok 1 |
import("./nope.js") (missing file) |
rejects with ReferenceError: Error loading module … (fine) |
rejects |
main.js run with --legacy-script |
rejection value is undefined |
b ok 2 |
test262: language/module-code/top-level-await/dynamic-import-resolution.js fails with the "unexpected status: New"
error; other language/expressions/dynamic-import/ tests are affected the same way.
Expected
Per ECMA-262 EvaluateImportCall →
HostLoadImportedModule →
FinishLoadingImportedModule →
ContinueDynamicImport, the loaded module is linked and evaluated
and the promise resolves with its namespace. import() is valid in classic scripts (the referrer is the Script
Record, or the Realm when there is no active script). Importing a module that is still evaluating is legal and
resolves after evaluation. A failure must reject with an error value, not undefined.
Likely cause (from reading the code, not verified with a debug build)
module_load_hook in runtime/script_loader.cpp handles static and dynamic loads the same way:
-
It calls
FinishLoadingImportedModule(cx, referrer, module_request, payload, result, false)synchronously from inside
the load hook, also whenpayloadis a dynamic-import promise. jsshell'sModuleLoader::loadImportedModuletreats
that case differently: it detects the promise payload and finishes the load later (fromdoDynamicImport, with a
null referrer). The synchronous re-entry is the likely reason SpiderMonkey reaches evaluation of a module that was
never linked (New) or is still evaluating. -
For a classic-script referrer,
JS::GetScriptPrivate(referrer)isundefined(only modules get theinfoobject).
The code then doesMOZ_ASSERT(ref_priv.isObject(), "Module referrer must have an object private value"); RootedObject info(cx, &ref_priv.toObject());In a release build the assert is compiled out and
toObject()is called onundefined. In practice the hook then
returnsfalsewith no pending exception, which rejects the promise withundefined.
Suggested fix (sketch)
- For a dynamic import (promise
payload), defer: queue a job that resolves and compiles the module and calls
FinishLoadingImportedModule(cx, nullptr, moduleRequest, payload, module, false), or
FinishLoadingImportedModuleFailedWithPendingException(cx, payload)on error, as jsshell's ModuleLoader does. - When the referrer has no object private (classic script,
eval,Function), resolve relative to the main script
path or the working directory instead of dereferencing it. - Add integration tests for
import()from a module, from a script, of a module that is evaluating, and of a missing file.
- Lingua principale
- C
- Stelle
- 297
- Fork
- 64
- Merge medio
- 2g 2h
- PR unite (30g)
- 19
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di bytecodealliance/StarlingMonkey
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
bytecodealliance/StarlingMonkey#359 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
bytecodealliance/StarlingMonkey#355 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 1-2 giorni Idoneità per principianti 68/100
bytecodealliance/StarlingMonkey#358 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
bytecodealliance/StarlingMonkey#357 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
bytecodealliance/StarlingMonkey#356 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di bytecodealliance/StarlingMonkey
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
msys2/MINGW-packages#33356 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
facebookincubator/muse-gadget-sdk#355 ·
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
kmod-project/kmod#492 ·
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
PecanProject/sipnet#435 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
SDL_GPU Vulkan: wrong screen orientation on OpenHarmony (preTransform set without pre-rotation)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
libsdl-org/SDL#16670 ·
I maintainer di solito rispondono entro 1 giorno