1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00

LibJS: Only "var" declarations go in the global object at program level

"let" and "const" go in the lexical environment.

This fixes one part of #4001 (Lexically declared variables are mixed up
with global object properties)
This commit is contained in:
Andreas Kling 2021-06-09 23:21:42 +02:00
parent d5fa0ea60f
commit 4bc98fd39f
2 changed files with 24 additions and 1 deletions

View file

@ -0,0 +1,21 @@
var foo = 1;
let bar = 2;
const baz = 3;
test("behavior of program-level var/let/const", () => {
expect(foo).toBe(1);
expect(bar).toBe(2);
expect(baz).toBe(3);
expect(globalThis.foo).toBe(1);
expect(globalThis.bar).toBeUndefined();
expect(globalThis.baz).toBeUndefined();
globalThis.foo = 4;
globalThis.bar = 5;
globalThis.baz = 6;
expect(foo).toBe(4);
expect(bar).toBe(2);
expect(baz).toBe(3);
expect(globalThis.foo).toBe(4);
expect(globalThis.bar).toBe(5);
expect(globalThis.baz).toBe(6);
});