| 1 |
// Copyright (C) 2024 André Bargull. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-destructuring-binding-patterns-runtime-semantics-propertybindinginitialization |
| 6 |
description: > |
| 7 |
Ensure correct evaluation order for binding lookups when destructuring target is var-binding. |
| 8 |
info: | |
| 9 |
14.3.3.1 Runtime Semantics: PropertyBindingInitialization |
| 10 |
|
| 11 |
BindingProperty : PropertyName : BindingElement |
| 12 |
|
| 13 |
1. Let P be ? Evaluation of PropertyName. |
| 14 |
2. Perform ? KeyedBindingInitialization of BindingElement with arguments value, environment, and P. |
| 15 |
... |
| 16 |
|
| 17 |
14.3.3.3 Runtime Semantics: KeyedBindingInitialization |
| 18 |
|
| 19 |
SingleNameBinding : BindingIdentifier Initializer_opt |
| 20 |
|
| 21 |
1. Let bindingId be the StringValue of BindingIdentifier. |
| 22 |
2. Let lhs be ? ResolveBinding(bindingId, environment). |
| 23 |
3. Let v be ? GetV(value, propertyName). |
| 24 |
4. If Initializer is present and v is undefined, then |
| 25 |
... |
| 26 |
b. Else, |
| 27 |
i. Let defaultValue be ? Evaluation of Initializer. |
| 28 |
ii. Set v to ? GetValue(defaultValue). |
| 29 |
... |
| 30 |
6. Return ? InitializeReferencedBinding(lhs, v). |
| 31 |
|
| 32 |
9.4.2 ResolveBinding ( name [ , env ] ) |
| 33 |
|
| 34 |
... |
| 35 |
4. Return ? GetIdentifierReference(env, name, strict). |
| 36 |
|
| 37 |
9.1.2.1 GetIdentifierReference ( env, name, strict ) |
| 38 |
|
| 39 |
... |
| 40 |
2. Let exists be ? env.HasBinding(name). |
| 41 |
... |
| 42 |
|
| 43 |
includes: [compareArray.js] |
| 44 |
features: [Proxy] |
| 45 |
flags: [noStrict] |
| 46 |
---*/ |
| 47 |
|
| 48 |
var log = []; |
| 49 |
|
| 50 |
var sourceKey = { |
| 51 |
toString: () => { |
| 52 |
log.push("sourceKey"); |
| 53 |
return "p"; |
| 54 |
} |
| 55 |
}; |
| 56 |
|
| 57 |
var source = { |
| 58 |
get p() { |
| 59 |
log.push("get source"); |
| 60 |
return undefined; |
| 61 |
} |
| 62 |
}; |
| 63 |
|
| 64 |
var env = new Proxy({}, { |
| 65 |
has(t, pk) { |
| 66 |
log.push("binding::" + pk); |
| 67 |
return false; |
| 68 |
} |
| 69 |
}); |
| 70 |
|
| 71 |
var defaultValue = 0; |
| 72 |
|
| 73 |
var varTarget; |
| 74 |
|
| 75 |
with (env) { |
| 76 |
var { |
| 77 |
[sourceKey]: varTarget = defaultValue |
| 78 |
} = source; |
| 79 |
} |
| 80 |
|
| 81 |
assert.compareArray(log, [ |
| 82 |
"binding::source", |
| 83 |
"binding::sourceKey", |
| 84 |
"sourceKey", |
| 85 |
"binding::varTarget", |
| 86 |
"get source", |
| 87 |
"binding::defaultValue", |
| 88 |
]); |
| 89 |
|
| 90 |
reportCompare(0, 0); |