mapfn-sync-arraylike.js (908B)
1 // |reftest| async 2 // Copyright (C) 2023 Igalia, S.L. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-array.fromasync 7 description: > 8 A synchronous mapping function is applied to each (awaited) item of an 9 arraylike. 10 info: | 11 3.k.vii.4. If _mapping_ is *true*, then 12 a. Let _mappedValue_ be ? Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). 13 ... 14 ... 15 6. Perform ? CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). 16 flags: [async] 17 includes: [asyncHelpers.js, compareArray.js] 18 features: [Array.fromAsync] 19 ---*/ 20 21 const arrayLike = { 22 length: 4, 23 0: 0, 24 1: 2, 25 2: Promise.resolve(4), 26 3: 6, 27 }; 28 29 function syncMap(val, ix) { 30 return val * ix; 31 } 32 33 asyncTest(async () => { 34 const result = await Array.fromAsync(arrayLike, syncMap); 35 assert.compareArray(result, [0, 2, 8, 18], "sync mapfn should be applied to arraylike"); 36 });