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 var $getHash; | 5 var $getHash; |
6 var $getExistingHash; | 6 var $getExistingHash; |
7 | 7 |
8 (function(global, utils) { | 8 (function(global, utils) { |
9 "use strict"; | 9 "use strict"; |
10 | 10 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 %_SetInitialize(this); | 133 %_SetInitialize(this); |
134 | 134 |
135 if (!IS_NULL_OR_UNDEFINED(iterable)) { | 135 if (!IS_NULL_OR_UNDEFINED(iterable)) { |
136 var adder = this.add; | 136 var adder = this.add; |
137 if (!IS_CALLABLE(adder)) { | 137 if (!IS_CALLABLE(adder)) { |
138 throw MakeTypeError(kPropertyNotFunction, 'add', this); | 138 throw MakeTypeError(kPropertyNotFunction, 'add', this); |
139 } | 139 } |
140 | 140 |
141 for (var value of iterable) { | 141 for (var value of iterable) { |
142 %_CallFunction(this, value, adder); | 142 %_Call(adder, this, value); |
143 } | 143 } |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 | 147 |
148 function SetAdd(key) { | 148 function SetAdd(key) { |
149 if (!IS_SET(this)) { | 149 if (!IS_SET(this)) { |
150 throw MakeTypeError(kIncompatibleMethodReceiver, 'Set.prototype.add', this); | 150 throw MakeTypeError(kIncompatibleMethodReceiver, 'Set.prototype.add', this); |
151 } | 151 } |
152 // Normalize -0 to +0 as required by the spec. | 152 // Normalize -0 to +0 as required by the spec. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 } | 239 } |
240 | 240 |
241 | 241 |
242 function SetForEach(f, receiver) { | 242 function SetForEach(f, receiver) { |
243 if (!IS_SET(this)) { | 243 if (!IS_SET(this)) { |
244 throw MakeTypeError(kIncompatibleMethodReceiver, | 244 throw MakeTypeError(kIncompatibleMethodReceiver, |
245 'Set.prototype.forEach', this); | 245 'Set.prototype.forEach', this); |
246 } | 246 } |
247 | 247 |
248 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 248 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
249 var needs_wrapper = false; | |
250 if (IS_NULL(receiver)) { | |
251 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | |
252 } else if (!IS_UNDEFINED(receiver)) { | |
253 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | |
254 } | |
255 | 249 |
256 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); | 250 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); |
257 var key; | 251 var key; |
258 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 252 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
259 var value_array = [UNDEFINED]; | 253 var value_array = [UNDEFINED]; |
260 while (%SetIteratorNext(iterator, value_array)) { | 254 while (%SetIteratorNext(iterator, value_array)) { |
261 if (stepping) %DebugPrepareStepInIfStepping(f); | 255 if (stepping) %DebugPrepareStepInIfStepping(f); |
262 key = value_array[0]; | 256 key = value_array[0]; |
263 var new_receiver = needs_wrapper ? TO_OBJECT(receiver) : receiver; | 257 %_Call(f, receiver, key, key, this); |
264 %_CallFunction(new_receiver, key, key, this, f); | |
265 } | 258 } |
266 } | 259 } |
267 | 260 |
268 // ------------------------------------------------------------------- | 261 // ------------------------------------------------------------------- |
269 | 262 |
270 %SetCode(GlobalSet, SetConstructor); | 263 %SetCode(GlobalSet, SetConstructor); |
271 %FunctionSetLength(GlobalSet, 0); | 264 %FunctionSetLength(GlobalSet, 0); |
272 %FunctionSetPrototype(GlobalSet, new GlobalObject()); | 265 %FunctionSetPrototype(GlobalSet, new GlobalObject()); |
273 %AddNamedProperty(GlobalSet.prototype, "constructor", GlobalSet, DONT_ENUM); | 266 %AddNamedProperty(GlobalSet.prototype, "constructor", GlobalSet, DONT_ENUM); |
274 %AddNamedProperty(GlobalSet.prototype, toStringTagSymbol, "Set", | 267 %AddNamedProperty(GlobalSet.prototype, toStringTagSymbol, "Set", |
(...skipping 25 matching lines...) Expand all Loading... |
300 if (!IS_NULL_OR_UNDEFINED(iterable)) { | 293 if (!IS_NULL_OR_UNDEFINED(iterable)) { |
301 var adder = this.set; | 294 var adder = this.set; |
302 if (!IS_CALLABLE(adder)) { | 295 if (!IS_CALLABLE(adder)) { |
303 throw MakeTypeError(kPropertyNotFunction, 'set', this); | 296 throw MakeTypeError(kPropertyNotFunction, 'set', this); |
304 } | 297 } |
305 | 298 |
306 for (var nextItem of iterable) { | 299 for (var nextItem of iterable) { |
307 if (!IS_SPEC_OBJECT(nextItem)) { | 300 if (!IS_SPEC_OBJECT(nextItem)) { |
308 throw MakeTypeError(kIteratorValueNotAnObject, nextItem); | 301 throw MakeTypeError(kIteratorValueNotAnObject, nextItem); |
309 } | 302 } |
310 %_CallFunction(this, nextItem[0], nextItem[1], adder); | 303 %_Call(adder, this, nextItem[0], nextItem[1]); |
311 } | 304 } |
312 } | 305 } |
313 } | 306 } |
314 | 307 |
315 | 308 |
316 function MapGet(key) { | 309 function MapGet(key) { |
317 if (!IS_MAP(this)) { | 310 if (!IS_MAP(this)) { |
318 throw MakeTypeError(kIncompatibleMethodReceiver, | 311 throw MakeTypeError(kIncompatibleMethodReceiver, |
319 'Map.prototype.get', this); | 312 'Map.prototype.get', this); |
320 } | 313 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 } | 423 } |
431 | 424 |
432 | 425 |
433 function MapForEach(f, receiver) { | 426 function MapForEach(f, receiver) { |
434 if (!IS_MAP(this)) { | 427 if (!IS_MAP(this)) { |
435 throw MakeTypeError(kIncompatibleMethodReceiver, | 428 throw MakeTypeError(kIncompatibleMethodReceiver, |
436 'Map.prototype.forEach', this); | 429 'Map.prototype.forEach', this); |
437 } | 430 } |
438 | 431 |
439 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 432 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
440 var needs_wrapper = false; | |
441 if (IS_NULL(receiver)) { | |
442 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | |
443 } else if (!IS_UNDEFINED(receiver)) { | |
444 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | |
445 } | |
446 | 433 |
447 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES); | 434 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES); |
448 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 435 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
449 var value_array = [UNDEFINED, UNDEFINED]; | 436 var value_array = [UNDEFINED, UNDEFINED]; |
450 while (%MapIteratorNext(iterator, value_array)) { | 437 while (%MapIteratorNext(iterator, value_array)) { |
451 if (stepping) %DebugPrepareStepInIfStepping(f); | 438 if (stepping) %DebugPrepareStepInIfStepping(f); |
452 var new_receiver = needs_wrapper ? TO_OBJECT(receiver) : receiver; | 439 %_Call(f, receiver, value_array[1], value_array[0], this); |
453 %_CallFunction(new_receiver, value_array[1], value_array[0], this, f); | |
454 } | 440 } |
455 } | 441 } |
456 | 442 |
457 // ------------------------------------------------------------------- | 443 // ------------------------------------------------------------------- |
458 | 444 |
459 %SetCode(GlobalMap, MapConstructor); | 445 %SetCode(GlobalMap, MapConstructor); |
460 %FunctionSetLength(GlobalMap, 0); | 446 %FunctionSetLength(GlobalMap, 0); |
461 %FunctionSetPrototype(GlobalMap, new GlobalObject()); | 447 %FunctionSetPrototype(GlobalMap, new GlobalObject()); |
462 %AddNamedProperty(GlobalMap.prototype, "constructor", GlobalMap, DONT_ENUM); | 448 %AddNamedProperty(GlobalMap.prototype, "constructor", GlobalMap, DONT_ENUM); |
463 %AddNamedProperty( | 449 %AddNamedProperty( |
(...skipping 15 matching lines...) Expand all Loading... |
479 // Expose to the global scope. | 465 // Expose to the global scope. |
480 $getHash = GetHash; | 466 $getHash = GetHash; |
481 $getExistingHash = GetExistingHash; | 467 $getExistingHash = GetExistingHash; |
482 | 468 |
483 function MapFromArray(array) { | 469 function MapFromArray(array) { |
484 var map = new GlobalMap; | 470 var map = new GlobalMap; |
485 var length = array.length; | 471 var length = array.length; |
486 for (var i = 0; i < length; i += 2) { | 472 for (var i = 0; i < length; i += 2) { |
487 var key = array[i]; | 473 var key = array[i]; |
488 var value = array[i + 1]; | 474 var value = array[i + 1]; |
489 %_CallFunction(map, key, value, MapSet); | 475 %_Call(MapSet, map, key, value); |
490 } | 476 } |
491 return map; | 477 return map; |
492 }; | 478 }; |
493 | 479 |
494 function SetFromArray(array) { | 480 function SetFromArray(array) { |
495 var set = new GlobalSet; | 481 var set = new GlobalSet; |
496 var length = array.length; | 482 var length = array.length; |
497 for (var i = 0; i < length; ++i) { | 483 for (var i = 0; i < length; ++i) { |
498 %_CallFunction(set, array[i], SetAdd); | 484 %_Call(SetAdd, set, array[i]); |
499 } | 485 } |
500 return set; | 486 return set; |
501 }; | 487 }; |
502 | 488 |
503 // ----------------------------------------------------------------------- | 489 // ----------------------------------------------------------------------- |
504 // Exports | 490 // Exports |
505 | 491 |
506 %InstallToContext([ | 492 %InstallToContext([ |
507 "map_get", MapGet, | 493 "map_get", MapGet, |
508 "map_set", MapSet, | 494 "map_set", MapSet, |
509 "map_has", MapHas, | 495 "map_has", MapHas, |
510 "map_delete", MapDelete, | 496 "map_delete", MapDelete, |
511 "set_add", SetAdd, | 497 "set_add", SetAdd, |
512 "set_has", SetHas, | 498 "set_has", SetHas, |
513 "set_delete", SetDelete, | 499 "set_delete", SetDelete, |
514 "map_from_array", MapFromArray, | 500 "map_from_array", MapFromArray, |
515 "set_from_array",SetFromArray, | 501 "set_from_array",SetFromArray, |
516 ]); | 502 ]); |
517 | 503 |
518 }) | 504 }) |
OLD | NEW |