@@ -48,59 +48,109 @@ <h1><ins>Array.fromAsync ( _asyncItems_ [ , _mapfn_ [ , _thisArg_ ] ] )</ins></h
48
48
1. Else,
49
49
1. If IsCallable(_mapfn_ ) is *false* , throw a *TypeError* exception.
50
50
1. Let _mapping_ be *true* .
51
- 1. Let _usingAsyncOrSyncIterator_ be ? GetMethod(_asyncItems_ , @@asyncIterator).
52
- 1. If _usingAsyncOrSyncIterator_ is *undefined* , let _usingAsyncOrSyncIterator_ be ? GetMethod(_asyncItems_ , @@iterator).
53
- 1. If _usingAsyncOrSyncIterator_ is not *undefined* , then
54
- 1. If IsConstructor(_C_ ) is *true* , then
55
- 1. Let _A_ be ? Construct(_C_ ).
56
- 1. Else,
57
- 1. Let _A_ be ! ArrayCreate(0).
58
- 1. Let _iteratorRecord_ be ? GetIterator(_asyncItems_ , ~async~ , _usingAsyncOrSyncIterator_ ).
51
+ 1. Let _usingAsyncIterator_ be ? GetMethod(_asyncItems_ , @@asyncIterator).
52
+ 1. Else,
53
+ 1. Let _usingSyncIterator_ be ? GetMethod(_asyncItems_ , @@iterator).
54
+ 1. If _usingSyncIterator_ is *undefined* , set _usingIterator_ to CreateArrayIterator(_asyncItems_ , ~value~ ).
55
+ 1. If IsConstructor(_C_ ) is *true* , then
56
+ 1. Let _A_ be ? Construct(_C_ ).
57
+ 1. Else,
58
+ 1. Let _A_ be ! ArrayCreate(0).
59
+ 1. If _usingAsyncIterator_ is not *undefined* , then
60
+ 1. Let _iteratorRecord_ be ? GetIterator(_asyncItems_ , ~async~ , _usingAsyncIterator_ ).
61
+ 1. Else,
62
+ 1. Let _iteratorRecord_ be ? CreateAsyncFromSyncIterator(GetIterator(_asyncItems_ , ~sync~ , _usingSyncIterator_ )).
63
+ 1. Let _k_ be 0.
64
+ 1. Repeat,
65
+ 1. If _k_ &ge ; 2<sup >53</sup > - 1, then
66
+ 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
67
+ 1. Return ? AsyncIteratorClose(_iteratorRecord_ , _error_ ).
68
+ 1. Let _Pk_ be ! ToString(𝔽(_k_ )).
69
+ 1. Let _next_ be ? Await(IteratorStep(_iteratorRecord_ )).
70
+ 1. If _next_ is *false* , then
71
+ 1. Perform ? Set(_A_ , *"length"* , 𝔽(_k_ ), *true* ).
72
+ 1. Return _A_ .
73
+ 1. Let _nextValue_ be ? IteratorValue(_next_ ).
74
+ 1. If _mapping_ is *true* , then
75
+ 1. Let _mappedValue_ be Call(_mapfn_ , _thisArg_ , « ; _nextValue_ , 𝔽(_k_ ) » ; ).
76
+ 1. IfAbruptCloseAsyncIterator(_iteratorRecord_ , _mappedValue_ ).
77
+ 1. Let _mappedValue_ to Await(_mappedValue_ ).
78
+ 1. IfAbruptCloseAsyncIterator(_iteratorRecord_ , _mappedValue_ ).
79
+ 1. Set _mappedValue_ to _mappedValue_ .[[Value]].
80
+ 1. Else, let _mappedValue_ be _nextValue_ .
81
+ 1. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_ , _Pk_ , _mappedValue_ ).
82
+ 1. If _defineStatus_ is an abrupt completion, return ? AsyncIteratorClose(_iteratorRecord_ , _defineStatus_ ).
83
+ 1. Set _k_ to _k_ + 1.
84
+ 1. Perform AsyncFunctionStart(promiseCapability, _fromAsyncClosure_ ).
85
+ 1. Return Completion { [[Type]]: ~return~ , [[Value]]: _promiseCapability_ .[[Promise]], [[Target]]: ~empty~ }.
86
+ </emu-alg >
87
+ <emu-note >
88
+ <p >The `fromAsync` function is an intentionally generic factory method; it does not require that its *this* value be the Array constructor. Therefore it can be transferred to or inherited by any other constructors that may be called with a single numeric argument.</p >
89
+ </emu-note >
90
+ </emu-clause >
91
+ </emu-clause >
92
+ </emu-clause >
93
+
94
+ <emu-clause id =" sec-typedarray-objects" >
95
+ <h1 >TypedArray Objects</h1 >
96
+
97
+ <emu-clause id =" sec-properties-of-the-%typedarray%-intrinsic-object" >
98
+ <h1 >Properties of the %TypedArray% Intrinsic Object</h1 >
99
+
100
+ <emu-clause id =" sec-%typedarray%.fromAsync" >
101
+ <h1 ><ins >%TypedArray%.fromAsync ( _source_ [ , _mapfn_ [ , _thisArg_ ] ] )</ins ></h1 >
102
+
103
+ <emu-note type =editor >
104
+ <p >This section is a wholly new subsection of the <a
105
+ href =https://tc39.es/ecma262/#sec-properties-of-the-%typedarray%-intrinsic-object >original
106
+ Properties of the %TypedArray% Intrinsic Object clause</a >, to be inserted before the <a
107
+ href =https://tc39.es/ecma262/#sec-%typedarray%.from >%TypedArray%.from
108
+ clause</a >.</p >
109
+ </emu-note >
110
+
111
+ <p >When the `fromAsync` method is called, the following steps are taken:</p >
112
+ <emu-alg >
113
+ 1. Let _C_ be the *this* value.
114
+ 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
115
+ 1. Let _fromAsyncClosure_ be a new Abstract Closure with no parameters that captures _C_ and _mapfn_ and performs the following steps when called:
116
+ 1. If IsConstructor(_C_ ) is *false* , throw a *TypeError* exception.
117
+ 1. If _mapfn_ is *undefined* , let _mapping_ be *false* .
118
+ 1. Else,
119
+ 1. If IsCallable(_mapfn_ ) is *false* , throw a *TypeError* exception.
120
+ 1. Let _mapping_ be *true* .
121
+ 1. Let _usingIterator_ be ? GetMethod(_source_ , @@iterator).
122
+ 1. If _usingIterator_ is not *undefined* , then
123
+ 1. Let _values_ be ? IterableToList(_source_ , _usingIterator_ ).
124
+ 1. Let _len_ be the number of elements in _values_ .
125
+ 1. Let _targetObj_ be ? TypedArrayCreate(_C_ , « ; 𝔽(_len_ ) » ; ).
59
126
1. Let _k_ be 0.
60
- 1. Repeat,
61
- 1. If _k_ &ge ; 2<sup >53</sup > - 1, then
62
- 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
63
- 1. Return ? AsyncIteratorClose(_iteratorRecord_ , _error_ ).
127
+ 1. Repeat, while _k_ < ; _len_ ,
64
128
1. Let _Pk_ be ! ToString(𝔽(_k_ )).
65
- 1. Let _next_ be ? Await(IteratorStep(_iteratorRecord_ )).
66
- 1. If _next_ is *false* , then
67
- 1. Perform ? Set(_A_ , *"length"* , 𝔽(_k_ ), *true* ).
68
- 1. Return _A_ .
69
- 1. Let _nextValue_ be ? IteratorValue(_next_ ).
129
+ 1. Let _kValue_ be the first element of _values_ and remove that element from _values_ .
70
130
1. If _mapping_ is *true* , then
71
- 1. Let _mappedValue_ be Call(_mapfn_ , _thisArg_ , « ; _nextValue_ , 𝔽(_k_ ) » ; ).
72
- 1. IfAbruptCloseAsyncIterator(_iteratorRecord_ , _mappedValue_ ).
73
- 1. Let _mappedValue_ to Await(_mappedValue_ ).
74
- 1. IfAbruptCloseAsyncIterator(_iteratorRecord_ , _mappedValue_ ).
75
- 1. Set _mappedValue_ to _mappedValue_ .[[Value]].
76
- 1. Else, let _mappedValue_ be _nextValue_ .
77
- 1. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_ , _Pk_ , _mappedValue_ ).
78
- 1. If _defineStatus_ is an abrupt completion, return ? AsyncIteratorClose(_iteratorRecord_ , _defineStatus_ ).
131
+ 1. Let _mappedValue_ be ? Call(_mapfn_ , _thisArg_ , « ; _kValue_ , 𝔽(_k_ ) » ; ).
132
+ 1. Else, let _mappedValue_ be _kValue_ .
133
+ 1. Perform ? Set(_targetObj_ , _Pk_ , _mappedValue_ , *true* ).
79
134
1. Set _k_ to _k_ + 1.
80
- 1. NOTE: _items_ is not an AsyncIterable or Iterable so assume it is an array-like object.
81
- 1. Let _arrayLike_ be ! ToObject(_items_ ).
135
+ 1. Assert: _values_ is now an empty List.
136
+ 1. Return _targetObj_ .
137
+ 1. NOTE: _source_ is not an Iterable so assume it is already an array-like object.
138
+ 1. Let _arrayLike_ be ! ToObject(_source_ ).
82
139
1. Let _len_ be ? LengthOfArrayLike(_arrayLike_ ).
83
- 1. If IsConstructor(_C_ ) is *true* , then
84
- 1. Let _A_ be ? Construct(_C_ , « ; 𝔽(_len_ ) » ; ).
85
- 1. Else,
86
- 1. Let _A_ be ? ArrayCreate(_len_ ).
140
+ 1. Let _targetObj_ be ? TypedArrayCreate(_C_ , « ; 𝔽(_len_ ) » ; ).
87
141
1. Let _k_ be 0.
88
142
1. Repeat, while _k_ < ; _len_ ,
89
143
1. Let _Pk_ be ! ToString(𝔽(_k_ )).
90
144
1. Let _kValue_ be ? Get(_arrayLike_ , _Pk_ ).
91
145
1. If _mapping_ is *true* , then
92
146
1. Let _mappedValue_ be ? Call(_mapfn_ , _thisArg_ , « ; _kValue_ , 𝔽(_k_ ) » ; ).
93
147
1. Else, let _mappedValue_ be _kValue_ .
94
- 1. Perform ? CreateDataPropertyOrThrow( _A_ , _Pk_ , _mappedValue_ ).
148
+ 1. Perform ? Set( _targetObj_ , _Pk_ , _mappedValue_ , *true* ).
95
149
1. Set _k_ to _k_ + 1.
96
- 1. Perform ? Set(_A_ , *"length"* , 𝔽(_len_ ), *true* ).
97
- 1. Return _A_ .
150
+ 1. Return _targetObj_ .
98
151
1. Perform AsyncFunctionStart(promiseCapability, _fromAsyncClosure_ ).
99
152
1. Return Completion { [[Type]]: ~return~ , [[Value]]: _promiseCapability_ .[[Promise]], [[Target]]: ~empty~ }.
100
153
</emu-alg >
101
- <emu-note >
102
- <p >The `fromAsync` function is an intentionally generic factory method; it does not require that its *this* value be the Array constructor. Therefore it can be transferred to or inherited by any other constructors that may be called with a single numeric argument.</p >
103
- </emu-note >
104
154
</emu-clause >
105
155
</emu-clause >
106
156
</emu-clause >
0 commit comments