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:
parent
d5fa0ea60f
commit
4bc98fd39f
2 changed files with 24 additions and 1 deletions
21
Userland/Libraries/LibJS/Tests/global-var-let-const.js
Normal file
21
Userland/Libraries/LibJS/Tests/global-var-let-const.js
Normal 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);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue