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

Unified Diff: src/string-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 | « src/runtime/runtime-object.cc ('k') | src/x64/macro-assembler-x64.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/string-iterator.js
diff --git a/src/string-iterator.js b/src/string-iterator.js
index 42ddb2391f7470c437df49e6caf577272d8b70b3..d63775748c239753f161c7830e216429e630dd24 100644
--- a/src/string-iterator.js
+++ b/src/string-iterator.js
@@ -11,7 +11,6 @@
// -------------------------------------------------------------------
// Imports
-var ArrayIteratorCreateResultObject;
var GlobalString = global.String;
var iteratorSymbol = utils.ImportNow("iterator_symbol");
var stringIteratorIteratedStringSymbol =
@@ -20,10 +19,6 @@ var stringIteratorNextIndexSymbol =
utils.ImportNow("string_iterator_next_index_symbol");
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
-utils.Import(function(from) {
- ArrayIteratorCreateResultObject = from.ArrayIteratorCreateResultObject;
-});
-
// -------------------------------------------------------------------
function StringIterator() {}
@@ -39,9 +34,11 @@ function CreateStringIterator(string) {
}
-// 21.1.5.2.1 %StringIteratorPrototype%.next( )
+// ES6 section 21.1.5.2.1 %StringIteratorPrototype%.next ( )
function StringIteratorNext() {
var iterator = this;
+ var value = UNDEFINED;
+ var done = true;
if (!IS_SPEC_OBJECT(iterator) ||
!HAS_DEFINED_PRIVATE(iterator, stringIteratorNextIndexSymbol)) {
@@ -50,34 +47,29 @@ function StringIteratorNext() {
}
var s = GET_PRIVATE(iterator, stringIteratorIteratedStringSymbol);
- if (IS_UNDEFINED(s)) {
- return ArrayIteratorCreateResultObject(UNDEFINED, true);
- }
-
- var position = GET_PRIVATE(iterator, stringIteratorNextIndexSymbol);
- var length = TO_UINT32(s.length);
-
- if (position >= length) {
- SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol,
- UNDEFINED);
- return ArrayIteratorCreateResultObject(UNDEFINED, true);
- }
+ if (!IS_UNDEFINED(s)) {
+ var position = GET_PRIVATE(iterator, stringIteratorNextIndexSymbol);
+ var length = TO_UINT32(s.length);
+ if (position >= length) {
+ SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol, UNDEFINED);
+ } else {
+ var first = %_StringCharCodeAt(s, position);
+ value = %_StringCharFromCode(first);
+ done = false;
+ position++;
- var first = %_StringCharCodeAt(s, position);
- var resultString = %_StringCharFromCode(first);
- position++;
+ if (first >= 0xD800 && first <= 0xDBFF && position < length) {
+ var second = %_StringCharCodeAt(s, position);
+ if (second >= 0xDC00 && second <= 0xDFFF) {
+ value += %_StringCharFromCode(second);
+ position++;
+ }
+ }
- if (first >= 0xD800 && first <= 0xDBFF && position < length) {
- var second = %_StringCharCodeAt(s, position);
- if (second >= 0xDC00 && second <= 0xDFFF) {
- resultString += %_StringCharFromCode(second);
- position++;
+ SET_PRIVATE(iterator, stringIteratorNextIndexSymbol, position);
}
}
-
- SET_PRIVATE(iterator, stringIteratorNextIndexSymbol, position);
-
- return ArrayIteratorCreateResultObject(resultString, false);
+ return %_CreateIterResultObject(value, done);
}
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | src/x64/macro-assembler-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698