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 } | |
108 | 111 |
109 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); | 112 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); |
110 var key; | 113 var key; |
111 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 114 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
112 var value_array = [UNDEFINED]; | 115 var value_array = [UNDEFINED]; |
113 while (%SetIteratorNext(iterator, value_array)) { | 116 while (%SetIteratorNext(iterator, value_array)) { |
117 var new_receiver = receiver; | |
118 if (!IS_NULL_OR_UNDEFINED(receiver)) { | |
arv (Not doing code reviews)
2014/09/12 16:29:17
Why is this one different? Can you verify with the
Diego Pino
2014/09/16 10:45:46
I tried to preserve the semantics of the old code.
| |
119 new_receiver = ToObject(receiver); | |
120 } | |
114 if (stepping) %DebugPrepareStepInIfStepping(f); | 121 if (stepping) %DebugPrepareStepInIfStepping(f); |
115 key = value_array[0]; | 122 key = value_array[0]; |
116 %_CallFunction(receiver, key, key, this, f); | 123 %_CallFunction(new_receiver, key, key, this, f); |
117 } | 124 } |
118 } | 125 } |
119 | 126 |
120 | 127 |
121 // ------------------------------------------------------------------- | 128 // ------------------------------------------------------------------- |
122 | 129 |
123 function SetUpSet() { | 130 function SetUpSet() { |
124 %CheckIsBootstrapping(); | 131 %CheckIsBootstrapping(); |
125 | 132 |
126 %SetCode($Set, SetConstructor); | 133 %SetCode($Set, SetConstructor); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 | 249 |
243 function MapForEach(f, receiver) { | 250 function MapForEach(f, receiver) { |
244 if (!IS_MAP(this)) { | 251 if (!IS_MAP(this)) { |
245 throw MakeTypeError('incompatible_method_receiver', | 252 throw MakeTypeError('incompatible_method_receiver', |
246 ['Map.prototype.forEach', this]); | 253 ['Map.prototype.forEach', this]); |
247 } | 254 } |
248 | 255 |
249 if (!IS_SPEC_FUNCTION(f)) { | 256 if (!IS_SPEC_FUNCTION(f)) { |
250 throw MakeTypeError('called_non_callable', [f]); | 257 throw MakeTypeError('called_non_callable', [f]); |
251 } | 258 } |
259 if (IS_NULL_OR_UNDEFINED(receiver)) { | |
260 receiver = %GetDefaultReceiver(f) || receiver; | |
261 } | |
252 | 262 |
253 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES); | 263 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES); |
254 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 264 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
255 var value_array = [UNDEFINED, UNDEFINED]; | 265 var value_array = [UNDEFINED, UNDEFINED]; |
256 while (%MapIteratorNext(iterator, value_array)) { | 266 while (%MapIteratorNext(iterator, value_array)) { |
267 var new_receiver = receiver; | |
268 if (!IS_NULL_OR_UNDEFINED(receiver)) { | |
wingo
2014/09/15 09:12:21
Same comment here as Erik's comment above.
| |
269 new_receiver = ToObject(receiver); | |
270 } | |
257 if (stepping) %DebugPrepareStepInIfStepping(f); | 271 if (stepping) %DebugPrepareStepInIfStepping(f); |
258 %_CallFunction(receiver, value_array[1], value_array[0], this, f); | 272 %_CallFunction(new_receiver, value_array[1], value_array[0], this, f); |
259 } | 273 } |
260 } | 274 } |
261 | 275 |
262 | 276 |
263 // ------------------------------------------------------------------- | 277 // ------------------------------------------------------------------- |
264 | 278 |
265 function SetUpMap() { | 279 function SetUpMap() { |
266 %CheckIsBootstrapping(); | 280 %CheckIsBootstrapping(); |
267 | 281 |
268 %SetCode($Map, MapConstructor); | 282 %SetCode($Map, MapConstructor); |
269 %FunctionSetPrototype($Map, new $Object()); | 283 %FunctionSetPrototype($Map, new $Object()); |
270 %AddNamedProperty($Map.prototype, "constructor", $Map, DONT_ENUM); | 284 %AddNamedProperty($Map.prototype, "constructor", $Map, DONT_ENUM); |
271 | 285 |
272 %FunctionSetLength(MapForEach, 1); | 286 %FunctionSetLength(MapForEach, 1); |
273 | 287 |
274 // Set up the non-enumerable functions on the Map prototype object. | 288 // Set up the non-enumerable functions on the Map prototype object. |
275 InstallGetter($Map.prototype, "size", MapGetSizeJS); | 289 InstallGetter($Map.prototype, "size", MapGetSizeJS); |
276 InstallFunctions($Map.prototype, DONT_ENUM, $Array( | 290 InstallFunctions($Map.prototype, DONT_ENUM, $Array( |
277 "get", MapGetJS, | 291 "get", MapGetJS, |
278 "set", MapSetJS, | 292 "set", MapSetJS, |
279 "has", MapHasJS, | 293 "has", MapHasJS, |
280 "delete", MapDeleteJS, | 294 "delete", MapDeleteJS, |
281 "clear", MapClearJS, | 295 "clear", MapClearJS, |
282 "forEach", MapForEach | 296 "forEach", MapForEach |
283 )); | 297 )); |
284 } | 298 } |
285 | 299 |
286 SetUpMap(); | 300 SetUpMap(); |
OLD | NEW |