Index: src/array.js |
diff --git a/src/array.js b/src/array.js |
index 44deff7de42c60986741615b1be389f9668dbf85..312eeff6c47bd691e633cad00e8dbf22b7d27d5a 100644 |
--- a/src/array.js |
+++ b/src/array.js |
@@ -1125,10 +1125,11 @@ function ArrayFilter(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 if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { |
- receiver = ToObject(receiver); |
+ } else { |
+ needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
} |
var result = new $Array(); |
@@ -1140,7 +1141,8 @@ function ArrayFilter(f, receiver) { |
var element = array[i]; |
// Prepare break slots for debugger step in. |
if (stepping) %DebugPrepareStepInIfStepping(f); |
- if (%_CallFunction(receiver, element, i, array, f)) { |
+ var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
+ if (%_CallFunction(new_receiver, element, i, array, f)) { |
accumulator[accumulator_length++] = element; |
} |
} |
@@ -1161,10 +1163,11 @@ function ArrayForEach(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 if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { |
- receiver = ToObject(receiver); |
+ } else { |
+ needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
} |
var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
@@ -1173,7 +1176,8 @@ function ArrayForEach(f, receiver) { |
var element = array[i]; |
// Prepare break slots for debugger step in. |
if (stepping) %DebugPrepareStepInIfStepping(f); |
- %_CallFunction(receiver, element, i, array, f); |
+ var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
+ %_CallFunction(new_receiver, element, i, array, f); |
} |
} |
} |
@@ -1192,10 +1196,11 @@ function ArraySome(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 if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { |
- receiver = ToObject(receiver); |
+ } else { |
+ needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
} |
var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
@@ -1204,7 +1209,8 @@ function ArraySome(f, receiver) { |
var element = array[i]; |
// Prepare break slots for debugger step in. |
if (stepping) %DebugPrepareStepInIfStepping(f); |
- if (%_CallFunction(receiver, element, i, array, f)) return true; |
+ var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
+ if (%_CallFunction(new_receiver, element, i, array, f)) return true; |
} |
} |
return false; |
@@ -1222,10 +1228,11 @@ function ArrayEvery(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 if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { |
- receiver = ToObject(receiver); |
+ } else { |
+ needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
} |
var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
@@ -1234,7 +1241,8 @@ function ArrayEvery(f, receiver) { |
var element = array[i]; |
// Prepare break slots for debugger step in. |
if (stepping) %DebugPrepareStepInIfStepping(f); |
- if (!%_CallFunction(receiver, element, i, array, f)) return false; |
+ var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
+ if (!%_CallFunction(new_receiver, element, i, array, f)) return false; |
} |
} |
return true; |
@@ -1251,10 +1259,11 @@ function ArrayMap(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 if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { |
- receiver = ToObject(receiver); |
+ } else { |
+ needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
} |
var result = new $Array(); |
@@ -1265,7 +1274,8 @@ function ArrayMap(f, receiver) { |
var element = array[i]; |
// Prepare break slots for debugger step in. |
if (stepping) %DebugPrepareStepInIfStepping(f); |
- accumulator[i] = %_CallFunction(receiver, element, i, array, f); |
+ var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
+ accumulator[i] = %_CallFunction(new_receiver, element, i, array, f); |
} |
} |
%MoveArrayContents(accumulator, result); |