mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
LibJS: Fix that constant declaration in for loop was mutable in body
This commit is contained in:
parent
714f0c3dce
commit
8319d7ac06
3 changed files with 34 additions and 4 deletions
|
@ -98,6 +98,16 @@ describe("special left hand sides", () => {
|
|||
eval("for (f() in [0]) { expect().fail() }");
|
||||
}).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment");
|
||||
});
|
||||
|
||||
test("Cannot change constant declaration in body", () => {
|
||||
const vals = [];
|
||||
for (const v in [1, 2]) {
|
||||
expect(() => v++).toThrowWithMessage(TypeError, "Invalid assignment to const variable");
|
||||
vals.push(v);
|
||||
}
|
||||
|
||||
expect(vals).toEqual(["0", "1"]);
|
||||
});
|
||||
});
|
||||
|
||||
test("remove properties while iterating", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue