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

Unified Diff: src/array-iterator.js

Issue 1302173007: [es6] Introduce a dedicated JSIteratorResult type. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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/bootstrapper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/array-iterator.js
diff --git a/src/array-iterator.js b/src/array-iterator.js
index 762714e0e377233b65412b54dc02002735e0732a..bf17a0ac8c8890e58908e2c918c34c821a5bb485 100644
--- a/src/array-iterator.js
+++ b/src/array-iterator.js
@@ -62,21 +62,17 @@ function CreateArrayIterator(array, kind) {
}
-// 15.19.4.3.4 CreateItrResultObject
-function CreateIteratorResultObject(value, done) {
- return {value: value, done: done};
-}
-
-
// 22.1.5.2.2 %ArrayIteratorPrototype%[@@iterator]
function ArrayIteratorIterator() {
return this;
}
-// 15.4.5.2.2 ArrayIterator.prototype.next( )
+// ES6 section 22.1.5.2.1 %ArrayIteratorPrototype%.next( )
function ArrayIteratorNext() {
var iterator = this;
+ var value = UNDEFINED;
+ var done = true;
if (!IS_SPEC_OBJECT(iterator) ||
!HAS_DEFINED_PRIVATE(iterator, arrayIteratorNextIndexSymbol)) {
@@ -85,32 +81,30 @@ function ArrayIteratorNext() {
}
var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol);
- if (IS_UNDEFINED(array)) {
- return CreateIteratorResultObject(UNDEFINED, true);
- }
-
- var index = GET_PRIVATE(iterator, arrayIteratorNextIndexSymbol);
- var itemKind = GET_PRIVATE(iterator, arrayIterationKindSymbol);
- var length = TO_UINT32(array.length);
-
- // "sparse" is never used.
-
- if (index >= length) {
- SET_PRIVATE(iterator, arrayIteratorObjectSymbol, UNDEFINED);
- return CreateIteratorResultObject(UNDEFINED, true);
+ if (!IS_UNDEFINED(array)) {
+ var index = GET_PRIVATE(iterator, arrayIteratorNextIndexSymbol);
+ var itemKind = GET_PRIVATE(iterator, arrayIterationKindSymbol);
+ var length = TO_UINT32(array.length);
+
+ // "sparse" is never used.
+
+ if (index >= length) {
+ SET_PRIVATE(iterator, arrayIteratorObjectSymbol, UNDEFINED);
+ } else {
+ SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, index + 1);
+
+ if (itemKind == ITERATOR_KIND_VALUES) {
+ value = array[index];
+ } else if (itemKind == ITERATOR_KIND_ENTRIES) {
+ value = [index, array[index]];
+ } else {
+ value = index;
+ }
+ done = false;
+ }
}
- SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, index + 1);
-
- if (itemKind == ITERATOR_KIND_VALUES) {
- return CreateIteratorResultObject(array[index], false);
- }
-
- if (itemKind == ITERATOR_KIND_ENTRIES) {
- return CreateIteratorResultObject([index, array[index]], false);
- }
-
- return CreateIteratorResultObject(index, false);
+ return %_CreateIterResultObject(value, done);
}
@@ -167,10 +161,6 @@ TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
// -------------------------------------------------------------------
// Exports
-utils.Export(function(to) {
- to.ArrayIteratorCreateResultObject = CreateIteratorResultObject;
-});
-
$arrayValues = ArrayValues;
%InstallToContext(["array_values_iterator", ArrayValues]);
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698