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; |
} |
} |