This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
generated from tc39/template-for-proposals
-
Notifications
You must be signed in to change notification settings - Fork 6
/
alt.emu
137 lines (128 loc) · 5.74 KB
/
alt.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
<!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: Object iteration (alternate spec text)
stage: 2
contributors: Jonathan Keslin
</pre>
<emu-clause id="Object_iterateKeys">
<h1>Object.iterateKeys( O )</h1>
<p>When the *iterateKeys* function is called with argument _O_, the following steps are taken:</p>
<emu-alg>
1. Let _obj_ be ? ToObject(_O_).
1. Return CreateObjectIterator(_obj_, ~key~).
</emu-alg>
</emu-clause>
<emu-clause id="Object_iterateValues">
<h1>Object.iterateValues( O )</h1>
<p>When the *iterateValues* function is called with argument _O_, the following steps are taken:</p>
<emu-alg>
1. Let _obj_ be ? ToObject(_O_).
1. Return CreateObjectIterator(_obj_, ~value~).
</emu-alg>
</emu-clause>
<emu-clause id="Object_iterateEntries">
<h1>Object.iterateEntries( O )</h1>
<p>When the *iterateEntries* function is called with argument _O_, the following steps are taken:</p>
<emu-alg>
1. Let _obj_ be ? ToObject(_O_).
1. Return CreateObjectIterator(_obj_, ~key+value~).
</emu-alg>
</emu-clause>
<emu-clause id="sec-object-iterator-objects">
<h1>Object Iterator Objects</h1>
<p>An Object Iterator is an object, that represents a specific iteration over some specific instance object. There is not a named constructor for Object Iterator objects. Instead, Object Iterator objects are created by calling certain methods of the Object global.</p>
<emu-clause id="sec-createobjectiterator" aoid="CreateObjectIterator">
<h1>CreateObjectIterator ( _obj_, _kind_ )</h1>
<p>Several methods of the Object global return Iterator objects. The abstract operation CreateObjectIterator with arguments _obj_ and _kind_ is used to create such iterator objects. It performs the following steps:</p>
<emu-alg>
1. Let _iterator_ be ObjectCreate(%ObjectIteratorPrototype%, « [[IteratedObject]], [[ObjectNextIndex]], [[ObjectIterationKind]] »).
1. Set _iterator_.[[IteratedObject]] to _obj_.
1. Set _iterator_.[[ObjectNextIndex]] to 0.
1. Set _iterator_.[[ObjectIterationKind]] to _kind_.
1. Return _iterator_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-%objectiteratorprototype%-object">
<h1>The %ObjectIteratorPrototype% Object</h1>
<p>The <dfn>%ObjectIteratorPrototype%</dfn> object:</p>
<ul>
<li>has properties that are inherited by all Object Iterator Objects.</li>
<li>is an ordinary object.</li>
<li>has a [[Prototype]] internal slot whose value is %IteratorPrototype%.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-%objectiteratorprototype%.next">
<h1>%ObjectIteratorPrototype%.next ( )</h1>
<emu-alg>
1. Let _O_ be the *this* value.
1. If Type(_O_) is not Object, throw a *TypeError* exception.
1. If _O_ does not have all of the internal slots of a Object Iterator Instance (<emu-xref href="#sec-properties-of-object-iterator-instances"></emu-xref>), throw a *TypeError* exception.
1. Let _obj_ be _O_.[[IteratedObject]].
1. Let _index_ be _O_.[[ObjectNextIndex]].
1. Let _itemKind_ be _O_.[[ObjectIterationKind]].
1. If _obj_ is *undefined*, return CreateIterResultObject(*undefined*, *true*).
1. Let _items_ be ? EnumerableOwnProperties(_obj_, _kind_).
1. Let _numItems_ be the number of elements of _items_.
1. NOTE: _numItems_ must be redetermined each time this method is evaluated.
1. Repeat, while _index_ is less than _numItems_,
1. Let _i_ be the Record that is the value of _items_[_index_].
1. Set _index_ to _index_ + 1.
1. Set _O_.[[ObjectNextIndex]] to _index_.
1. Return CreateIterResultObject(_i_, *false*).
1. Set _O_.[[IteratedObject]] to *undefined*.
1. Return CreateIterResultObject(*undefined*, *true*).
</emu-alg>
</emu-clause>
<emu-clause id="sec-%objectiteratorprototype%-@@tostringtag">
<h1>%ObjectIteratorPrototype% [ @@toStringTag ]</h1>
<p>The initial value of the @@toStringTag property is the String value *"Object Iterator"*.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-object-iterator-instances">
<h1>Properties of Object Iterator Instances</h1>
<p>Object Iterator instances are ordinary objects that inherit properties from the %ObjectIteratorPrototype% intrinsic object. Object Iterator instances are initially created with the internal slots described in <emu-xref href="#table-object-iterator-slots"></emu-xref>.</p>
<emu-table id="table-object-iterator-slots" caption="Internal Slots of Object Iterator Instances">
<table>
<tbody>
<tr>
<th>
Internal Slot
</th>
<th>
Description
</th>
</tr>
<tr>
<td>
[[IteratedObject]]
</td>
<td>
The object that is being iterated.
</td>
</tr>
<tr>
<td>
[[ObjectNextIndex]]
</td>
<td>
The integer index of the next enumerable element to be examined by this iterator.
</td>
</tr>
<tr>
<td>
[[ObjectIterationKind]]
</td>
<td>
A String value that identifies what is returned for each element of the iteration. The possible values are: ~key~, ~value~, ~key+value~.
</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
</emu-clause>