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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 | 7 |
8 // This file relies on the fact that the following declaration has been made | 8 // This file relies on the fact that the following declaration has been made |
9 // in runtime.js: | 9 // in runtime.js: |
10 // var $Set = global.Set; | 10 // var $Set = global.Set; |
11 // var $Map = global.Map; | 11 // var $Map = global.Map; |
12 | 12 |
13 | 13 |
14 function SetIteratorConstructor(set, kind) { | 14 function SetIteratorConstructor(set, kind) { |
15 %SetIteratorInitialize(this, set, kind); | 15 %SetIteratorInitialize(this, set, kind); |
16 } | 16 } |
17 | 17 |
18 | 18 |
19 function SetIteratorNextJS() { | 19 function SetIteratorNextJS() { |
20 if (!IS_SET_ITERATOR(this)) { | 20 if (!IS_SET_ITERATOR(this)) { |
21 throw MakeTypeError('incompatible_method_receiver', | 21 throw MakeTypeError('incompatible_method_receiver', |
22 ['Set Iterator.prototype.next', this]); | 22 ['Set Iterator.prototype.next', this]); |
23 } | 23 } |
24 return %SetIteratorNext(this); | 24 |
| 25 var value_array = [UNDEFINED, UNDEFINED]; |
| 26 var entry = {value: value_array, done: false}; |
| 27 switch (%SetIteratorNext(this, value_array)) { |
| 28 case 0: |
| 29 entry.value = UNDEFINED; |
| 30 entry.done = true; |
| 31 break; |
| 32 case ITERATOR_KIND_VALUES: |
| 33 entry.value = value_array[0]; |
| 34 break; |
| 35 case ITERATOR_KIND_ENTRIES: |
| 36 value_array[1] = value_array[0]; |
| 37 break; |
| 38 } |
| 39 |
| 40 return entry; |
25 } | 41 } |
26 | 42 |
27 | 43 |
28 function SetIteratorSymbolIterator() { | 44 function SetIteratorSymbolIterator() { |
29 return this; | 45 return this; |
30 } | 46 } |
31 | 47 |
32 | 48 |
33 function SetEntries() { | 49 function SetEntries() { |
34 if (!IS_SET(this)) { | 50 if (!IS_SET(this)) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 function MapIteratorSymbolIterator() { | 106 function MapIteratorSymbolIterator() { |
91 return this; | 107 return this; |
92 } | 108 } |
93 | 109 |
94 | 110 |
95 function MapIteratorNextJS() { | 111 function MapIteratorNextJS() { |
96 if (!IS_MAP_ITERATOR(this)) { | 112 if (!IS_MAP_ITERATOR(this)) { |
97 throw MakeTypeError('incompatible_method_receiver', | 113 throw MakeTypeError('incompatible_method_receiver', |
98 ['Map Iterator.prototype.next', this]); | 114 ['Map Iterator.prototype.next', this]); |
99 } | 115 } |
100 return %MapIteratorNext(this); | 116 |
| 117 var value_array = [UNDEFINED, UNDEFINED]; |
| 118 var entry = {value: value_array, done: false}; |
| 119 switch (%MapIteratorNext(this, value_array)) { |
| 120 case 0: |
| 121 entry.value = UNDEFINED; |
| 122 entry.done = true; |
| 123 break; |
| 124 case ITERATOR_KIND_KEYS: |
| 125 entry.value = value_array[0]; |
| 126 break; |
| 127 case ITERATOR_KIND_VALUES: |
| 128 entry.value = value_array[1]; |
| 129 break; |
| 130 // ITERATOR_KIND_ENTRIES does not need any processing. |
| 131 } |
| 132 |
| 133 return entry; |
101 } | 134 } |
102 | 135 |
103 | 136 |
104 function MapEntries() { | 137 function MapEntries() { |
105 if (!IS_MAP(this)) { | 138 if (!IS_MAP(this)) { |
106 throw MakeTypeError('incompatible_method_receiver', | 139 throw MakeTypeError('incompatible_method_receiver', |
107 ['Map.prototype.entries', this]); | 140 ['Map.prototype.entries', this]); |
108 } | 141 } |
109 return new MapIterator(this, ITERATOR_KIND_ENTRIES); | 142 return new MapIterator(this, ITERATOR_KIND_ENTRIES); |
110 } | 143 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 'entries', MapEntries, | 186 'entries', MapEntries, |
154 'keys', MapKeys, | 187 'keys', MapKeys, |
155 'values', MapValues | 188 'values', MapValues |
156 )); | 189 )); |
157 | 190 |
158 %SetProperty($Map.prototype, symbolIterator, MapEntries, | 191 %SetProperty($Map.prototype, symbolIterator, MapEntries, |
159 DONT_ENUM); | 192 DONT_ENUM); |
160 } | 193 } |
161 | 194 |
162 ExtendMapPrototype(); | 195 ExtendMapPrototype(); |
OLD | NEW |