OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 return %SetGetSize(this); | 107 return %SetGetSize(this); |
108 } | 108 } |
109 | 109 |
110 | 110 |
111 function SetClear() { | 111 function SetClear() { |
112 if (!IS_SET(this)) { | 112 if (!IS_SET(this)) { |
113 throw MakeTypeError('incompatible_method_receiver', | 113 throw MakeTypeError('incompatible_method_receiver', |
114 ['Set.prototype.clear', this]); | 114 ['Set.prototype.clear', this]); |
115 } | 115 } |
116 // Replace the internal table with a new empty table. | 116 %SetClear(this); |
117 %SetInitialize(this); | |
118 } | 117 } |
119 | 118 |
120 | 119 |
| 120 // Matches OrderedHashTableIterator::Kind enum values. |
| 121 var SET_ITERATOR_KIND_VALUES = 2; |
| 122 |
| 123 |
| 124 function SetForEach(f, receiver) { |
| 125 if (!IS_SET(this)) { |
| 126 throw MakeTypeError('incompatible_method_receiver', |
| 127 ['Set.prototype.forEach', this]); |
| 128 } |
| 129 |
| 130 if (typeof f !== 'function') { |
| 131 throw MakeTypeError('called_non_callable', [f]); |
| 132 } |
| 133 |
| 134 var iterator = %SetCreateIterator(this, SET_ITERATOR_KIND_VALUES); |
| 135 var entry; |
| 136 try { |
| 137 while (!(entry = %SetIteratorNext(iterator)).done) { |
| 138 %_CallFunction(receiver, entry.value, entry.value, this, f); |
| 139 } |
| 140 } finally { |
| 141 %SetIteratorClose(iterator); |
| 142 } |
| 143 } |
| 144 |
| 145 |
121 // ------------------------------------------------------------------- | 146 // ------------------------------------------------------------------- |
122 | 147 |
123 function SetUpSet() { | 148 function SetUpSet() { |
124 %CheckIsBootstrapping(); | 149 %CheckIsBootstrapping(); |
125 | 150 |
126 %SetCode($Set, SetConstructor); | 151 %SetCode($Set, SetConstructor); |
127 %FunctionSetPrototype($Set, new $Object()); | 152 %FunctionSetPrototype($Set, new $Object()); |
128 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); | 153 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); |
129 | 154 |
| 155 %FunctionSetLength(SetForEach, 1); |
| 156 |
130 // Set up the non-enumerable functions on the Set prototype object. | 157 // Set up the non-enumerable functions on the Set prototype object. |
131 InstallGetter($Set.prototype, "size", SetGetSize); | 158 InstallGetter($Set.prototype, "size", SetGetSize); |
132 InstallFunctions($Set.prototype, DONT_ENUM, $Array( | 159 InstallFunctions($Set.prototype, DONT_ENUM, $Array( |
133 "add", SetAdd, | 160 "add", SetAdd, |
134 "has", SetHas, | 161 "has", SetHas, |
135 "delete", SetDelete, | 162 "delete", SetDelete, |
136 "clear", SetClear | 163 "clear", SetClear, |
| 164 "forEach", SetForEach |
137 )); | 165 )); |
138 } | 166 } |
139 | 167 |
140 SetUpSet(); | 168 SetUpSet(); |
141 | 169 |
142 | 170 |
143 // ------------------------------------------------------------------- | 171 // ------------------------------------------------------------------- |
144 // Harmony Map | 172 // Harmony Map |
145 | 173 |
146 function MapConstructor() { | 174 function MapConstructor() { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 223 } |
196 return %MapGetSize(this); | 224 return %MapGetSize(this); |
197 } | 225 } |
198 | 226 |
199 | 227 |
200 function MapClear() { | 228 function MapClear() { |
201 if (!IS_MAP(this)) { | 229 if (!IS_MAP(this)) { |
202 throw MakeTypeError('incompatible_method_receiver', | 230 throw MakeTypeError('incompatible_method_receiver', |
203 ['Map.prototype.clear', this]); | 231 ['Map.prototype.clear', this]); |
204 } | 232 } |
205 // Replace the internal table with a new empty table. | 233 %MapClear(this); |
206 %MapInitialize(this); | |
207 } | 234 } |
208 | 235 |
209 | 236 |
| 237 // Matches OrderedHashTableIterator::Kind enum values. |
| 238 var MAP_ITERATOR_KIND_ENTRIES = 3; |
| 239 |
| 240 |
| 241 function MapForEach(f, receiver) { |
| 242 if (!IS_MAP(this)) { |
| 243 throw MakeTypeError('incompatible_method_receiver', |
| 244 ['Map.prototype.forEach', this]); |
| 245 } |
| 246 |
| 247 if (typeof f !== 'function') { |
| 248 throw MakeTypeError('called_non_callable', [f]); |
| 249 } |
| 250 |
| 251 var iterator = %MapCreateIterator(this, MAP_ITERATOR_KIND_ENTRIES); |
| 252 var entry; |
| 253 try { |
| 254 while (!(entry = %MapIteratorNext(iterator)).done) { |
| 255 %_CallFunction(receiver, entry.value[1], entry.value[0], this, f); |
| 256 } |
| 257 } finally { |
| 258 %MapIteratorClose(iterator); |
| 259 } |
| 260 } |
| 261 |
| 262 |
210 // ------------------------------------------------------------------- | 263 // ------------------------------------------------------------------- |
211 | 264 |
212 function SetUpMap() { | 265 function SetUpMap() { |
213 %CheckIsBootstrapping(); | 266 %CheckIsBootstrapping(); |
214 | 267 |
215 %SetCode($Map, MapConstructor); | 268 %SetCode($Map, MapConstructor); |
216 %FunctionSetPrototype($Map, new $Object()); | 269 %FunctionSetPrototype($Map, new $Object()); |
217 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); | 270 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); |
218 | 271 |
| 272 %FunctionSetLength(MapForEach, 1); |
| 273 |
219 // Set up the non-enumerable functions on the Map prototype object. | 274 // Set up the non-enumerable functions on the Map prototype object. |
220 InstallGetter($Map.prototype, "size", MapGetSize); | 275 InstallGetter($Map.prototype, "size", MapGetSize); |
221 InstallFunctions($Map.prototype, DONT_ENUM, $Array( | 276 InstallFunctions($Map.prototype, DONT_ENUM, $Array( |
222 "get", MapGet, | 277 "get", MapGet, |
223 "set", MapSet, | 278 "set", MapSet, |
224 "has", MapHas, | 279 "has", MapHas, |
225 "delete", MapDelete, | 280 "delete", MapDelete, |
226 "clear", MapClear | 281 "clear", MapClear, |
| 282 "forEach", MapForEach |
227 )); | 283 )); |
228 } | 284 } |
229 | 285 |
230 SetUpMap(); | 286 SetUpMap(); |
OLD | NEW |