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

Unified Diff: src/harmony-array.js

Issue 856303002: Don't take iterable path in ArrayFrom if items[@@iterator] is null (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cleanup test Created 5 years, 11 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/v8natives.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-array.js
diff --git a/src/harmony-array.js b/src/harmony-array.js
index 762f746e56d923f1330ac177fa41403a331c18c8..72625a57f55423d93c72f8f9d674dc8416df9dd5 100644
--- a/src/harmony-array.js
+++ b/src/harmony-array.js
@@ -142,7 +142,7 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
}
}
- var iterable = ToIterable(items);
+ var iterable = GetMethod(items, symbolIterator);
var k;
var result;
var mappedValue;
@@ -151,23 +151,40 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
if (!IS_UNDEFINED(iterable)) {
result = %IsConstructor(this) ? new this() : [];
+ var iterator = GetIterator(items, iterable);
+
k = 0;
- for (nextValue of items) {
- if (mapping) mappedValue = %_CallFunction(receiver, nextValue, k, mapfn);
- else mappedValue = nextValue;
+ while (true) {
+ var next = iterator.next();
+
+ if (!IS_OBJECT(next)) {
+ throw MakeTypeError("iterator_result_not_an_object", [next]);
+ }
+
+ if (next.done) {
+ result.length = k;
+ return result;
+ }
+
+ nextValue = next.value;
+ if (mapping) {
+ mappedValue = %_CallFunction(receiver, nextValue, k, mapfn);
+ } else {
+ mappedValue = nextValue;
+ }
%AddElement(result, k++, mappedValue, NONE);
}
-
- result.length = k;
- return result;
} else {
var len = ToLength(items.length);
result = %IsConstructor(this) ? new this(len) : new $Array(len);
for (k = 0; k < len; ++k) {
nextValue = items[k];
- if (mapping) mappedValue = %_CallFunction(receiver, nextValue, k, mapfn);
- else mappedValue = nextValue;
+ if (mapping) {
+ mappedValue = %_CallFunction(receiver, nextValue, k, mapfn);
+ } else {
+ mappedValue = nextValue;
+ }
%AddElement(result, k, mappedValue, NONE);
}
« no previous file with comments | « no previous file | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698