Files
ladybird/Tests/LibJS/Runtime/global-declaration-instantiation-error-skips-evaluation.js
Andreas Kling 7df998166c LibJS: Check result of GlobalDeclarationInstantiation before evaluating
Per step 13 of ScriptEvaluation in the ECMA-262 spec, the script body
should only be evaluated if GlobalDeclarationInstantiation returned a
normal completion.

This can't currently be triggered since we always create fresh Script
objects, but if we ever start reusing cached executables across
evaluations, this would prevent a subtle bug where the script body
runs despite GDI failing.
2026-02-19 12:02:50 +01:00

8 lines
348 B
JavaScript

test("script body is not evaluated when GlobalDeclarationInstantiation fails", () => {
evaluateSource("let x = 1;");
expect(() => {
evaluateSource("let x = 2; globalThis.__side_effect = true;");
}).toThrowWithMessage(SyntaxError, "Redeclaration of top level variable");
expect(globalThis.__side_effect).toBeUndefined();
});