mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 18:17:22 +02:00
LibJS: Fix scope detection for ids in default function params
This change fixes an issue where identifiers used in default function parameters were being "registered" in the function's parent scope instead of its own scope. This bug resulted in incorrectly detected local variables. (Variables used in the default function parameter expression should be considered 'captured by nested function'.) To resolve this issue, the function scope is now created before parsing function parameters. Since function parameters can no longer be passed in the constructor, a setter function has been introduced to set them later, when they are ready.
This commit is contained in:
committed by
Andreas Kling
parent
996c020b0d
commit
2f85faef0f
Notes:
sideshowbarker
2024-07-17 22:41:14 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/2f85faef0f Pull-request: https://github.com/SerenityOS/serenity/pull/19873
@@ -141,3 +141,13 @@ test("parameter with an object default value", () => {
|
||||
expect(arrowFunc()).toBe("bar");
|
||||
expect(arrowFunc({ foo: "baz" })).toBe("baz");
|
||||
});
|
||||
|
||||
test("use variable as default function parameter", () => {
|
||||
let a = 1;
|
||||
|
||||
function func(param = a) {
|
||||
return param;
|
||||
}
|
||||
|
||||
expect(func()).toBe(a);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user