mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 08:39:22 +00:00
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:
parent
7d420bbd3d
commit
049109452e
Notes:
github-actions[bot]
2025-01-21 13:59:50 +00:00
Author: https://github.com/trflynn89
Commit: 049109452e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3324
2 changed files with 8 additions and 1 deletions
|
@ -551,7 +551,10 @@ ThrowCompletionOr<void> VM::link_and_eval_module(Badge<Bytecode::Interpreter>, S
|
||||||
ThrowCompletionOr<void> VM::link_and_eval_module(CyclicModule& module)
|
ThrowCompletionOr<void> VM::link_and_eval_module(CyclicModule& module)
|
||||||
{
|
{
|
||||||
auto filename = module.filename();
|
auto filename = module.filename();
|
||||||
module.load_requested_modules(nullptr);
|
auto& promise_capability = module.load_requested_modules(nullptr);
|
||||||
|
|
||||||
|
if (auto const& promise = verify_cast<Promise>(*promise_capability.promise()); promise.state() == Promise::State::Rejected)
|
||||||
|
return JS::throw_completion(promise.result());
|
||||||
|
|
||||||
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Linking module {}", filename);
|
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Linking module {}", filename);
|
||||||
auto linked_or_error = module.link(*this);
|
auto linked_or_error = module.link(*this);
|
||||||
|
|
|
@ -219,6 +219,10 @@ describe("in- and exports", () => {
|
||||||
expect(result.default).toBeInstanceOf(RegExp);
|
expect(result.default).toBeInstanceOf(RegExp);
|
||||||
expect(result.default.toString()).toBe(/foo/.toString());
|
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", () => {
|
describe("loops", () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue