archives

« Bugzilla Issues Index

#4351 — 12.14.5.2 DestructuringAssignmentEvaluation, 13.3.3.5 BindingInitialization: Different null/undefined checks


12.14.5.2 Runtime Semantics: DestructuringAssignmentEvaluation
13.3.3.5 Runtime Semantics: BindingInitialization

13.3.3.5 BindingInitialization starts with calling RequireObjectCoercible, cf. step 1 for `BindingPattern : ObjectBindingPattern`.

Compared to that, 12.14.5.2 DestructuringAssignmentEvaluation does not call RequireObjectCoercible for non-empty object destructuring. The null/undefined checks are executed implicitly when calling GetV in 12.14.5.4 KeyedDestructuringAssignmentEvaluation.


Test case:
---
with (new Proxy({}, {
has(t, p) {
print(`has:${p}`);
return Reflect.has(t,p);
}
})) {
var {a} = null; // has:a is not printed
}
---

---
var a;
with (new Proxy({}, {
has(t, p) {
print(`has:${p}`);
return Reflect.has(t,p);
}
})) {
({a} = null); // has:a is printed !
}
---


Smaller tests without with+Proxy:
---
var a;
({[print("hello")]: a} = null); // Prints "hello"


var {[print("hello")]: a} = null; // Does not print "hello"
---


fixed in rev39 publication draft

added to 12.14.5.2

ObjectAssignmentPattern :
{ AssignmentPropertyList }
{ AssignmentPropertyList , }

1. Let valid be RequireObjectCoercible(value).
2. ReturnIfAbrupt(valid).
3. Return the result of performing DestructuringAssignmentEvaluation for AssignmentPropertyList using value as the argument.