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

Unified Diff: src/harmony-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: Apply same changes to MapForEach and SetForEach Created 6 years, 3 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
Index: src/harmony-array.js
diff --git a/src/harmony-array.js b/src/harmony-array.js
index 88b878f0a76ef594f64f7905d61459c05749724b..b27960ad94052fe38090be9b432ba856188dd9f5 100644
--- a/src/harmony-array.js
+++ b/src/harmony-array.js
@@ -28,14 +28,17 @@ function ArrayFind(predicate /* thisArg */) { // length == 1
if (IS_NULL_OR_UNDEFINED(thisArg)) {
thisArg = %GetDefaultReceiver(predicate) || thisArg;
- } else if (!IS_SPEC_OBJECT(thisArg) && %IsSloppyModeFunction(predicate)) {
- thisArg = ToObject(thisArg);
}
for (var i = 0; i < length; i++) {
if (i in array) {
var element = array[i];
- if (%_CallFunction(thisArg, element, i, array, predicate)) {
+ var new_thisArg = thisArg;
wingo 2014/09/15 09:12:21 Call it "receiver", or something that doesn't have
Diego Pino 2014/09/16 10:45:46 Acknowledged.
+ if (!IS_NULL_OR_UNDEFINED(thisArg) &&
+ !IS_SPEC_OBJECT(thisArg) && %IsSloppyModeFunction(predicate)) {
+ new_thisArg = ToObject(thisArg);
+ }
+ if (%_CallFunction(new_thisArg, element, i, array, predicate)) {
return element;
}
}
@@ -63,14 +66,17 @@ function ArrayFindIndex(predicate /* thisArg */) { // length == 1
if (IS_NULL_OR_UNDEFINED(thisArg)) {
thisArg = %GetDefaultReceiver(predicate) || thisArg;
- } else if (!IS_SPEC_OBJECT(thisArg) && %IsSloppyModeFunction(predicate)) {
- thisArg = ToObject(thisArg);
}
for (var i = 0; i < length; i++) {
if (i in array) {
+ var new_thisArg = thisArg;
+ if (!IS_NULL_OR_UNDEFINED(thisArg) &&
+ !IS_SPEC_OBJECT(thisArg) && %IsSloppyModeFunction(predicate)) {
+ new_thisArg = ToObject(thisArg);
+ }
var element = array[i];
- if (%_CallFunction(thisArg, element, i, array, predicate)) {
+ if (%_CallFunction(new_thisArg, element, i, array, predicate)) {
return i;
}
}

Powered by Google App Engine
This is Rietveld 408576698