Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: src/array.js

Issue 553413002: Array.prototype.{every, filter, find, findIndex, forEach, map, some}: Use fresh primitive wrapper f… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed nits from last patch. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/collection.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « no previous file | src/collection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698