OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 // This file relies on the fact that the following declaration has been made | 7 // This file relies on the fact that the following declaration has been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 function SetConstructor(iterable) { | 95 function SetConstructor(iterable) { |
96 if (!%_IsConstructCall()) { | 96 if (!%_IsConstructCall()) { |
97 throw MakeTypeError('constructor_not_function', ['Set']); | 97 throw MakeTypeError('constructor_not_function', ['Set']); |
98 } | 98 } |
99 | 99 |
100 %_SetInitialize(this); | 100 %_SetInitialize(this); |
101 | 101 |
102 if (!IS_NULL_OR_UNDEFINED(iterable)) { | 102 if (!IS_NULL_OR_UNDEFINED(iterable)) { |
103 var adder = this.add; | 103 var adder = this.add; |
104 if (!IS_SPEC_FUNCTION(adder)) { | 104 if (!IS_SPEC_FUNCTION(adder)) { |
105 throw MakeTypeError(kPropertyNotFunction, 'add', this); | 105 throw MakeTypeError(kPropertyNotFunction, ['add', this]); |
106 } | 106 } |
107 | 107 |
108 for (var value of iterable) { | 108 for (var value of iterable) { |
109 %_CallFunction(this, value, adder); | 109 %_CallFunction(this, value, adder); |
110 } | 110 } |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 | 114 |
115 function SetAdd(key) { | 115 function SetAdd(key) { |
116 if (!IS_SET(this)) { | 116 if (!IS_SET(this)) { |
117 throw MakeTypeError(kIncompatibleMethodReceiver, 'Set.prototype.add', this); | 117 throw MakeTypeError('incompatible_method_receiver', |
| 118 ['Set.prototype.add', this]); |
118 } | 119 } |
119 // Normalize -0 to +0 as required by the spec. | 120 // Normalize -0 to +0 as required by the spec. |
120 // Even though we use SameValueZero as the comparison for the keys we don't | 121 // Even though we use SameValueZero as the comparison for the keys we don't |
121 // want to ever store -0 as the key since the key is directly exposed when | 122 // want to ever store -0 as the key since the key is directly exposed when |
122 // doing iteration. | 123 // doing iteration. |
123 if (key === 0) { | 124 if (key === 0) { |
124 key = 0; | 125 key = 0; |
125 } | 126 } |
126 var table = %_JSCollectionGetTable(this); | 127 var table = %_JSCollectionGetTable(this); |
127 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); | 128 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); |
(...skipping 19 matching lines...) Expand all Loading... |
147 ORDERED_HASH_TABLE_SET_BUCKET_AT(table, bucket, entry); | 148 ORDERED_HASH_TABLE_SET_BUCKET_AT(table, bucket, entry); |
148 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof + 1); | 149 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof + 1); |
149 FIXED_ARRAY_SET(table, index, key); | 150 FIXED_ARRAY_SET(table, index, key); |
150 FIXED_ARRAY_SET_SMI(table, index + 1, chainEntry); | 151 FIXED_ARRAY_SET_SMI(table, index + 1, chainEntry); |
151 return this; | 152 return this; |
152 } | 153 } |
153 | 154 |
154 | 155 |
155 function SetHas(key) { | 156 function SetHas(key) { |
156 if (!IS_SET(this)) { | 157 if (!IS_SET(this)) { |
157 throw MakeTypeError(kIncompatibleMethodReceiver, 'Set.prototype.has', this); | 158 throw MakeTypeError('incompatible_method_receiver', |
| 159 ['Set.prototype.has', this]); |
158 } | 160 } |
159 var table = %_JSCollectionGetTable(this); | 161 var table = %_JSCollectionGetTable(this); |
160 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); | 162 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); |
161 var hash = GetHash(key); | 163 var hash = GetHash(key); |
162 return SetFindEntry(table, numBuckets, key, hash) !== NOT_FOUND; | 164 return SetFindEntry(table, numBuckets, key, hash) !== NOT_FOUND; |
163 } | 165 } |
164 | 166 |
165 | 167 |
166 function SetDelete(key) { | 168 function SetDelete(key) { |
167 if (!IS_SET(this)) { | 169 if (!IS_SET(this)) { |
168 throw MakeTypeError(kIncompatibleMethodReceiver, | 170 throw MakeTypeError('incompatible_method_receiver', |
169 'Set.prototype.delete', this); | 171 ['Set.prototype.delete', this]); |
170 } | 172 } |
171 var table = %_JSCollectionGetTable(this); | 173 var table = %_JSCollectionGetTable(this); |
172 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); | 174 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); |
173 var hash = GetHash(key); | 175 var hash = GetHash(key); |
174 var entry = SetFindEntry(table, numBuckets, key, hash); | 176 var entry = SetFindEntry(table, numBuckets, key, hash); |
175 if (entry === NOT_FOUND) return false; | 177 if (entry === NOT_FOUND) return false; |
176 | 178 |
177 var nof = ORDERED_HASH_TABLE_ELEMENT_COUNT(table) - 1; | 179 var nof = ORDERED_HASH_TABLE_ELEMENT_COUNT(table) - 1; |
178 var nod = ORDERED_HASH_TABLE_DELETED_COUNT(table) + 1; | 180 var nod = ORDERED_HASH_TABLE_DELETED_COUNT(table) + 1; |
179 var index = ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets); | 181 var index = ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets); |
180 FIXED_ARRAY_SET(table, index, %_TheHole()); | 182 FIXED_ARRAY_SET(table, index, %_TheHole()); |
181 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof); | 183 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof); |
182 ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, nod); | 184 ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, nod); |
183 if (nof < (numBuckets >>> 1)) %SetShrink(this); | 185 if (nof < (numBuckets >>> 1)) %SetShrink(this); |
184 return true; | 186 return true; |
185 } | 187 } |
186 | 188 |
187 | 189 |
188 function SetGetSize() { | 190 function SetGetSize() { |
189 if (!IS_SET(this)) { | 191 if (!IS_SET(this)) { |
190 throw MakeTypeError(kIncompatibleMethodReceiver, | 192 throw MakeTypeError('incompatible_method_receiver', |
191 'Set.prototype.size', this); | 193 ['Set.prototype.size', this]); |
192 } | 194 } |
193 var table = %_JSCollectionGetTable(this); | 195 var table = %_JSCollectionGetTable(this); |
194 return ORDERED_HASH_TABLE_ELEMENT_COUNT(table); | 196 return ORDERED_HASH_TABLE_ELEMENT_COUNT(table); |
195 } | 197 } |
196 | 198 |
197 | 199 |
198 function SetClearJS() { | 200 function SetClearJS() { |
199 if (!IS_SET(this)) { | 201 if (!IS_SET(this)) { |
200 throw MakeTypeError(kIncompatibleMethodReceiver, | 202 throw MakeTypeError('incompatible_method_receiver', |
201 'Set.prototype.clear', this); | 203 ['Set.prototype.clear', this]); |
202 } | 204 } |
203 %_SetClear(this); | 205 %_SetClear(this); |
204 } | 206 } |
205 | 207 |
206 | 208 |
207 function SetForEach(f, receiver) { | 209 function SetForEach(f, receiver) { |
208 if (!IS_SET(this)) { | 210 if (!IS_SET(this)) { |
209 throw MakeTypeError(kIncompatibleMethodReceiver, | 211 throw MakeTypeError('incompatible_method_receiver', |
210 'Set.prototype.forEach', this); | 212 ['Set.prototype.forEach', this]); |
211 } | 213 } |
212 | 214 |
213 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 215 if (!IS_SPEC_FUNCTION(f)) { |
| 216 throw MakeTypeError('called_non_callable', [f]); |
| 217 } |
214 var needs_wrapper = false; | 218 var needs_wrapper = false; |
215 if (IS_NULL_OR_UNDEFINED(receiver)) { | 219 if (IS_NULL_OR_UNDEFINED(receiver)) { |
216 receiver = %GetDefaultReceiver(f) || receiver; | 220 receiver = %GetDefaultReceiver(f) || receiver; |
217 } else { | 221 } else { |
218 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 222 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
219 } | 223 } |
220 | 224 |
221 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); | 225 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); |
222 var key; | 226 var key; |
223 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 227 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 function MapConstructor(iterable) { | 261 function MapConstructor(iterable) { |
258 if (!%_IsConstructCall()) { | 262 if (!%_IsConstructCall()) { |
259 throw MakeTypeError('constructor_not_function', ['Map']); | 263 throw MakeTypeError('constructor_not_function', ['Map']); |
260 } | 264 } |
261 | 265 |
262 %_MapInitialize(this); | 266 %_MapInitialize(this); |
263 | 267 |
264 if (!IS_NULL_OR_UNDEFINED(iterable)) { | 268 if (!IS_NULL_OR_UNDEFINED(iterable)) { |
265 var adder = this.set; | 269 var adder = this.set; |
266 if (!IS_SPEC_FUNCTION(adder)) { | 270 if (!IS_SPEC_FUNCTION(adder)) { |
267 throw MakeTypeError(kPropertyNotFunction, 'set', this); | 271 throw MakeTypeError(kPropertyNotFunction, ['set', this]); |
268 } | 272 } |
269 | 273 |
270 for (var nextItem of iterable) { | 274 for (var nextItem of iterable) { |
271 if (!IS_SPEC_OBJECT(nextItem)) { | 275 if (!IS_SPEC_OBJECT(nextItem)) { |
272 throw MakeTypeError('iterator_value_not_an_object', [nextItem]); | 276 throw MakeTypeError('iterator_value_not_an_object', [nextItem]); |
273 } | 277 } |
274 %_CallFunction(this, nextItem[0], nextItem[1], adder); | 278 %_CallFunction(this, nextItem[0], nextItem[1], adder); |
275 } | 279 } |
276 } | 280 } |
277 } | 281 } |
278 | 282 |
279 | 283 |
280 function MapGet(key) { | 284 function MapGet(key) { |
281 if (!IS_MAP(this)) { | 285 if (!IS_MAP(this)) { |
282 throw MakeTypeError(kIncompatibleMethodReceiver, | 286 throw MakeTypeError('incompatible_method_receiver', |
283 'Map.prototype.get', this); | 287 ['Map.prototype.get', this]); |
284 } | 288 } |
285 var table = %_JSCollectionGetTable(this); | 289 var table = %_JSCollectionGetTable(this); |
286 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); | 290 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); |
287 var hash = GetHash(key); | 291 var hash = GetHash(key); |
288 var entry = MapFindEntry(table, numBuckets, key, hash); | 292 var entry = MapFindEntry(table, numBuckets, key, hash); |
289 if (entry === NOT_FOUND) return UNDEFINED; | 293 if (entry === NOT_FOUND) return UNDEFINED; |
290 return ORDERED_HASH_MAP_VALUE_AT(table, entry, numBuckets); | 294 return ORDERED_HASH_MAP_VALUE_AT(table, entry, numBuckets); |
291 } | 295 } |
292 | 296 |
293 | 297 |
294 function MapSet(key, value) { | 298 function MapSet(key, value) { |
295 if (!IS_MAP(this)) { | 299 if (!IS_MAP(this)) { |
296 throw MakeTypeError(kIncompatibleMethodReceiver, | 300 throw MakeTypeError('incompatible_method_receiver', |
297 'Map.prototype.set', this); | 301 ['Map.prototype.set', this]); |
298 } | 302 } |
299 // Normalize -0 to +0 as required by the spec. | 303 // Normalize -0 to +0 as required by the spec. |
300 // Even though we use SameValueZero as the comparison for the keys we don't | 304 // Even though we use SameValueZero as the comparison for the keys we don't |
301 // want to ever store -0 as the key since the key is directly exposed when | 305 // want to ever store -0 as the key since the key is directly exposed when |
302 // doing iteration. | 306 // doing iteration. |
303 if (key === 0) { | 307 if (key === 0) { |
304 key = 0; | 308 key = 0; |
305 } | 309 } |
306 | 310 |
307 var table = %_JSCollectionGetTable(this); | 311 var table = %_JSCollectionGetTable(this); |
(...skipping 26 matching lines...) Expand all Loading... |
334 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof + 1); | 338 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof + 1); |
335 FIXED_ARRAY_SET(table, index, key); | 339 FIXED_ARRAY_SET(table, index, key); |
336 FIXED_ARRAY_SET(table, index + 1, value); | 340 FIXED_ARRAY_SET(table, index + 1, value); |
337 FIXED_ARRAY_SET(table, index + 2, chainEntry); | 341 FIXED_ARRAY_SET(table, index + 2, chainEntry); |
338 return this; | 342 return this; |
339 } | 343 } |
340 | 344 |
341 | 345 |
342 function MapHas(key) { | 346 function MapHas(key) { |
343 if (!IS_MAP(this)) { | 347 if (!IS_MAP(this)) { |
344 throw MakeTypeError(kIncompatibleMethodReceiver, | 348 throw MakeTypeError('incompatible_method_receiver', |
345 'Map.prototype.has', this); | 349 ['Map.prototype.has', this]); |
346 } | 350 } |
347 var table = %_JSCollectionGetTable(this); | 351 var table = %_JSCollectionGetTable(this); |
348 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); | 352 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); |
349 var hash = GetHash(key); | 353 var hash = GetHash(key); |
350 return MapFindEntry(table, numBuckets, key, hash) !== NOT_FOUND; | 354 return MapFindEntry(table, numBuckets, key, hash) !== NOT_FOUND; |
351 } | 355 } |
352 | 356 |
353 | 357 |
354 function MapDelete(key) { | 358 function MapDelete(key) { |
355 if (!IS_MAP(this)) { | 359 if (!IS_MAP(this)) { |
356 throw MakeTypeError(kIncompatibleMethodReceiver, | 360 throw MakeTypeError('incompatible_method_receiver', |
357 'Map.prototype.delete', this); | 361 ['Map.prototype.delete', this]); |
358 } | 362 } |
359 var table = %_JSCollectionGetTable(this); | 363 var table = %_JSCollectionGetTable(this); |
360 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); | 364 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); |
361 var hash = GetHash(key); | 365 var hash = GetHash(key); |
362 var entry = MapFindEntry(table, numBuckets, key, hash); | 366 var entry = MapFindEntry(table, numBuckets, key, hash); |
363 if (entry === NOT_FOUND) return false; | 367 if (entry === NOT_FOUND) return false; |
364 | 368 |
365 var nof = ORDERED_HASH_TABLE_ELEMENT_COUNT(table) - 1; | 369 var nof = ORDERED_HASH_TABLE_ELEMENT_COUNT(table) - 1; |
366 var nod = ORDERED_HASH_TABLE_DELETED_COUNT(table) + 1; | 370 var nod = ORDERED_HASH_TABLE_DELETED_COUNT(table) + 1; |
367 var index = ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets); | 371 var index = ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets); |
368 FIXED_ARRAY_SET(table, index, %_TheHole()); | 372 FIXED_ARRAY_SET(table, index, %_TheHole()); |
369 FIXED_ARRAY_SET(table, index + 1, %_TheHole()); | 373 FIXED_ARRAY_SET(table, index + 1, %_TheHole()); |
370 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof); | 374 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof); |
371 ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, nod); | 375 ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, nod); |
372 if (nof < (numBuckets >>> 1)) %MapShrink(this); | 376 if (nof < (numBuckets >>> 1)) %MapShrink(this); |
373 return true; | 377 return true; |
374 } | 378 } |
375 | 379 |
376 | 380 |
377 function MapGetSize() { | 381 function MapGetSize() { |
378 if (!IS_MAP(this)) { | 382 if (!IS_MAP(this)) { |
379 throw MakeTypeError(kIncompatibleMethodReceiver, | 383 throw MakeTypeError('incompatible_method_receiver', |
380 'Map.prototype.size', this); | 384 ['Map.prototype.size', this]); |
381 } | 385 } |
382 var table = %_JSCollectionGetTable(this); | 386 var table = %_JSCollectionGetTable(this); |
383 return ORDERED_HASH_TABLE_ELEMENT_COUNT(table); | 387 return ORDERED_HASH_TABLE_ELEMENT_COUNT(table); |
384 } | 388 } |
385 | 389 |
386 | 390 |
387 function MapClearJS() { | 391 function MapClearJS() { |
388 if (!IS_MAP(this)) { | 392 if (!IS_MAP(this)) { |
389 throw MakeTypeError(kIncompatibleMethodReceiver, | 393 throw MakeTypeError('incompatible_method_receiver', |
390 'Map.prototype.clear', this); | 394 ['Map.prototype.clear', this]); |
391 } | 395 } |
392 %_MapClear(this); | 396 %_MapClear(this); |
393 } | 397 } |
394 | 398 |
395 | 399 |
396 function MapForEach(f, receiver) { | 400 function MapForEach(f, receiver) { |
397 if (!IS_MAP(this)) { | 401 if (!IS_MAP(this)) { |
398 throw MakeTypeError(kIncompatibleMethodReceiver, | 402 throw MakeTypeError('incompatible_method_receiver', |
399 'Map.prototype.forEach', this); | 403 ['Map.prototype.forEach', this]); |
400 } | 404 } |
401 | 405 |
402 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 406 if (!IS_SPEC_FUNCTION(f)) { |
| 407 throw MakeTypeError('called_non_callable', [f]); |
| 408 } |
403 var needs_wrapper = false; | 409 var needs_wrapper = false; |
404 if (IS_NULL_OR_UNDEFINED(receiver)) { | 410 if (IS_NULL_OR_UNDEFINED(receiver)) { |
405 receiver = %GetDefaultReceiver(f) || receiver; | 411 receiver = %GetDefaultReceiver(f) || receiver; |
406 } else { | 412 } else { |
407 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 413 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
408 } | 414 } |
409 | 415 |
410 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES); | 416 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES); |
411 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 417 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
412 var value_array = [UNDEFINED, UNDEFINED]; | 418 var value_array = [UNDEFINED, UNDEFINED]; |
(...skipping 19 matching lines...) Expand all Loading... |
432 InstallFunctions($Map.prototype, DONT_ENUM, [ | 438 InstallFunctions($Map.prototype, DONT_ENUM, [ |
433 "get", MapGet, | 439 "get", MapGet, |
434 "set", MapSet, | 440 "set", MapSet, |
435 "has", MapHas, | 441 "has", MapHas, |
436 "delete", MapDelete, | 442 "delete", MapDelete, |
437 "clear", MapClearJS, | 443 "clear", MapClearJS, |
438 "forEach", MapForEach | 444 "forEach", MapForEach |
439 ]); | 445 ]); |
440 | 446 |
441 })(); | 447 })(); |
OLD | NEW |