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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils, extrasUtils) { 5 (function(global, utils, extrasUtils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 } 1769 }
1770 1770
1771 var iterable = GetMethod(items, iteratorSymbol); 1771 var iterable = GetMethod(items, iteratorSymbol);
1772 var k; 1772 var k;
1773 var result; 1773 var result;
1774 var mappedValue; 1774 var mappedValue;
1775 var nextValue; 1775 var nextValue;
1776 1776
1777 if (!IS_UNDEFINED(iterable)) { 1777 if (!IS_UNDEFINED(iterable)) {
1778 result = %IsConstructor(this) ? new this() : []; 1778 result = %IsConstructor(this) ? new this() : [];
1779 k = 0;
1779 1780
1780 var iterator = GetIterator(items, iterable); 1781 for (nextValue of
1781 1782 { [iteratorSymbol]() { return GetIterator(items, iterable) } }) {
1782 k = 0;
1783 while (true) {
1784 var next = iterator.next();
1785
1786 if (!IS_RECEIVER(next)) {
1787 throw MakeTypeError(kIteratorResultNotAnObject, next);
1788 }
1789
1790 if (next.done) {
1791 result.length = k;
1792 return result;
1793 }
1794
1795 nextValue = next.value;
1796 if (mapping) { 1783 if (mapping) {
1797 mappedValue = %_Call(mapfn, receiver, nextValue, k); 1784 mappedValue = %_Call(mapfn, receiver, nextValue, k);
1798 } else { 1785 } else {
1799 mappedValue = nextValue; 1786 mappedValue = nextValue;
1800 } 1787 }
1801 AddArrayElement(this, result, k, mappedValue); 1788 AddArrayElement(this, result, k, mappedValue);
1802 k++; 1789 k++;
1803 } 1790 }
1791 result.length = k;
1792 return result;
1804 } else { 1793 } else {
1805 var len = TO_LENGTH(items.length); 1794 var len = TO_LENGTH(items.length);
1806 result = %IsConstructor(this) ? new this(len) : new GlobalArray(len); 1795 result = %IsConstructor(this) ? new this(len) : new GlobalArray(len);
1807 1796
1808 for (k = 0; k < len; ++k) { 1797 for (k = 0; k < len; ++k) {
1809 nextValue = items[k]; 1798 nextValue = items[k];
1810 if (mapping) { 1799 if (mapping) {
1811 mappedValue = %_Call(mapfn, receiver, nextValue, k); 1800 mappedValue = %_Call(mapfn, receiver, nextValue, k);
1812 } else { 1801 } else {
1813 mappedValue = nextValue; 1802 mappedValue = nextValue;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 %InstallToContext([ 1961 %InstallToContext([
1973 "array_pop", ArrayPop, 1962 "array_pop", ArrayPop,
1974 "array_push", ArrayPush, 1963 "array_push", ArrayPush,
1975 "array_shift", ArrayShift, 1964 "array_shift", ArrayShift,
1976 "array_splice", ArraySplice, 1965 "array_splice", ArraySplice,
1977 "array_slice", ArraySlice, 1966 "array_slice", ArraySlice,
1978 "array_unshift", ArrayUnshift, 1967 "array_unshift", ArrayUnshift,
1979 ]); 1968 ]);
1980 1969
1981 }); 1970 });
OLDNEW
« 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