Chromium Code Reviews| Index: src/collection.js |
| diff --git a/src/collection.js b/src/collection.js |
| index 0027bd732041f94ccf81dbfe3256c4f75d680c5a..7c7dd8bb728cda1f4c5262d32080834acb8fef0e 100644 |
| --- a/src/collection.js |
| +++ b/src/collection.js |
| @@ -105,15 +105,22 @@ function SetForEach(f, receiver) { |
| if (!IS_SPEC_FUNCTION(f)) { |
| throw MakeTypeError('called_non_callable', [f]); |
| } |
| + if (IS_NULL_OR_UNDEFINED(receiver)) { |
| + receiver = %GetDefaultReceiver(f) || receiver; |
| + } |
| var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); |
| var key; |
| var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| var value_array = [UNDEFINED]; |
| while (%SetIteratorNext(iterator, value_array)) { |
| + var new_receiver = receiver; |
| + 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.
|
| + new_receiver = ToObject(receiver); |
| + } |
| if (stepping) %DebugPrepareStepInIfStepping(f); |
| key = value_array[0]; |
| - %_CallFunction(receiver, key, key, this, f); |
| + %_CallFunction(new_receiver, key, key, this, f); |
| } |
| } |
| @@ -249,13 +256,20 @@ function MapForEach(f, receiver) { |
| if (!IS_SPEC_FUNCTION(f)) { |
| throw MakeTypeError('called_non_callable', [f]); |
| } |
| + if (IS_NULL_OR_UNDEFINED(receiver)) { |
| + receiver = %GetDefaultReceiver(f) || receiver; |
| + } |
| var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES); |
| var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| var value_array = [UNDEFINED, UNDEFINED]; |
| while (%MapIteratorNext(iterator, value_array)) { |
| + var new_receiver = receiver; |
| + if (!IS_NULL_OR_UNDEFINED(receiver)) { |
|
wingo
2014/09/15 09:12:21
Same comment here as Erik's comment above.
|
| + new_receiver = ToObject(receiver); |
| + } |
| if (stepping) %DebugPrepareStepInIfStepping(f); |
| - %_CallFunction(receiver, value_array[1], value_array[0], this, f); |
| + %_CallFunction(new_receiver, value_array[1], value_array[0], this, f); |
| } |
| } |