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

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: Created wrapper. Added tests for strict mode. Fixed nits. 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..0fe6db63dc65c9a9185ed7031b253d1859e5a012 100644
--- a/src/harmony-array.js
+++ b/src/harmony-array.js
@@ -11,7 +11,7 @@
// -------------------------------------------------------------------
// ES6 draft 07-15-13, section 15.4.3.23
-function ArrayFind(predicate /* thisArg */) { // length == 1
+function ArrayFind(predicate /* receiver */) { // length == 1
wingo 2014/09/23 18:39:01 So in the last patch I wanted to avoid new_thisArg
Diego Pino 2014/09/24 10:13:01 OK, understood. It's worth noticing that array fu
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find");
var array = ToObject(this);
@@ -21,21 +21,21 @@ function ArrayFind(predicate /* thisArg */) { // length == 1
throw MakeTypeError('called_non_callable', [predicate]);
}
- var thisArg;
+ var receiver;
if (%_ArgumentsLength() > 1) {
- thisArg = %_Arguments(1);
+ receiver = %_Arguments(1);
}
- if (IS_NULL_OR_UNDEFINED(thisArg)) {
- thisArg = %GetDefaultReceiver(predicate) || thisArg;
- } else if (!IS_SPEC_OBJECT(thisArg) && %IsSloppyModeFunction(predicate)) {
- thisArg = ToObject(thisArg);
+ if (IS_NULL_OR_UNDEFINED(receiver)) {
+ receiver = %GetDefaultReceiver(predicate) || receiver;
}
+ var needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, receiver);
for (var i = 0; i < length; i++) {
if (i in array) {
var element = array[i];
- if (%_CallFunction(thisArg, element, i, array, predicate)) {
+ var new_receiver = needs_wrapper ? ToObject(receiver) : receiver;
+ if (%_CallFunction(new_receiver, element, i, array, predicate)) {
return element;
}
}
@@ -46,7 +46,7 @@ function ArrayFind(predicate /* thisArg */) { // length == 1
// ES6 draft 07-15-13, section 15.4.3.24
-function ArrayFindIndex(predicate /* thisArg */) { // length == 1
+function ArrayFindIndex(predicate /* receiver */) { // length == 1
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex");
var array = ToObject(this);
@@ -56,21 +56,21 @@ function ArrayFindIndex(predicate /* thisArg */) { // length == 1
throw MakeTypeError('called_non_callable', [predicate]);
}
- var thisArg;
+ var receiver;
if (%_ArgumentsLength() > 1) {
- thisArg = %_Arguments(1);
+ receiver = %_Arguments(1);
}
- if (IS_NULL_OR_UNDEFINED(thisArg)) {
- thisArg = %GetDefaultReceiver(predicate) || thisArg;
- } else if (!IS_SPEC_OBJECT(thisArg) && %IsSloppyModeFunction(predicate)) {
- thisArg = ToObject(thisArg);
+ if (IS_NULL_OR_UNDEFINED(receiver)) {
+ receiver = %GetDefaultReceiver(predicate) || receiver;
}
+ var needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, receiver);
for (var i = 0; i < length; i++) {
if (i in array) {
var element = array[i];
- if (%_CallFunction(thisArg, element, i, array, predicate)) {
+ var new_receiver = needs_wrapper ? ToObject(receiver) : receiver;
+ if (%_CallFunction(new_receiver, element, i, array, predicate)) {
return i;
}
}

Powered by Google App Engine
This is Rietveld 408576698