OLD | NEW |
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 // ------------------------------------------------------------------- |
| 12 // Imports |
| 13 |
11 var GlobalString = global.String; | 14 var GlobalString = global.String; |
12 | 15 |
13 //------------------------------------------------------------------- | 16 var ArrayIteratorCreateResultObject; |
| 17 |
| 18 utils.Import(function(from) { |
| 19 ArrayIteratorCreateResultObject = from.ArrayIteratorCreateResultObject; |
| 20 }); |
| 21 |
| 22 // ------------------------------------------------------------------- |
14 | 23 |
15 var stringIteratorIteratedStringSymbol = | 24 var stringIteratorIteratedStringSymbol = |
16 GLOBAL_PRIVATE("StringIterator#iteratedString"); | 25 GLOBAL_PRIVATE("StringIterator#iteratedString"); |
17 var stringIteratorNextIndexSymbol = GLOBAL_PRIVATE("StringIterator#next"); | 26 var stringIteratorNextIndexSymbol = GLOBAL_PRIVATE("StringIterator#next"); |
18 | 27 |
19 | 28 |
20 function StringIterator() {} | 29 function StringIterator() {} |
21 | 30 |
22 | 31 |
23 // 21.1.5.1 CreateStringIterator Abstract Operation | 32 // 21.1.5.1 CreateStringIterator Abstract Operation |
(...skipping 10 matching lines...) Expand all Loading... |
34 function StringIteratorNext() { | 43 function StringIteratorNext() { |
35 var iterator = $toObject(this); | 44 var iterator = $toObject(this); |
36 | 45 |
37 if (!HAS_DEFINED_PRIVATE(iterator, stringIteratorNextIndexSymbol)) { | 46 if (!HAS_DEFINED_PRIVATE(iterator, stringIteratorNextIndexSymbol)) { |
38 throw MakeTypeError(kIncompatibleMethodReceiver, | 47 throw MakeTypeError(kIncompatibleMethodReceiver, |
39 'String Iterator.prototype.next'); | 48 'String Iterator.prototype.next'); |
40 } | 49 } |
41 | 50 |
42 var s = GET_PRIVATE(iterator, stringIteratorIteratedStringSymbol); | 51 var s = GET_PRIVATE(iterator, stringIteratorIteratedStringSymbol); |
43 if (IS_UNDEFINED(s)) { | 52 if (IS_UNDEFINED(s)) { |
44 return $iteratorCreateResultObject(UNDEFINED, true); | 53 return ArrayIteratorCreateResultObject(UNDEFINED, true); |
45 } | 54 } |
46 | 55 |
47 var position = GET_PRIVATE(iterator, stringIteratorNextIndexSymbol); | 56 var position = GET_PRIVATE(iterator, stringIteratorNextIndexSymbol); |
48 var length = TO_UINT32(s.length); | 57 var length = TO_UINT32(s.length); |
49 | 58 |
50 if (position >= length) { | 59 if (position >= length) { |
51 SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol, | 60 SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol, |
52 UNDEFINED); | 61 UNDEFINED); |
53 return $iteratorCreateResultObject(UNDEFINED, true); | 62 return ArrayIteratorCreateResultObject(UNDEFINED, true); |
54 } | 63 } |
55 | 64 |
56 var first = %_StringCharCodeAt(s, position); | 65 var first = %_StringCharCodeAt(s, position); |
57 var resultString = %_StringCharFromCode(first); | 66 var resultString = %_StringCharFromCode(first); |
58 position++; | 67 position++; |
59 | 68 |
60 if (first >= 0xD800 && first <= 0xDBFF && position < length) { | 69 if (first >= 0xD800 && first <= 0xDBFF && position < length) { |
61 var second = %_StringCharCodeAt(s, position); | 70 var second = %_StringCharCodeAt(s, position); |
62 if (second >= 0xDC00 && second <= 0xDFFF) { | 71 if (second >= 0xDC00 && second <= 0xDFFF) { |
63 resultString += %_StringCharFromCode(second); | 72 resultString += %_StringCharFromCode(second); |
64 position++; | 73 position++; |
65 } | 74 } |
66 } | 75 } |
67 | 76 |
68 SET_PRIVATE(iterator, stringIteratorNextIndexSymbol, position); | 77 SET_PRIVATE(iterator, stringIteratorNextIndexSymbol, position); |
69 | 78 |
70 return $iteratorCreateResultObject(resultString, false); | 79 return ArrayIteratorCreateResultObject(resultString, false); |
71 } | 80 } |
72 | 81 |
73 | 82 |
74 // 21.1.3.27 String.prototype [ @@iterator ]( ) | 83 // 21.1.3.27 String.prototype [ @@iterator ]( ) |
75 function StringPrototypeIterator() { | 84 function StringPrototypeIterator() { |
76 return CreateStringIterator(this); | 85 return CreateStringIterator(this); |
77 } | 86 } |
78 | 87 |
79 //------------------------------------------------------------------- | 88 //------------------------------------------------------------------- |
80 | 89 |
81 %FunctionSetPrototype(StringIterator, {__proto__: $iteratorPrototype}); | 90 %FunctionSetPrototype(StringIterator, {__proto__: $iteratorPrototype}); |
82 %FunctionSetInstanceClassName(StringIterator, 'String Iterator'); | 91 %FunctionSetInstanceClassName(StringIterator, 'String Iterator'); |
83 | 92 |
84 $installFunctions(StringIterator.prototype, DONT_ENUM, [ | 93 utils.InstallFunctions(StringIterator.prototype, DONT_ENUM, [ |
85 'next', StringIteratorNext | 94 'next', StringIteratorNext |
86 ]); | 95 ]); |
87 %AddNamedProperty(StringIterator.prototype, symbolToStringTag, | 96 %AddNamedProperty(StringIterator.prototype, symbolToStringTag, |
88 "String Iterator", READ_ONLY | DONT_ENUM); | 97 "String Iterator", READ_ONLY | DONT_ENUM); |
89 | 98 |
90 $setFunctionName(StringPrototypeIterator, symbolIterator); | 99 utils.SetFunctionName(StringPrototypeIterator, symbolIterator); |
91 %AddNamedProperty(GlobalString.prototype, symbolIterator, | 100 %AddNamedProperty(GlobalString.prototype, symbolIterator, |
92 StringPrototypeIterator, DONT_ENUM); | 101 StringPrototypeIterator, DONT_ENUM); |
93 | 102 |
94 }) | 103 }) |
OLD | NEW |