head-using-fresh-binding-per-iteration.js (1049B)
1 // |reftest| shell-option(--enable-explicit-resource-management) skip-if(!(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('explicit-resource-management'))||!xulRuntime.shell) -- explicit-resource-management is not enabled unconditionally, requires shell-options 2 // Copyright (C) 2023 Ron Buckton. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 /*--- 5 esid: sec-for-in-and-for-of-statements 6 description: > 7 ForDeclaration containing 'using' creates a fresh binding per iteration 8 features: [explicit-resource-management] 9 ---*/ 10 11 let f = [undefined, undefined, undefined]; 12 13 const obj1 = { [Symbol.dispose]() { } }; 14 const obj2 = { [Symbol.dispose]() { } }; 15 const obj3 = { [Symbol.dispose]() { } }; 16 17 let i = 0; 18 for (using x of [obj1, obj2, obj3]) { 19 f[i++] = function() { return x; }; 20 } 21 assert.sameValue(f[0](), obj1, "`f[0]()` returns `obj1`"); 22 assert.sameValue(f[1](), obj2, "`f[1]()` returns `obj2`"); 23 assert.sameValue(f[2](), obj3, "`f[2]()` returns `obj3`"); 24 25 reportCompare(0, 0);