diff options
Diffstat (limited to 'deps/v8/src/array.js')
-rw-r--r-- | deps/v8/src/array.js | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/deps/v8/src/array.js b/deps/v8/src/array.js index e1d7c2064e..214065c7bf 100644 --- a/deps/v8/src/array.js +++ b/deps/v8/src/array.js @@ -1013,18 +1013,22 @@ function ArrayFilter(f, receiver) { } if (IS_NULL_OR_UNDEFINED(receiver)) { receiver = %GetDefaultReceiver(f) || receiver; + } else if (!IS_SPEC_OBJECT(receiver)) { + receiver = ToObject(receiver); } - var result = []; - var result_length = 0; + var result = new $Array(); + var accumulator = new InternalArray(); + var accumulator_length = 0; for (var i = 0; i < length; i++) { var current = array[i]; if (!IS_UNDEFINED(current) || i in array) { if (%_CallFunction(receiver, current, i, array, f)) { - result[result_length++] = current; + accumulator[accumulator_length++] = current; } } } + %MoveArrayContents(accumulator, result); return result; } @@ -1045,6 +1049,8 @@ function ArrayForEach(f, receiver) { } if (IS_NULL_OR_UNDEFINED(receiver)) { receiver = %GetDefaultReceiver(f) || receiver; + } else if (!IS_SPEC_OBJECT(receiver)) { + receiver = ToObject(receiver); } for (var i = 0; i < length; i++) { @@ -1074,6 +1080,8 @@ function ArraySome(f, receiver) { } if (IS_NULL_OR_UNDEFINED(receiver)) { receiver = %GetDefaultReceiver(f) || receiver; + } else if (!IS_SPEC_OBJECT(receiver)) { + receiver = ToObject(receiver); } for (var i = 0; i < length; i++) { @@ -1102,6 +1110,8 @@ function ArrayEvery(f, receiver) { } if (IS_NULL_OR_UNDEFINED(receiver)) { receiver = %GetDefaultReceiver(f) || receiver; + } else if (!IS_SPEC_OBJECT(receiver)) { + receiver = ToObject(receiver); } for (var i = 0; i < length; i++) { @@ -1129,6 +1139,8 @@ function ArrayMap(f, receiver) { } if (IS_NULL_OR_UNDEFINED(receiver)) { receiver = %GetDefaultReceiver(f) || receiver; + } else if (!IS_SPEC_OBJECT(receiver)) { + receiver = ToObject(receiver); } var result = new $Array(); |