| 1 |
// |reftest| async |
| 2 |
'use strict'; |
| 3 |
// Copyright (C) 2022 Igalia, S.L. All rights reserved. |
| 4 |
// This code is governed by the BSD license found in the LICENSE file. |
| 5 |
|
| 6 |
/*--- |
| 7 |
esid: sec-array.fromasync |
| 8 |
description: > |
| 9 |
If thisArg is a primitive, mapfn is called with it as the this-value in strict |
| 10 |
mode |
| 11 |
info: | |
| 12 |
6. If _mapping_ is *true*, then |
| 13 |
a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). |
| 14 |
|
| 15 |
In OrdinaryCallBindThis, _thisArgument_ is always bound as the this-value in |
| 16 |
strict mode (_F_.[[ThisMode]] is ~strict~, where _F_ is the function object.) |
| 17 |
flags: [async, onlyStrict] |
| 18 |
includes: [asyncHelpers.js] |
| 19 |
features: [Array.fromAsync] |
| 20 |
---*/ |
| 21 |
|
| 22 |
asyncTest(async () => { |
| 23 |
await Array.fromAsync([1, 2, 3], async function () { |
| 24 |
assert.sameValue(this, undefined, "undefined thisArg should be bound as the this-value of mapfn"); |
| 25 |
}, undefined); |
| 26 |
|
| 27 |
await Array.fromAsync([1, 2, 3], async function () { |
| 28 |
assert.sameValue(this, null, "null thisArg should be bound as the this-value of mapfn"); |
| 29 |
}, null); |
| 30 |
|
| 31 |
await Array.fromAsync([1, 2, 3], async function () { |
| 32 |
assert.sameValue(this, "string", "string thisArg should be bound as the this-value of mapfn"); |
| 33 |
}, "string"); |
| 34 |
|
| 35 |
await Array.fromAsync([1, 2, 3], async function () { |
| 36 |
assert.sameValue(this, 3.1416, "number thisArg should be bound as the this-value of mapfn"); |
| 37 |
}, 3.1416); |
| 38 |
|
| 39 |
await Array.fromAsync([1, 2, 3], async function () { |
| 40 |
assert.sameValue(this, 42n, "bigint thisArg should be bound as the this-value of mapfn"); |
| 41 |
}, 42n); |
| 42 |
|
| 43 |
await Array.fromAsync([1, 2, 3], async function () { |
| 44 |
assert.sameValue(this, true, "boolean thisArg should be bound as the this-value of mapfn"); |
| 45 |
}, true); |
| 46 |
|
| 47 |
const symbolThis = Symbol("symbol"); |
| 48 |
await Array.fromAsync([1, 2, 3], async function () { |
| 49 |
assert.sameValue(this, symbolThis, "symbol thisArg should be bound as the this-value of mapfn"); |
| 50 |
}, symbolThis); |
| 51 |
}); |