mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
When a function has parameter expressions (default values), body var declarations that shadow a name referenced in a default parameter expression must not be optimized to local variables. The default expression needs to resolve the name from the outer scope via the environment chain, not read the uninitialized local. We now mark identifiers referenced during formal parameter parsing with an IsReferencedInFormalParameters flag, and skip local variable optimization for body vars that carry both this flag and IsVar (but not IsForbiddenLexical, which indicates parameter names themselves).
20 lines
600 B
JavaScript
20 lines
600 B
JavaScript
// A body `var` that shadows a name referenced in a default parameter
|
|
// expression must resolve the name from the outer scope at runtime,
|
|
// not from the (uninitialized) body var binding.
|
|
|
|
// A body `var` that shadows a name used in a default -- must use GetBinding,
|
|
// and a separate variable environment must be created.
|
|
var shadow = "outer";
|
|
function shadow_in_default(x = shadow) {
|
|
var shadow = "inner";
|
|
return x;
|
|
}
|
|
shadow_in_default();
|
|
|
|
// No conflict -- body var `y` should stay a local (Mov, no GetBinding).
|
|
function no_conflict(x = 1) {
|
|
var y = 2;
|
|
return y;
|
|
}
|
|
no_conflict();
|