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

Side by Side Diff: src/string-iterator.js

Issue 1293493004: Unify symbols sharing across native scripts and runtime. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 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
« src/heap/heap.h ('K') | « src/runtime/runtime-symbol.cc ('k') | 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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var ArrayIteratorCreateResultObject;
14 var GlobalString = global.String; 15 var GlobalString = global.String;
15 16 var StringIteratorIteratedStringSymbol =
16 var ArrayIteratorCreateResultObject; 17 utils.GetPrivateSymbol("string_iterator_iterated_string_symbol");
18 var StringIteratorNextIndexSymbol =
19 utils.GetPrivateSymbol("string_iterator_next_index_symbol");
17 20
18 utils.Import(function(from) { 21 utils.Import(function(from) {
19 ArrayIteratorCreateResultObject = from.ArrayIteratorCreateResultObject; 22 ArrayIteratorCreateResultObject = from.ArrayIteratorCreateResultObject;
20 }); 23 });
21 24
22 // ------------------------------------------------------------------- 25 // -------------------------------------------------------------------
23 26
24 var stringIteratorIteratedStringSymbol =
25 GLOBAL_PRIVATE("StringIterator#iteratedString");
26 var stringIteratorNextIndexSymbol = GLOBAL_PRIVATE("StringIterator#next");
27
28
29 function StringIterator() {} 27 function StringIterator() {}
30 28
31 29
32 // 21.1.5.1 CreateStringIterator Abstract Operation 30 // 21.1.5.1 CreateStringIterator Abstract Operation
33 function CreateStringIterator(string) { 31 function CreateStringIterator(string) {
34 var s = TO_STRING_INLINE(string); 32 var s = TO_STRING_INLINE(string);
35 var iterator = new StringIterator; 33 var iterator = new StringIterator;
36 SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol, s); 34 SET_PRIVATE(iterator, StringIteratorIteratedStringSymbol, s);
37 SET_PRIVATE(iterator, stringIteratorNextIndexSymbol, 0); 35 SET_PRIVATE(iterator, StringIteratorNextIndexSymbol, 0);
38 return iterator; 36 return iterator;
39 } 37 }
40 38
41 39
42 // 21.1.5.2.1 %StringIteratorPrototype%.next( ) 40 // 21.1.5.2.1 %StringIteratorPrototype%.next( )
43 function StringIteratorNext() { 41 function StringIteratorNext() {
44 var iterator = TO_OBJECT(this); 42 var iterator = TO_OBJECT(this);
45 43
46 if (!HAS_DEFINED_PRIVATE(iterator, stringIteratorNextIndexSymbol)) { 44 if (!HAS_DEFINED_PRIVATE(iterator, StringIteratorNextIndexSymbol)) {
47 throw MakeTypeError(kIncompatibleMethodReceiver, 45 throw MakeTypeError(kIncompatibleMethodReceiver,
48 'String Iterator.prototype.next'); 46 'String Iterator.prototype.next');
49 } 47 }
50 48
51 var s = GET_PRIVATE(iterator, stringIteratorIteratedStringSymbol); 49 var s = GET_PRIVATE(iterator, StringIteratorIteratedStringSymbol);
52 if (IS_UNDEFINED(s)) { 50 if (IS_UNDEFINED(s)) {
53 return ArrayIteratorCreateResultObject(UNDEFINED, true); 51 return ArrayIteratorCreateResultObject(UNDEFINED, true);
54 } 52 }
55 53
56 var position = GET_PRIVATE(iterator, stringIteratorNextIndexSymbol); 54 var position = GET_PRIVATE(iterator, StringIteratorNextIndexSymbol);
57 var length = TO_UINT32(s.length); 55 var length = TO_UINT32(s.length);
58 56
59 if (position >= length) { 57 if (position >= length) {
60 SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol, 58 SET_PRIVATE(iterator, StringIteratorIteratedStringSymbol,
61 UNDEFINED); 59 UNDEFINED);
62 return ArrayIteratorCreateResultObject(UNDEFINED, true); 60 return ArrayIteratorCreateResultObject(UNDEFINED, true);
63 } 61 }
64 62
65 var first = %_StringCharCodeAt(s, position); 63 var first = %_StringCharCodeAt(s, position);
66 var resultString = %_StringCharFromCode(first); 64 var resultString = %_StringCharFromCode(first);
67 position++; 65 position++;
68 66
69 if (first >= 0xD800 && first <= 0xDBFF && position < length) { 67 if (first >= 0xD800 && first <= 0xDBFF && position < length) {
70 var second = %_StringCharCodeAt(s, position); 68 var second = %_StringCharCodeAt(s, position);
71 if (second >= 0xDC00 && second <= 0xDFFF) { 69 if (second >= 0xDC00 && second <= 0xDFFF) {
72 resultString += %_StringCharFromCode(second); 70 resultString += %_StringCharFromCode(second);
73 position++; 71 position++;
74 } 72 }
75 } 73 }
76 74
77 SET_PRIVATE(iterator, stringIteratorNextIndexSymbol, position); 75 SET_PRIVATE(iterator, StringIteratorNextIndexSymbol, position);
78 76
79 return ArrayIteratorCreateResultObject(resultString, false); 77 return ArrayIteratorCreateResultObject(resultString, false);
80 } 78 }
81 79
82 80
83 // 21.1.3.27 String.prototype [ @@iterator ]( ) 81 // 21.1.3.27 String.prototype [ @@iterator ]( )
84 function StringPrototypeIterator() { 82 function StringPrototypeIterator() {
85 return CreateStringIterator(this); 83 return CreateStringIterator(this);
86 } 84 }
87 85
88 //------------------------------------------------------------------- 86 //-------------------------------------------------------------------
89 87
90 %FunctionSetPrototype(StringIterator, {__proto__: $iteratorPrototype}); 88 %FunctionSetPrototype(StringIterator, {__proto__: $iteratorPrototype});
91 %FunctionSetInstanceClassName(StringIterator, 'String Iterator'); 89 %FunctionSetInstanceClassName(StringIterator, 'String Iterator');
92 90
93 utils.InstallFunctions(StringIterator.prototype, DONT_ENUM, [ 91 utils.InstallFunctions(StringIterator.prototype, DONT_ENUM, [
94 'next', StringIteratorNext 92 'next', StringIteratorNext
95 ]); 93 ]);
96 %AddNamedProperty(StringIterator.prototype, symbolToStringTag, 94 %AddNamedProperty(StringIterator.prototype, symbolToStringTag,
97 "String Iterator", READ_ONLY | DONT_ENUM); 95 "String Iterator", READ_ONLY | DONT_ENUM);
98 96
99 utils.SetFunctionName(StringPrototypeIterator, symbolIterator); 97 utils.SetFunctionName(StringPrototypeIterator, symbolIterator);
100 %AddNamedProperty(GlobalString.prototype, symbolIterator, 98 %AddNamedProperty(GlobalString.prototype, symbolIterator,
101 StringPrototypeIterator, DONT_ENUM); 99 StringPrototypeIterator, DONT_ENUM);
102 100
103 }) 101 })
OLDNEW
« src/heap/heap.h ('K') | « src/runtime/runtime-symbol.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698