| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 function SetForEach(f, receiver) { | 99 function SetForEach(f, receiver) { |
| 100 if (!IS_SET(this)) { | 100 if (!IS_SET(this)) { |
| 101 throw MakeTypeError('incompatible_method_receiver', | 101 throw MakeTypeError('incompatible_method_receiver', |
| 102 ['Set.prototype.forEach', this]); | 102 ['Set.prototype.forEach', this]); |
| 103 } | 103 } |
| 104 | 104 |
| 105 if (!IS_SPEC_FUNCTION(f)) { | 105 if (!IS_SPEC_FUNCTION(f)) { |
| 106 throw MakeTypeError('called_non_callable', [f]); | 106 throw MakeTypeError('called_non_callable', [f]); |
| 107 } | 107 } |
| 108 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 109 receiver = %GetDefaultReceiver(f) || receiver; |
| 110 } |
| 111 var needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 108 | 112 |
| 109 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); | 113 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); |
| 110 var key; | 114 var key; |
| 111 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 115 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 112 var value_array = [UNDEFINED]; | 116 var value_array = [UNDEFINED]; |
| 113 while (%SetIteratorNext(iterator, value_array)) { | 117 while (%SetIteratorNext(iterator, value_array)) { |
| 114 if (stepping) %DebugPrepareStepInIfStepping(f); | 118 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 115 key = value_array[0]; | 119 key = value_array[0]; |
| 116 %_CallFunction(receiver, key, key, this, f); | 120 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 121 %_CallFunction(new_receiver, key, key, this, f); |
| 117 } | 122 } |
| 118 } | 123 } |
| 119 | 124 |
| 120 | 125 |
| 121 // ------------------------------------------------------------------- | 126 // ------------------------------------------------------------------- |
| 122 | 127 |
| 123 function SetUpSet() { | 128 function SetUpSet() { |
| 124 %CheckIsBootstrapping(); | 129 %CheckIsBootstrapping(); |
| 125 | 130 |
| 126 %SetCode($Set, SetConstructor); | 131 %SetCode($Set, SetConstructor); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 247 |
| 243 function MapForEach(f, receiver) { | 248 function MapForEach(f, receiver) { |
| 244 if (!IS_MAP(this)) { | 249 if (!IS_MAP(this)) { |
| 245 throw MakeTypeError('incompatible_method_receiver', | 250 throw MakeTypeError('incompatible_method_receiver', |
| 246 ['Map.prototype.forEach', this]); | 251 ['Map.prototype.forEach', this]); |
| 247 } | 252 } |
| 248 | 253 |
| 249 if (!IS_SPEC_FUNCTION(f)) { | 254 if (!IS_SPEC_FUNCTION(f)) { |
| 250 throw MakeTypeError('called_non_callable', [f]); | 255 throw MakeTypeError('called_non_callable', [f]); |
| 251 } | 256 } |
| 257 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 258 receiver = %GetDefaultReceiver(f) || receiver; |
| 259 } |
| 260 var needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 252 | 261 |
| 253 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES); | 262 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES); |
| 254 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 263 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 255 var value_array = [UNDEFINED, UNDEFINED]; | 264 var value_array = [UNDEFINED, UNDEFINED]; |
| 256 while (%MapIteratorNext(iterator, value_array)) { | 265 while (%MapIteratorNext(iterator, value_array)) { |
| 257 if (stepping) %DebugPrepareStepInIfStepping(f); | 266 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 258 %_CallFunction(receiver, value_array[1], value_array[0], this, f); | 267 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 268 %_CallFunction(new_receiver, value_array[1], value_array[0], this, f); |
| 259 } | 269 } |
| 260 } | 270 } |
| 261 | 271 |
| 262 | 272 |
| 263 // ------------------------------------------------------------------- | 273 // ------------------------------------------------------------------- |
| 264 | 274 |
| 265 function SetUpMap() { | 275 function SetUpMap() { |
| 266 %CheckIsBootstrapping(); | 276 %CheckIsBootstrapping(); |
| 267 | 277 |
| 268 %SetCode($Map, MapConstructor); | 278 %SetCode($Map, MapConstructor); |
| 269 %FunctionSetPrototype($Map, new $Object()); | 279 %FunctionSetPrototype($Map, new $Object()); |
| 270 %AddNamedProperty($Map.prototype, "constructor", $Map, DONT_ENUM); | 280 %AddNamedProperty($Map.prototype, "constructor", $Map, DONT_ENUM); |
| 271 | 281 |
| 272 %FunctionSetLength(MapForEach, 1); | 282 %FunctionSetLength(MapForEach, 1); |
| 273 | 283 |
| 274 // Set up the non-enumerable functions on the Map prototype object. | 284 // Set up the non-enumerable functions on the Map prototype object. |
| 275 InstallGetter($Map.prototype, "size", MapGetSizeJS); | 285 InstallGetter($Map.prototype, "size", MapGetSizeJS); |
| 276 InstallFunctions($Map.prototype, DONT_ENUM, $Array( | 286 InstallFunctions($Map.prototype, DONT_ENUM, $Array( |
| 277 "get", MapGetJS, | 287 "get", MapGetJS, |
| 278 "set", MapSetJS, | 288 "set", MapSetJS, |
| 279 "has", MapHasJS, | 289 "has", MapHasJS, |
| 280 "delete", MapDeleteJS, | 290 "delete", MapDeleteJS, |
| 281 "clear", MapClearJS, | 291 "clear", MapClearJS, |
| 282 "forEach", MapForEach | 292 "forEach", MapForEach |
| 283 )); | 293 )); |
| 284 } | 294 } |
| 285 | 295 |
| 286 SetUpMap(); | 296 SetUpMap(); |
| OLD | NEW |