This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
spec.html
438 lines (399 loc) · 26.6 KB
/
spec.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<!DOCTYPE html>
<meta charset="utf8" />
<pre class="metadata">
title: Change Array by copy
stage: 2
contributors: Robin Ricard, Ashley Claymore
</pre>
<emu-biblio href="biblio.json"></emu-biblio>
<emu-clause id="sec-indexed-collections">
<h1>Indexed Collections</h1>
<emu-clause id="sec-array-objects">
<h1>Array Objects</h1>
<emu-clause id="sec-properties-of-the-array-prototype-object">
<h1>Properties of the Array Prototype Object</h1>
<emu-clause id="sec-array.prototype.sort" oldids="sec-sortcompare">
<h1>Array.prototype.sort ( _comparefn_ )</h1>
<p>When the `sort` method is called, the following steps are taken:</p>
<emu-alg>
1. [id="step-array-sort-comparefn"] If _comparefn_ is not *undefined* and IsCallable(_comparefn_) is *false*, throw a *TypeError* exception.
1. Let _obj_ be ? ToObject(*this* value).
1. [id="step-array-sort-len"] Let _len_ be ? LengthOfArrayLike(_obj_).
1. Let _SortCompare_ be a new Abstract Closure with parameters (_x_, _y_) that captures _comparefn_ and performs the following steps when called:
1. <del>If _x_ and _y_ are both *undefined*, return *+0*<sub>𝔽</sub>.</del>
1. <del>If _x_ is *undefined*, return *1*<sub>𝔽</sub>.</del>
1. <del>If _y_ is *undefined*, return *-1*<sub>𝔽</sub>.</del>
1. <del>If _comparefn_ is not *undefined*, then</del>
1. <del>Let _v_ be ? ToNumber(? Call(_comparefn_, *undefined*, « _x_, _y_ »)).</del>
1. <del>If _v_ is *NaN*, return *+0*<sub>𝔽</sub>.</del>
1. <del>Return _v_.</del>
1. <del>[id="step-sortcompare-tostring-x"] Let _xString_ be ? ToString(_x_).</del>
1. <del>[id="step-sortcompare-tostring-y"] Let _yString_ be ? ToString(_y_).</del>
1. <del>Let _xSmaller_ be ! IsLessThan(_xString_, _yString_, *true*).</del>
1. <del>If _xSmaller_ is *true*, return *-1*<sub>𝔽</sub>.</del>
1. <del>Let _ySmaller_ be ! IsLessThan(_yString_, _xString_, *true*).</del>
1. <del>If _ySmaller_ is *true*, return *1*<sub>𝔽</sub>.</del>
1. <del>Return *+0*<sub>𝔽</sub>.</del>
1. <ins>Return ? CompareArrayElements(_x_, _y_, _comparefn_).</ins>
1. <del>Return ? SortIndexedProperties(_obj_, _len_, _SortCompare_).</del>
1. [id="step-array-sortindexedproperties"] <ins>Let _sortedList_ be ? SortIndexedProperties(_obj_, _len_, _SortCompare_, *true*).</ins>
1. <ins>Let _itemCount_ be the number of elements in _sortedList_.</ins>
1. <ins>Let _j_ be 0.</ins>
1. <ins>Repeat, while _j_ < _itemCount_,</ins>
1. <ins>Perform ? Set(_obj_, ! ToString(𝔽(_j_)), _sortedList_[_j_], true).</ins>
1. <ins>Set _j_ to _j_ + 1.</ins>
1. <ins>NOTE: The call to SortIndexedProperties in step <emu-xref href="#step-array-sortindexedproperties"></emu-xref> has the *skipHoles* parameter set to *true*. The remaining indexes are deleted to preserve the number of holes that were detected and excluded from the sort.</ins>
1. <ins>Repeat, while _j_ < _len_,</ins>
1. <ins>Perform ? DeletePropertyOrThrow(_obj_, ! ToString(𝔽(_j_))).</ins>
1. <ins>Set _j_ to _j_ + 1.</ins>
1. <ins>Return _obj_.</ins>
</emu-alg>
</emu-clause>
<emu-clause id="sec-comparearrayelements" type="abstract operation">
<h1>
CompareArrayElements(
_x_: unknown,
_y_: unknown,
_comparefn_: a function object or *undefined*
): either a normal completion containing a Number or an abrupt completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. If _x_ and _y_ are both *undefined*, return *+0*<sub>𝔽</sub>.
1. If _x_ is *undefined*, return *1*<sub>𝔽</sub>.
1. If _y_ is *undefined*, return *-1*<sub>𝔽</sub>.
1. If _comparefn_ is not *undefined*, then
1. Let _v_ be ? ToNumber(? Call(_comparefn_, *undefined*, « _x_, _y_ »)).
1. If _v_ is *NaN*, return *+0*<sub>𝔽</sub>.
1. Return _v_.
1. [id="step-sortcompare-tostring-x"] Let _xString_ be ? ToString(_x_).
1. [id="step-sortcompare-tostring-y"] Let _yString_ be ? ToString(_y_).
1. Let _xSmaller_ be ! IsLessThan(_xString_, _yString_, *true*).
1. If _xSmaller_ is *true*, return *-1*<sub>𝔽</sub>.
1. Let _ySmaller_ be ! IsLessThan(_yString_, _xString_, *true*).
1. If _ySmaller_ is *true*, return *1*<sub>𝔽</sub>.
1. Return *+0*<sub>𝔽</sub>.
</emu-alg>
</emu-clause>
<emu-clause id="sec-sortindexedproperties" type="abstract operation">
<h1>
SortIndexedProperties (
_obj_: an Object,
_len_: a non-negative integer,
_SortCompare_: an Abstract Closure with two parameters,
<ins>_skipHoles_: a Boolean</ins>
): either a normal completion containing <del>an Object</del><ins>a List</ins> or an abrupt completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. Let _items_ be a new empty List.
1. Let _k_ be 0.
1. Repeat, while _k_ < _len_,
1. Let _Pk_ be ! ToString(𝔽(_k_)).
1. <del>Let _kPresent_ be ? HasProperty(_obj_, _Pk_).</del>
1. <ins>If _skipHoles_ is *true*, then</ins>
1. <ins>Let _kRead_ be ? HasProperty(_obj_, _Pk_).</ins>
1. <ins>Else,</ins>
1. <ins>Let _kRead_ be *true*.</ins>
1. If <del>_kPresent_</del><ins>_kRead_</ins> is *true*, then
1. Let _kValue_ be ? Get(_obj_, _Pk_).
1. Append _kValue_ to _items_.
1. Set _k_ to _k_ + 1.
1. <del>Let _itemCount_ be the number of elements in _items_.</del>
1. [id="step-array-sort"] Sort _items_ using an implementation-defined sequence of calls to _SortCompare_. If any such call returns an abrupt completion, stop before performing any further calls to _SortCompare_ or steps in this algorithm and return that Completion Record.
1. <del>Let _j_ be 0.</del>
1. <del>Repeat, while _j_ < _itemCount_,</del>
1. <del>Perform ? Set(_obj_, ! ToString(𝔽(_j_)), _items_[_j_], *true*).</del>
1. <del>Set _j_ to _j_ + 1.</del>
1. <del>Repeat, while _j_ < _len_,</del>
1. <del>Perform ? DeletePropertyOrThrow(_obj_, ! ToString(𝔽(_j_))).</del>
1. <del>Set _j_ to _j_ + 1.</del>
1. <del>Return _obj_.</del>
1. <ins>Return _items_.</ins>
</emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype.toReversed">
<h1>Array.prototype.toReversed ( )</h1>
<p>When the *toReversed* method is called, the following steps are taken:</p>
<emu-alg>
1. Let _O_ be ? ToObject(*this* value).
1. Let _len_ be ? LengthOfArrayLike(_O_).
1. Let _A_ be ? ArrayCreate(𝔽(_len_)).
1. Let _k_ be 0.
1. Repeat, while _k_ < _len_,
1. Let _from_ be ! ToString(𝔽(_len_ - _k_ - 1)).
1. Let _Pk_ be ! ToString(𝔽(_k_)).
1. Let _fromValue_ be ? Get(_O_, _from_).
1. Perform ! CreateDataPropertyOrThrow(_A_, _Pk_, _fromValue_).
1. Set _k_ to _k_ + 1.
1. Return _A_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype.toSorted">
<h1>Array.prototype.toSorted ( _comparefn_ )</h1>
<p>When the *toSorted* method is called, the following steps are taken:</p>
<emu-alg>
1. If _comparefn_ is not *undefined* and IsCallable(_comparefn_) is *false*, throw a *TypeError* exception.
1. Let _O_ be ? ToObject(*this* value).
1. Let _len_ be ? LengthOfArrayLike(_O_).
1. Let _A_ be ? ArrayCreate(𝔽(_len_)).
1. Let _SortCompare_ be a new Abstract Closure with parameters (_x_, _y_) that captures _comparefn_ and performs the following steps when called:
1. Return ? CompareArrayElements(_x_, _y_, _comparefn_).
1. Let _sortedList_ be ? SortIndexedProperties(_obj_, _len_, _SortCompare_, *false*).
1. Let _j_ be 0.
1. Repeat, while _j_ < _len_,
1. Perform ! CreateDataPropertyOrThrow(_A_, ! ToString(𝔽(_j_)), _sortedList_[_j_]).
1. Set _j_ to _j_ + 1.
1. Return _A_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype.toSpliced">
<h1>Array.prototype.toSpliced ( _start_, _deleteCount_, ..._items_ )</h1>
<p>When the *toSpliced* method is called, the following steps are taken:</p>
<emu-alg>
1. Let _O_ be ? ToObject(*this* value).
1. Let _len_ be ? LengthOfArrayLike(_O_).
1. Let _relativeStart_ be ? ToIntegerOrInfinity(_start_).
1. If _relativeStart_ is -∞, let _actualStart_ be 0.
1. Else if _relativeStart_ < 0, let _actualStart_ be max(_len_ + _relativeStart_, 0).
1. Else, let _actualStart_ be min(_relativeStart_, _len_).
1. Let _insertCount_ be the number of elements in _items_.
1. If _start_ is not present, then
1. Let _actualDeleteCount_ be 0.
1. Else if _deleteCount_ is not present, then
1. Let _actualDeleteCount_ be _len_ - _actualStart_.
1. Else,
1. Let _dc_ be ? ToIntegerOrInfinity(_deleteCount_).
1. Let _actualDeleteCount_ be the result of clamping _dc_ between 0 and _len_ - _actualStart_.
1. Let _newLen_ be _len_ + _insertCount_ - _actualDeleteCount_.
1. If _newLen_ > 2<sup>53</sup> - 1, throw a *TypeError* exception.
1. Let _A_ be ? ArrayCreate(𝔽(_newLen_)).
1. Let _i_ be 0.
1. Let _r_ be _actualStart_ + _actualDeleteCount_.
1. Repeat, while _i_ < _actualStart_,
1. Let _Pi_ be ! ToString(𝔽(_i_)).
1. Let _iValue_ be ? Get(_O_, _Pi_).
1. Perform ! CreateDataPropertyOrThrow(_A_, _Pi_, _iValue_).
1. Set _i_ to _i_ + 1.
1. For each element _E_ of _items_, do
1. Let _Pi_ be ! ToString(𝔽(_i_)).
1. Perform ! CreateDataPropertyOrThrow(_A_, _Pi_, _E_).
1. Set _i_ to _i_ + 1.
1. Repeat, while _i_ < _newLen_,
1. Let _Pi_ be ! ToString(𝔽(_i_)).
1. Let _from_ be ! ToString(𝔽(_r_)).
1. Let _fromValue_ be ? Get(_O_, _from_).
1. Perform ! CreateDataPropertyOrThrow(_A_, _Pi_, _fromValue_).
1. Set _i_ to _i_ + 1.
1. Set _r_ to _r_ + 1.
1. Return _A_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype.with">
<h1>Array.prototype.with ( _index_, _value_ )</h1>
<p>When the *with* method is called, the following steps are taken:</p>
<emu-alg>
1. Let _O_ be ? ToObject(*this* value).
1. Let _len_ be ? LengthOfArrayLike(_O_).
1. Let _relativeIndex_ be ? ToIntegerOrInfinity(_index_).
1. If _relativeIndex_ ≥ 0, let _actualIndex_ be _relativeIndex_.
1. Else, let _actualIndex_ be _len_ + _relativeIndex_.
1. If _actualIndex_ ≥ _len_ or _actualIndex_ < 0, throw a *RangeError* exception.
1. Let _A_ be ? ArrayCreate(𝔽(_len_)).
1. Let _k_ be 0.
1. Repeat, while _k_ < _len_,
1. Let _Pk_ be ! ToString(𝔽(_k_)).
1. If _k_ is _actualIndex_, let _fromValue_ be _value_.
1. Else, let _fromValue_ be ? Get(_O_, _Pk_).
1. Perform ! CreateDataPropertyOrThrow(_A_, _Pk_, _fromValue_).
1. Set _k_ to _k_ + 1.
1. Return _A_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype-@@unscopables">
<h1>Array.prototype [ @@unscopables ]</h1>
<p>The initial value of the @@unscopables data property is an object created by the following steps:</p>
<emu-alg>
1. Let _unscopableList_ be ! OrdinaryObjectCreate(*null*).
1. Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"at"*, *true*).
1. Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"copyWithin"*, *true*).
1. Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"entries"*, *true*).
1. Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"fill"*, *true*).
1. Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"find"*, *true*).
1. Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"findIndex"*, *true*).
1. Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"flat"*, *true*).
1. Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"flatMap"*, *true*).
1. Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"includes"*, *true*).
1. Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"keys"*, *true*).
1. <ins>Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"toReversed"*, *true*).</ins>
1. <ins>Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"toSorted"*, *true*).</ins>
1. <ins>Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"toSpliced"*, *true*).</ins>
1. Perform ! CreateDataPropertyOrThrow(_unscopableList_, *"values"*, *true*).
1. Return _unscopableList_.
</emu-alg>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.</p>
<emu-note>
<p>The reason that *"with"* is not included in the _unscopableList_ is because it is already a <emu-xref href="#sec-keywords-and-reserved-words">reserved word</emu-xref>.</p>
</emu-note>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-typedarray-objects">
<h1>TypedArray Objects</h1>
<emu-clause id="sec-abstract-operations-for-typedarray-objects">
<h1>Abstract Operations for TypedArray Objects</h1>
<emu-clause id="typedarray-create-same-type" type="abstract operation">
<h1>
TypedArrayCreateSameType (
_exemplar_: a TypedArray,
_argumentList_: unknown,
)
</h1>
<dl class="header">
<dt>description</dt>
<dd>It is used to specify the creation of a new TypedArray using a constructor function that is derived from _exemplar_. Unlike TypedArraySpeciesCreate, which can construct custom TypedArray subclasses through the use of @@species, this operation always uses one of the built-in TypedArray constructors.</dd>
</dl>
<emu-alg>
1. Assert: _exemplar_ is an Object that has [[TypedArrayName]] and [[ContentType]] internal slots.
1. Let _constructor_ be the intrinsic object listed in column one of <emu-xref href="#table-the-typedarray-constructors"></emu-xref> for _exemplar_.[[TypedArrayName]].
1. Let _result_ be ? TypedArrayCreate(_constructor_, _argumentList_).
1. Assert: _result_ has [[TypedArrayName]] and [[ContentType]] internal slots.
1. Assert: _result_.[[ContentType]] is _exemplar_.[[ContentType]].
1. Return _result_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-%typedarray%-intrinsic-object">
<h1>The %TypedArray% Intrinsic Object</h1>
<emu-clause id="sec-properties-of-the-%typedarrayprototype%-object">
<h1>Properties of the %TypedArray% Prototype Object</h1>
<emu-clause id="sec-%typedarray%.prototype.sort" oldids="sec-typedarraysortcompare">
<h1>%TypedArray%.prototype.sort ( _comparefn_ )</h1>
<p>The following steps are performed:</p>
<emu-alg>
1. If _comparefn_ is not *undefined* and IsCallable(_comparefn_) is *false*, throw a *TypeError* exception.
1. Let _obj_ be the *this* value.
1. Perform ? ValidateTypedArray(_obj_).
1. Let _len_ be _obj_.[[ArrayLength]].
1. NOTE: The following closure performs a numeric comparison rather than the string comparison used in <emu-xref href="#sec-array.prototype.sort"></emu-xref>.
1. Let _SortCompare_ be a new Abstract Closure with parameters (_x_, _y_) that captures _comparefn_ and performs the following steps when called:
1. <del>Assert: _x_ is a Number and _y_ is a Number, or _x_ is a BigInt and _y_ is a BigInt.</del>
1. <del>If _comparefn_ is not *undefined*, then</del>
1. <del>Let _v_ be ? ToNumber(? Call(_comparefn_, *undefined*, « _x_, _y_ »)).</del>
1. <del>If _v_ is *NaN*, return *+0*<sub>𝔽</sub>.</del>
1. <del>Return _v_.</del>
1. <del>If _x_ and _y_ are both *NaN*, return *+0*<sub>𝔽</sub>.</del>
1. <del>If _x_ is *NaN*, return *1*<sub>𝔽</sub>.</del>
1. <del>If _y_ is *NaN*, return *-1*<sub>𝔽</sub>.</del>
1. <del>If _x_ < _y_, return *-1*<sub>𝔽</sub>.</del>
1. <del>If _x_ > _y_, return *1*<sub>𝔽</sub>.</del>
1. <del>If _x_ is *-0*<sub>𝔽</sub> and _y_ is *+0*<sub>𝔽</sub>, return *-1*<sub>𝔽</sub>.</del>
1. <del>If _x_ is *+0*<sub>𝔽</sub> and _y_ is *-0*<sub>𝔽</sub>, return *1*<sub>𝔽</sub>.</del>
1. <del>Return *+0*<sub>𝔽</sub>.</del>
1. <ins>Return ? CompareTypedArrayElements(_x_, _y_, _comparefn_).</ins>
1. <del>Return ? SortIndexedProperties(_obj_, _len_, _SortCompare_).</del>
1. <ins>Let _sortedList_ be ? SortIndexedProperties(_obj_, _len_, _SortCompare_, *false*).</ins>
1. <ins>Let _j_ be 0.</ins>
1. <ins>Repeat, while _j_ < _len_,</ins>
1. <ins>Perform ! Set(_obj_, ! ToString(𝔽(_j_)), _sortedList_[_j_], *true*).</ins>
1. <ins>Set _j_ to _j_ + 1.</ins>
1. <ins>Return _obj_.</ins>
</emu-alg>
</emu-clause>
<emu-clause id="sec-comparetypedarrayelements" type="abstract operation">
<h1>
CompareTypedArrayElements(
_x_: unknown,
_y_: unknown,
_comparefn_: a function object or *undefined*,
): either a normal completion containing a Number or an abrupt completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. Assert: _x_ is a Number and _y_ is a Number, or _x_ is a BigInt and _y_ is a BigInt.
1. If _comparefn_ is not *undefined*, then
1. Let _v_ be ? ToNumber(? Call(_comparefn_, *undefined*, « _x_, _y_ »)).
1. If _v_ is *NaN*, return *+0*<sub>𝔽</sub>.
1. Return _v_.
1. If _x_ and _y_ are both *NaN*, return *+0*<sub>𝔽</sub>.
1. If _x_ is *NaN*, return *1*<sub>𝔽</sub>.
1. If _y_ is *NaN*, return *-1*<sub>𝔽</sub>.
1. If _x_ < _y_, return *-1*<sub>𝔽</sub>.
1. If _x_ > _y_, return *1*<sub>𝔽</sub>.
1. If _x_ is *-0*<sub>𝔽</sub> and _y_ is *+0*<sub>𝔽</sub>, return *-1*<sub>𝔽</sub>.
1. If _x_ is *+0*<sub>𝔽</sub> and _y_ is *-0*<sub>𝔽</sub>, return *1*<sub>𝔽</sub>.
1. Return *+0*<sub>𝔽</sub>.
</emu-alg>
<emu-note>
This performs a numeric comparison rather than the string comparison used in <emu-xref href="#sec-comparearrayelements"></emu-xref>.
</emu-note>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.toReversed">
<h1>%TypedArray%.prototype.toReversed ( )</h1>
<p>When the *toReversed* method is called, the following steps are taken:</p>
<emu-alg>
1. Let _O_ be the *this* value.
1. Perform ? ValidateTypedArray(_O_).
1. Let _length_ be _O_.[[ArrayLength]].
1. Let _A_ be ? TypedArrayCreateSameType(_O_, « 𝔽(_length_) »).
1. Let _k_ be 0.
1. Repeat, while _k_ < _length_,
1. Let _from_ be ! ToString(𝔽(_length_ - _k_ - 1)).
1. Let _Pk_ be ! ToString(𝔽(_k_)).
1. Let _fromValue_ be ! Get(_O_, _from_).
1. Perform ! Set(_A_, _Pk_, _fromValue_, *true*).
1. Set _k_ to _k_ + 1.
1. Return _A_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.toSorted">
<h1>%TypedArray%.prototype.toSorted ( _comparefn_ )</h1>
<p>When the *toSorted* method is called, the following steps are taken:</p>
<emu-alg>
1. If _comparefn_ is not *undefined* and IsCallable(_comparefn_) is *false*, throw a *TypeError* exception.
1. Let _O_ be the *this* value.
1. Perform ? ValidateTypedArray(_O_).
1. Let _len_ be _O_.[[ArrayLength]].
1. Let _A_ be ? TypedArrayCreateSameType(_O_, « 𝔽(_len_) »).
1. NOTE: The following closure performs a numeric comparison rather than the string comparison used in <emu-xref href="#sec-array.prototype.toSorted"></emu-xref>.
1. Let _SortCompare_ be a new Abstract Closure with parameters (_x_, _y_) that captures _comparefn_ and performs the following steps when called:
1. Return ? CompareTypedArrayElements(_x_, _y_, _comparefn_).
1. Let _sortedList_ be ? SortIndexedProperties(_obj_, _len_, _SortCompare_, *false*).
1. Let _j_ be 0.
1. Repeat, while _j_ < _len_,
1. Perform ! Set(_A_, ! ToString(𝔽(_j_)), _sortedList_[_j_], *true*).
1. Set _j_ to _j_ + 1.
1. Return _A_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.with">
<h1>%TypedArray%.prototype.with ( _index_, _value_ )</h1>
<p>When the *with* method is called, the following steps are taken:</p>
<emu-alg>
1. Let _O_ be the *this* value.
1. Perform ? ValidateTypedArray(_O_).
1. Let _len_ be _O_.[[ArrayLength]].
1. Let _relativeIndex_ be ? ToIntegerOrInfinity(_index_).
1. If _relativeIndex_ ≥ 0, let _actualIndex_ be _relativeIndex_.
1. Else, let _actualIndex_ be _len_ + _relativeIndex_.
1. If _O_.[[ContentType]] is ~BigInt~, set _value_ to ? ToBigInt(_value_).
1. Else, set _value_ to ? ToNumber(_value_).
1. If ! IsValidIntegerIndex(_O_, 𝔽(_actualIndex_)) is *false*, throw a *RangeError* exception.
1. Let _A_ be ? TypedArrayCreateSameType(_O_, « 𝔽(_len_) »).
1. Let _k_ be 0.
1. Repeat, while _k_ < _len_,
1. Let _Pk_ be ! ToString(𝔽(_k_)).
1. If _k_ is _actualIndex_, let _fromValue_ be _value_.
1. Else, let _fromValue_ be ! Get(_O_, _Pk_).
1. Perform ! Set(_A_, _Pk_, _fromValue_, *true*).
1. Set _k_ to _k_ + 1.
1. Return _A_.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>