LibJS: Do not attempt to link modules which have failed to load

Linking a module has assertions about the module's state, namely that
the state is not "new". The state remains "new" if loading the module
has failed. See: https://tc39.es/ecma262/#figure-module-graph-missing

    In any case, this exception causes a loading failure, which results
    in A's [[Status]] remaining new.

So we must propagate that failure, instead of blindly moving on to the
linking steps.
This commit is contained in:
Timothy Flynn 2025-01-20 11:10:07 -05:00 committed by Andreas Kling
commit 049109452e
Notes: github-actions[bot] 2025-01-21 13:59:50 +00:00
2 changed files with 8 additions and 1 deletions

View file

@ -219,6 +219,10 @@ describe("in- and exports", () => {
expect(result.default).toBeInstanceOf(RegExp);
expect(result.default.toString()).toBe(/foo/.toString());
});
test("importing a non-existent file results in a SyntaxError", () => {
expectedModuleToThrowSyntaxError("./i-do-no-exist.mjs", "Cannot find/open module");
});
});
describe("loops", () => {