2 // Copyright (C) 2022 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
6 esid: sec-array.fromasync
8 If thisArg is a primitive, mapfn is called with a wrapper this-value or the
9 global, according to the usual rules of sloppy mode
11 6. If _mapping_ is *true*, then
12 a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »).
14 OrdinaryCallBindThis, when _F_.[[ThisMode]] is ~global~, where _F_ is the
17 a. If _thisArgument_ is *undefined* or *null*, then
18 i. Let _globalEnv_ be _calleeRealm_.[[GlobalEnv]].
19 ii. Assert: _globalEnv_ is a Global Environment Record.
20 iii. Let _thisValue_ be _globalEnv_.[[GlobalThisValue]].
22 i. Let _thisValue_ be ! ToObject(_thisArgument_).
23 ii. NOTE: ToObject produces wrapper objects using _calleeRealm_.
24 flags: [async, noStrict]
25 includes: [asyncHelpers.js]
26 features: [Array.fromAsync]
29 asyncTest(async () => {
30 await Array.fromAsync([1, 2, 3], async function () {
34 "the global should be bound as the this-value of mapfn when thisArg is undefined"
38 await Array.fromAsync([1, 2, 3], async function () {
42 "the global should be bound as the this-value of mapfn when thisArg is null"
46 await Array.fromAsync([1, 2, 3], async function () {
47 assert.notSameValue(this, "string", "string thisArg should not be bound as the this-value of mapfn");
48 assert.sameValue(typeof this, "object", "a String wrapper object should be bound as the this-value of mapfn when thisArg is a string")
49 assert.sameValue(this.valueOf(), "string", "String wrapper object should have the same primitive value as thisArg");
52 await Array.fromAsync([1, 2, 3], async function () {
53 assert.notSameValue(this, 3.1416, "number thisArg should be not bound as the this-value of mapfn");
54 assert.sameValue(typeof this, "object", "a Number wrapper object should be bound as the this-value of mapfn when thisArg is a number")
55 assert.sameValue(this.valueOf(), 3.1416, "Number wrapper object should have the same primitive value as thisArg");
58 await Array.fromAsync([1, 2, 3], async function () {
59 assert.notSameValue(this, 42n, "bigint thisArg should not be bound as the this-value of mapfn");
60 assert.sameValue(typeof this, "object", "a BigInt wrapper object should be bound as the this-value of mapfn when thisArg is a bigint")
61 assert.sameValue(this.valueOf(), 42n, "BigInt wrapper object should have the same primitive value as thisArg");
64 await Array.fromAsync([1, 2, 3], async function () {
65 assert.notSameValue(this, true, "boolean thisArg should not be bound as the this-value of mapfn");
66 assert.sameValue(typeof this, "object", "a Boolean wrapper object should be bound as the this-value of mapfn when thisArg is a boolean")
67 assert.sameValue(this.valueOf(), true, "Boolean wrapper object should have the same primitive value as thisArg");
70 const symbolThis = Symbol("symbol");
71 await Array.fromAsync([1, 2, 3], async function () {
72 assert.notSameValue(this, symbolThis, "symbol thisArg should not be bound as the this-value of mapfn");
73 assert.sameValue(typeof this, "object", "a Symbol wrapper object should be bound as the this-value of mapfn when thisArg is a symbol")
74 assert.sameValue(this.valueOf(), symbolThis, "Symbol wrapper object should have the same primitive value as thisArg");