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
3 // found in the LICENSE file.
8 // This file relies on the fact that the following declaration has been made
10 // var $Set = global.Set;
11 // var $Map = global.Map;
14 function SetIteratorConstructor(set, kind) {
15 %SetIteratorInitialize(this, set, kind);
19 function SetIteratorNextJS() {
20 if (!IS_SET_ITERATOR(this)) {
21 throw MakeTypeError('incompatible_method_receiver',
22 ['Set Iterator.prototype.next', this]);
25 var value_array = [UNDEFINED, UNDEFINED];
26 var entry = {value: value_array, done: false};
27 switch (%SetIteratorNext(this, value_array)) {
29 entry.value = UNDEFINED;
32 case ITERATOR_KIND_VALUES:
33 entry.value = value_array[0];
35 case ITERATOR_KIND_ENTRIES:
36 value_array[1] = value_array[0];
44 function SetIteratorSymbolIterator() {
49 function SetEntries() {
51 throw MakeTypeError('incompatible_method_receiver',
52 ['Set.prototype.entries', this]);
54 return new SetIterator(this, ITERATOR_KIND_ENTRIES);
58 function SetValues() {
60 throw MakeTypeError('incompatible_method_receiver',
61 ['Set.prototype.values', this]);
63 return new SetIterator(this, ITERATOR_KIND_VALUES);
67 function SetUpSetIterator() {
68 %CheckIsBootstrapping();
70 %SetCode(SetIterator, SetIteratorConstructor);
71 %FunctionSetPrototype(SetIterator, new $Object());
72 %FunctionSetInstanceClassName(SetIterator, 'Set Iterator');
73 InstallFunctions(SetIterator.prototype, DONT_ENUM, $Array(
74 'next', SetIteratorNextJS
77 %FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]');
78 %AddNamedProperty(SetIterator.prototype, symbolIterator,
79 SetIteratorSymbolIterator, DONT_ENUM);
85 function ExtendSetPrototype() {
86 %CheckIsBootstrapping();
88 InstallFunctions($Set.prototype, DONT_ENUM, $Array(
89 'entries', SetEntries,
94 %AddNamedProperty($Set.prototype, symbolIterator, SetValues, DONT_ENUM);
101 function MapIteratorConstructor(map, kind) {
102 %MapIteratorInitialize(this, map, kind);
106 function MapIteratorSymbolIterator() {
111 function MapIteratorNextJS() {
112 if (!IS_MAP_ITERATOR(this)) {
113 throw MakeTypeError('incompatible_method_receiver',
114 ['Map Iterator.prototype.next', this]);
117 var value_array = [UNDEFINED, UNDEFINED];
118 var entry = {value: value_array, done: false};
119 switch (%MapIteratorNext(this, value_array)) {
121 entry.value = UNDEFINED;
124 case ITERATOR_KIND_KEYS:
125 entry.value = value_array[0];
127 case ITERATOR_KIND_VALUES:
128 entry.value = value_array[1];
130 // ITERATOR_KIND_ENTRIES does not need any processing.
137 function MapEntries() {
139 throw MakeTypeError('incompatible_method_receiver',
140 ['Map.prototype.entries', this]);
142 return new MapIterator(this, ITERATOR_KIND_ENTRIES);
148 throw MakeTypeError('incompatible_method_receiver',
149 ['Map.prototype.keys', this]);
151 return new MapIterator(this, ITERATOR_KIND_KEYS);
155 function MapValues() {
157 throw MakeTypeError('incompatible_method_receiver',
158 ['Map.prototype.values', this]);
160 return new MapIterator(this, ITERATOR_KIND_VALUES);
164 function SetUpMapIterator() {
165 %CheckIsBootstrapping();
167 %SetCode(MapIterator, MapIteratorConstructor);
168 %FunctionSetPrototype(MapIterator, new $Object());
169 %FunctionSetInstanceClassName(MapIterator, 'Map Iterator');
170 InstallFunctions(MapIterator.prototype, DONT_ENUM, $Array(
171 'next', MapIteratorNextJS
174 %FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]');
175 %AddNamedProperty(MapIterator.prototype, symbolIterator,
176 MapIteratorSymbolIterator, DONT_ENUM);
182 function ExtendMapPrototype() {
183 %CheckIsBootstrapping();
185 InstallFunctions($Map.prototype, DONT_ENUM, $Array(
186 'entries', MapEntries,
191 %AddNamedProperty($Map.prototype, symbolIterator, MapEntries, DONT_ENUM);
194 ExtendMapPrototype();