array-pattern-emulates-undefined.js (1191B)
1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-destructuring-binding-patterns-runtime-semantics-bindinginitialization 5 description: > 6 Destructuring initializer is not evaluated when value is an object 7 with [[IsHTMLDDA]] internal slot. 8 info: | 9 BindingPattern : ArrayBindingPattern 10 11 1. Let iteratorRecord be ? GetIterator(value). 12 2. Let result be IteratorBindingInitialization of ArrayBindingPattern with arguments 13 iteratorRecord and environment. 14 3. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iteratorRecord, result). 15 4. Return result. 16 17 Runtime Semantics: IteratorBindingInitialization 18 19 SingleNameBinding : BindingIdentifier Initializer[opt] 20 21 [...] 22 5. If Initializer is present and v is undefined, then 23 [...] 24 6. If environment is undefined, return ? PutValue(lhs, v). 25 features: [destructuring-binding, IsHTMLDDA] 26 ---*/ 27 28 let initCount = 0; 29 const counter = function() { 30 initCount += 1; 31 }; 32 33 const IsHTMLDDA = $262.IsHTMLDDA; 34 const [x = counter()] = [IsHTMLDDA]; 35 36 assert.sameValue(x, IsHTMLDDA); 37 assert.sameValue(initCount, 0); 38 39 reportCompare(0, 0);