OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 var $mapEntries; |
| 6 var $mapIteratorNext; |
| 7 var $setIteratorNext; |
| 8 var $setValues; |
| 9 |
| 10 (function() { |
| 11 |
5 "use strict"; | 12 "use strict"; |
6 | 13 |
| 14 %CheckIsBootstrapping(); |
7 | 15 |
8 // This file relies on the fact that the following declaration has been made | 16 var GlobalMap = global.Map; |
9 // in runtime.js: | 17 var GlobalObject = global.Object; |
10 // var $Set = global.Set; | 18 var GlobalSet = global.Set; |
11 // var $Map = global.Map; | |
12 | 19 |
| 20 // ------------------------------------------------------------------- |
13 | 21 |
14 function SetIteratorConstructor(set, kind) { | 22 function SetIteratorConstructor(set, kind) { |
15 %SetIteratorInitialize(this, set, kind); | 23 %SetIteratorInitialize(this, set, kind); |
16 } | 24 } |
17 | 25 |
18 | 26 |
19 function SetIteratorNextJS() { | 27 function SetIteratorNextJS() { |
20 if (!IS_SET_ITERATOR(this)) { | 28 if (!IS_SET_ITERATOR(this)) { |
21 throw MakeTypeError('incompatible_method_receiver', | 29 throw MakeTypeError('incompatible_method_receiver', |
22 ['Set Iterator.prototype.next', this]); | 30 ['Set Iterator.prototype.next', this]); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 64 |
57 | 65 |
58 function SetValues() { | 66 function SetValues() { |
59 if (!IS_SET(this)) { | 67 if (!IS_SET(this)) { |
60 throw MakeTypeError('incompatible_method_receiver', | 68 throw MakeTypeError('incompatible_method_receiver', |
61 ['Set.prototype.values', this]); | 69 ['Set.prototype.values', this]); |
62 } | 70 } |
63 return new SetIterator(this, ITERATOR_KIND_VALUES); | 71 return new SetIterator(this, ITERATOR_KIND_VALUES); |
64 } | 72 } |
65 | 73 |
| 74 // ------------------------------------------------------------------- |
66 | 75 |
67 function SetUpSetIterator() { | 76 %SetCode(SetIterator, SetIteratorConstructor); |
68 %CheckIsBootstrapping(); | 77 %FunctionSetPrototype(SetIterator, new GlobalObject()); |
| 78 %FunctionSetInstanceClassName(SetIterator, 'Set Iterator'); |
| 79 InstallFunctions(SetIterator.prototype, DONT_ENUM, [ |
| 80 'next', SetIteratorNextJS |
| 81 ]); |
69 | 82 |
70 %SetCode(SetIterator, SetIteratorConstructor); | 83 %FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]'); |
71 %FunctionSetPrototype(SetIterator, new $Object()); | 84 %AddNamedProperty(SetIterator.prototype, symbolIterator, |
72 %FunctionSetInstanceClassName(SetIterator, 'Set Iterator'); | 85 SetIteratorSymbolIterator, DONT_ENUM); |
73 InstallFunctions(SetIterator.prototype, DONT_ENUM, [ | 86 %AddNamedProperty(SetIterator.prototype, symbolToStringTag, |
74 'next', SetIteratorNextJS | 87 "Set Iterator", READ_ONLY | DONT_ENUM); |
75 ]); | |
76 | 88 |
77 %FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]'); | 89 InstallFunctions(GlobalSet.prototype, DONT_ENUM, [ |
78 %AddNamedProperty(SetIterator.prototype, symbolIterator, | 90 'entries', SetEntries, |
79 SetIteratorSymbolIterator, DONT_ENUM); | 91 'keys', SetValues, |
80 %AddNamedProperty(SetIterator.prototype, symbolToStringTag, | 92 'values', SetValues |
81 "Set Iterator", READ_ONLY | DONT_ENUM); | 93 ]); |
82 } | |
83 | 94 |
84 SetUpSetIterator(); | 95 %AddNamedProperty(GlobalSet.prototype, symbolIterator, SetValues, DONT_ENUM); |
85 | 96 |
| 97 $setIteratorNext = SetIteratorNextJS; |
| 98 $setValues = SetValues; |
86 | 99 |
87 function ExtendSetPrototype() { | 100 // ------------------------------------------------------------------- |
88 %CheckIsBootstrapping(); | |
89 | |
90 InstallFunctions($Set.prototype, DONT_ENUM, [ | |
91 'entries', SetEntries, | |
92 'keys', SetValues, | |
93 'values', SetValues | |
94 ]); | |
95 | |
96 %AddNamedProperty($Set.prototype, symbolIterator, SetValues, DONT_ENUM); | |
97 } | |
98 | |
99 ExtendSetPrototype(); | |
100 | |
101 | |
102 | 101 |
103 function MapIteratorConstructor(map, kind) { | 102 function MapIteratorConstructor(map, kind) { |
104 %MapIteratorInitialize(this, map, kind); | 103 %MapIteratorInitialize(this, map, kind); |
105 } | 104 } |
106 | 105 |
107 | 106 |
108 function MapIteratorSymbolIterator() { | 107 function MapIteratorSymbolIterator() { |
109 return this; | 108 return this; |
110 } | 109 } |
111 | 110 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 154 |
156 | 155 |
157 function MapValues() { | 156 function MapValues() { |
158 if (!IS_MAP(this)) { | 157 if (!IS_MAP(this)) { |
159 throw MakeTypeError('incompatible_method_receiver', | 158 throw MakeTypeError('incompatible_method_receiver', |
160 ['Map.prototype.values', this]); | 159 ['Map.prototype.values', this]); |
161 } | 160 } |
162 return new MapIterator(this, ITERATOR_KIND_VALUES); | 161 return new MapIterator(this, ITERATOR_KIND_VALUES); |
163 } | 162 } |
164 | 163 |
| 164 // ------------------------------------------------------------------- |
165 | 165 |
166 function SetUpMapIterator() { | 166 %SetCode(MapIterator, MapIteratorConstructor); |
167 %CheckIsBootstrapping(); | 167 %FunctionSetPrototype(MapIterator, new GlobalObject()); |
| 168 %FunctionSetInstanceClassName(MapIterator, 'Map Iterator'); |
| 169 InstallFunctions(MapIterator.prototype, DONT_ENUM, [ |
| 170 'next', MapIteratorNextJS |
| 171 ]); |
168 | 172 |
169 %SetCode(MapIterator, MapIteratorConstructor); | 173 %FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]'); |
170 %FunctionSetPrototype(MapIterator, new $Object()); | 174 %AddNamedProperty(MapIterator.prototype, symbolIterator, |
171 %FunctionSetInstanceClassName(MapIterator, 'Map Iterator'); | 175 MapIteratorSymbolIterator, DONT_ENUM); |
172 InstallFunctions(MapIterator.prototype, DONT_ENUM, [ | 176 %AddNamedProperty(MapIterator.prototype, symbolToStringTag, |
173 'next', MapIteratorNextJS | 177 "Map Iterator", READ_ONLY | DONT_ENUM); |
174 ]); | |
175 | |
176 %FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]'); | |
177 %AddNamedProperty(MapIterator.prototype, symbolIterator, | |
178 MapIteratorSymbolIterator, DONT_ENUM); | |
179 %AddNamedProperty(MapIterator.prototype, symbolToStringTag, | |
180 "Map Iterator", READ_ONLY | DONT_ENUM); | |
181 } | |
182 | |
183 SetUpMapIterator(); | |
184 | 178 |
185 | 179 |
186 function ExtendMapPrototype() { | 180 InstallFunctions(GlobalMap.prototype, DONT_ENUM, [ |
187 %CheckIsBootstrapping(); | 181 'entries', MapEntries, |
| 182 'keys', MapKeys, |
| 183 'values', MapValues |
| 184 ]); |
188 | 185 |
189 InstallFunctions($Map.prototype, DONT_ENUM, [ | 186 %AddNamedProperty(GlobalMap.prototype, symbolIterator, MapEntries, DONT_ENUM); |
190 'entries', MapEntries, | |
191 'keys', MapKeys, | |
192 'values', MapValues | |
193 ]); | |
194 | 187 |
195 %AddNamedProperty($Map.prototype, symbolIterator, MapEntries, DONT_ENUM); | 188 $mapEntries = MapEntries; |
196 } | 189 $mapIteratorNext = MapIteratorNextJS; |
197 | 190 |
198 ExtendMapPrototype(); | 191 })(); |
OLD | NEW |