generated from tc39/template-for-proposals
-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec.emu
138 lines (133 loc) · 7.37 KB
/
spec.emu
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
<!doctype html>
<meta charset="utf8">
<link rel="stylesheet" href="./spec.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<script src="./spec.js"></script>
<pre class="metadata">
title: Array.zip
stage: 1
contributors: Jordan Harband
</pre>
<emu-clause id="sec-array-objects" number="23">
<h1>Array Objects</h1>
<emu-clause id="sec-array-constructor" number="1">
<h1>The Array Constructor</h1>
<emu-clause id="sec-properties-of-the-array-constructor" number="2">
<h1>Properties of the Array Constructor</h1>
<emu-clause id="sec-array.zip" number="5">
<h1>Array.zip ( _iterables_ [ , _options_ ] )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. If _iterables_ is not an Object, throw a *TypeError* exception.
1. Set _options_ to ? GetOptionsObject(_options_).
1. Let _mode_ be ? Get(_options_, *"mode"*).
1. If _mode_ is *undefined*, set _mode_ to *"shortest"*.
1. If _mode_ is not one of *"shortest"*, *"longest"*, or *"strict"*, throw a *TypeError* exception.
1. Let _paddingOption_ be *undefined*.
1. If _mode_ is *"longest"*, then
1. Set _paddingOption_ to ? Get(_options_, *"padding"*).
1. If _paddingOption_ is not *undefined* and _paddingOption_ is not an Object, throw a *TypeError* exception.
1. Let _iters_ be a new empty List.
1. Let _padding_ be a new empty List.
1. Let _inputIter_ be ? GetIterator(_iterables_, ~sync~).
1. Let _next_ be ~not-started~.
1. Repeat, while _next_ is not ~done~,
1. Set _next_ to Completion(IteratorStepValue(_inputIter_)).
1. IfAbruptCloseIterators(_next_, _iters_).
1. If _next_ is not ~done~, then
1. Let _iter_ be Completion(GetIteratorFlattenable(_next_, ~reject-strings~)).
1. IfAbruptCloseIterators(_iter_, the list-concatenation of « _inputIter_ » and _iters_).
1. Append _iter_ to _iters_.
1. Let _iterCount_ be the number of elements in _iters_.
1. If _mode_ is *"longest"*, then
1. If _paddingOption_ is *undefined*, then
1. Perform the following steps _iterCount_ times:
1. Append *undefined* to _padding_.
1. Else,
1. Let _paddingIter_ be Completion(GetIterator(_paddingOption_, ~sync~)).
1. IfAbruptCloseIterators(_paddingIter_, _iters_).
1. If _paddingIter_ is a String, throw a *TypeError* exception.
1. Let _usingIterator_ be *true*.
1. Perform the following steps _iterCount_ times:
1. If _usingIterator_ is *true*, then
1. Set _next_ to Completion(IteratorStepValue(_paddingIter_)).
1. IfAbruptCloseIterators(_next_, _iters_).
1. If _next_ is ~done~, then
1. Set _usingIterator_ to *false*.
1. Else,
1. Append _next_ to _padding_.
1. If _usingIterator_ is *false*, append *undefined* to _padding_.
1. If _usingIterator_ is *true*, then
1. Let _completion_ be Completion(IteratorClose(_paddingIter_, ReturnCompletion(*undefined*))).
1. IfAbruptCloseIterators(_completion_, _iters_).
1. Let _finishResults_ be a new Abstract Closure with parameters (_results_) that captures nothing and performs the following steps when called:
1. Return CreateArrayFromList(_results_).
1. Let _gen_ be IteratorZip(_iters_, _mode_, _padding_, _finishResults_).
1. Let _items_ be a new empty List.
1. Repeat,
1. Let _value_ be ? IteratorStepValue(_gen_).
1. If _value_ is ~done~, return CreateArrayFromList(_items_).
1. Append _value_ to _items_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-array.zipkeyed">
<h1>Array.zipKeyed ( _iterables_ [ , _options_ ] )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. If _iterables_ is not an Object, throw a *TypeError* exception.
1. Set _options_ to ? GetOptionsObject(_options_).
1. Let _mode_ be ? Get(_options_, *"mode"*).
1. If _mode_ is *undefined*, set _mode_ to *"shortest"*.
1. If _mode_ is not one of *"shortest"*, *"longest"*, or *"strict"*, throw a *TypeError* exception.
1. Let _paddingOption_ be *undefined*.
1. If _mode_ is *"longest"*, then
1. Set _paddingOption_ to ? Get(_options_, *"padding"*).
1. If _paddingOption_ is not *undefined* and _paddingOption_ is not an Object, throw a *TypeError* exception.
1. Let _iters_ be a new empty List.
1. Let _padding_ be a new empty List.
1. Let _allKeys_ be ? _iterables_.[[OwnPropertyKeys]]().
1. Let _keys_ be a new empty List.
1. For each element _key_ of _allKeys_, do
1. Let _desc_ be ? _iterables_.[[GetOwnProperty]](_key_).
1. If _desc_ is not *undefined* and _desc_.[[Enumerable]] is *true*, then
1. Let _value_ be *undefined*.
1. If IsDataDescriptor(_desc_) is *true*, then
1. Set _value_ to _desc_.[[Value]].
1. Else,
1. Assert: IsAccessorDescriptor(_desc_) is *true*.
1. Let _getter_ be _desc_.[[Get]].
1. If _getter_ is not *undefined*, then
1. Let _getterResult_ be Completion(Call(_getter_, _iterables_)).
1. IfAbruptCloseIterators(_getterResult_, _iters_).
1. Set _value_ to _getterResult_.
1. If _value_ is not *undefined*, then
1. Append _key_ to _keys_.
1. Let _iter_ be Completion(GetIteratorFlattenable(_value_, ~reject-strings~)).
1. IfAbruptCloseIterators(_iter_, _iters_).
1. Append _iter_ to _iters_.
1. Let _iterCount_ be the number of elements in _iters_.
1. If _mode_ is *"longest"*, then
1. If _paddingOption_ is *undefined*, then
1. Perform the following steps _iterCount_ times:
1. Append *undefined* to _padding_.
1. Else,
1. For each element _key_ of _keys_, do
1. Let _value_ be Completion(Get(_paddingOption_, _key_)).
1. IfAbruptCloseIterators(_value_, _iters_).
1. Append _value_ to _padding_.
1. Let _finishResults_ be a new Abstract Closure with parameters (_results_) that captures _keys_ and _iterCount_ and performs the following steps when called:
1. Let _obj_ be OrdinaryObjectCreate(*null*).
1. For each integer _i_ such that 0 ≤ _i_ < _iterCount_, in ascending order, do
1. Perform ! CreateDataPropertyOrThrow(_obj_, _keys_[_i_], _results_[_i_]).
1. Return _obj_.
1. Let _gen_ be IteratorZip(_iters_, _mode_, _padding_, _finishResults_).
1. Let _items_ be a new empty List.
1. Repeat,
1. Let _value_ be ? IteratorStepValue(_gen_).
1. If _value_ is ~done~, return CreateArrayFromList(_items_).
1. Append _value_ to _items_.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>