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
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 44/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- c, javascript, wasm
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C
- スター
- 297
- フォーク
- 64
- 平均マージ
- 2日 2時間
- マージ済み PR(30日)
- 19
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bytecodealliance/StarlingMonkey のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
bytecodealliance/StarlingMonkey#359 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
bytecodealliance/StarlingMonkey#355 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 1〜2日 初心者へのやさしさ 68/100
bytecodealliance/StarlingMonkey#358 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
bytecodealliance/StarlingMonkey#357 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
bytecodealliance/StarlingMonkey#356 ·
メンテナーはふだん 1 日以内に返信
bytecodealliance/StarlingMonkey の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
msys2/MINGW-packages#33356 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
kmod-project/kmod#492 ·
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
PecanProject/sipnet#435 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
SDL_GPU Vulkan: wrong screen orientation on OpenHarmony (preTransform set without pre-rotation)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
libsdl-org/SDL#16670 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100