Index: src/collection.js |
diff --git a/src/collection.js b/src/collection.js |
index 0027bd732041f94ccf81dbfe3256c4f75d680c5a..7d185d9c34191c14c276dc0520627cff86b6ebe5 100644 |
--- a/src/collection.js |
+++ b/src/collection.js |
@@ -105,6 +105,12 @@ function SetForEach(f, receiver) { |
if (!IS_SPEC_FUNCTION(f)) { |
throw MakeTypeError('called_non_callable', [f]); |
} |
+ var needs_wrapper = false; |
+ if (IS_NULL_OR_UNDEFINED(receiver)) { |
+ receiver = %GetDefaultReceiver(f) || receiver; |
+ } else { |
+ needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
+ } |
var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); |
var key; |
@@ -113,7 +119,8 @@ function SetForEach(f, receiver) { |
while (%SetIteratorNext(iterator, value_array)) { |
if (stepping) %DebugPrepareStepInIfStepping(f); |
key = value_array[0]; |
- %_CallFunction(receiver, key, key, this, f); |
+ var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
+ %_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]); |
} |
+ var needs_wrapper = false; |
+ if (IS_NULL_OR_UNDEFINED(receiver)) { |
+ receiver = %GetDefaultReceiver(f) || receiver; |
+ } else { |
+ needs_wrapper = SHOULD_CREATE_WRAPPER(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)) { |
if (stepping) %DebugPrepareStepInIfStepping(f); |
- %_CallFunction(receiver, value_array[1], value_array[0], this, f); |
+ var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
+ %_CallFunction(new_receiver, value_array[1], value_array[0], this, f); |
} |
} |