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

Unified Diff: src/js/array.js

Issue 1686433003: Use a for-of loop in Array.from (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Use GetIterator Created 4 years, 10 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/array.js
diff --git a/src/js/array.js b/src/js/array.js
index da6e02ededdcd7bd79dc53ff04dfaa05040c5719..914abd85dcfba085f00a92ae46abc4ac6d77f6e1 100644
--- a/src/js/array.js
+++ b/src/js/array.js
@@ -1776,23 +1776,10 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
if (!IS_UNDEFINED(iterable)) {
result = %IsConstructor(this) ? new this() : [];
-
- var iterator = GetIterator(items, iterable);
-
k = 0;
- while (true) {
- var next = iterator.next();
-
- if (!IS_RECEIVER(next)) {
- throw MakeTypeError(kIteratorResultNotAnObject, next);
- }
- if (next.done) {
- result.length = k;
- return result;
- }
-
- nextValue = next.value;
+ for (nextValue of
+ { [iteratorSymbol]() { return GetIterator(items, iterable) } }) {
if (mapping) {
mappedValue = %_Call(mapfn, receiver, nextValue, k);
} else {
@@ -1801,6 +1788,8 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
AddArrayElement(this, result, k, mappedValue);
k++;
}
+ result.length = k;
+ return result;
} else {
var len = TO_LENGTH(items.length);
result = %IsConstructor(this) ? new this(len) : new GlobalArray(len);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698