head-await-using-fresh-binding-per-iteration.js (1117B)
1 // |reftest| shell-option(--enable-explicit-resource-management) skip-if(!(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('explicit-resource-management'))||!xulRuntime.shell) module -- 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 'await using' creates a fresh binding per iteration 8 flags: [module] 9 features: [explicit-resource-management] 10 ---*/ 11 12 let f = [undefined, undefined, undefined]; 13 14 const obj1 = { async [Symbol.asyncDispose]() { } }; 15 const obj2 = { async [Symbol.asyncDispose]() { } }; 16 const obj3 = { async [Symbol.asyncDispose]() { } }; 17 18 let i = 0; 19 for (await using x of [obj1, obj2, obj3]) { 20 f[i++] = function() { return x; }; 21 } 22 assert.sameValue(f[0](), obj1, "`f[0]()` returns `obj1`"); 23 assert.sameValue(f[1](), obj2, "`f[1]()` returns `obj2`"); 24 assert.sameValue(f[2](), obj3, "`f[2]()` returns `obj3`"); 25 26 reportCompare(0, 0);