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 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
12 // Imports | 12 // Imports |
13 | 13 |
14 var GlobalString = global.String; | 14 var GlobalString = global.String; |
15 var IteratorPrototype = utils.ImportNow("IteratorPrototype"); | 15 var IteratorPrototype = utils.ImportNow("IteratorPrototype"); |
16 var iteratorSymbol = utils.ImportNow("iterator_symbol"); | 16 var iteratorSymbol = utils.ImportNow("iterator_symbol"); |
17 var MakeTypeError; | |
18 var stringIteratorIteratedStringSymbol = | 17 var stringIteratorIteratedStringSymbol = |
19 utils.ImportNow("string_iterator_iterated_string_symbol"); | 18 utils.ImportNow("string_iterator_iterated_string_symbol"); |
20 var stringIteratorNextIndexSymbol = | 19 var stringIteratorNextIndexSymbol = |
21 utils.ImportNow("string_iterator_next_index_symbol"); | 20 utils.ImportNow("string_iterator_next_index_symbol"); |
22 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 21 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
23 | 22 |
24 utils.Import(function(from) { | |
25 MakeTypeError = from.MakeTypeError; | |
26 }); | |
27 | |
28 // ------------------------------------------------------------------- | 23 // ------------------------------------------------------------------- |
29 | 24 |
30 function StringIterator() {} | 25 function StringIterator() {} |
31 | 26 |
32 | 27 |
33 // 21.1.5.1 CreateStringIterator Abstract Operation | 28 // 21.1.5.1 CreateStringIterator Abstract Operation |
34 function CreateStringIterator(string) { | 29 function CreateStringIterator(string) { |
35 CHECK_OBJECT_COERCIBLE(string, 'String.prototype[Symbol.iterator]'); | 30 CHECK_OBJECT_COERCIBLE(string, 'String.prototype[Symbol.iterator]'); |
36 var s = TO_STRING(string); | 31 var s = TO_STRING(string); |
37 var iterator = new StringIterator; | 32 var iterator = new StringIterator; |
38 SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol, s); | 33 SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol, s); |
39 SET_PRIVATE(iterator, stringIteratorNextIndexSymbol, 0); | 34 SET_PRIVATE(iterator, stringIteratorNextIndexSymbol, 0); |
40 return iterator; | 35 return iterator; |
41 } | 36 } |
42 | 37 |
43 | 38 |
44 // ES6 section 21.1.5.2.1 %StringIteratorPrototype%.next ( ) | 39 // ES6 section 21.1.5.2.1 %StringIteratorPrototype%.next ( ) |
45 function StringIteratorNext() { | 40 function StringIteratorNext() { |
46 var iterator = this; | 41 var iterator = this; |
47 var value = UNDEFINED; | 42 var value = UNDEFINED; |
48 var done = true; | 43 var done = true; |
49 | 44 |
50 if (!IS_RECEIVER(iterator) || | 45 if (!IS_RECEIVER(iterator) || |
51 !HAS_DEFINED_PRIVATE(iterator, stringIteratorNextIndexSymbol)) { | 46 !HAS_DEFINED_PRIVATE(iterator, stringIteratorNextIndexSymbol)) { |
52 throw MakeTypeError(kIncompatibleMethodReceiver, | 47 throw %make_type_error(kIncompatibleMethodReceiver, |
53 'String Iterator.prototype.next'); | 48 'String Iterator.prototype.next'); |
54 } | 49 } |
55 | 50 |
56 var s = GET_PRIVATE(iterator, stringIteratorIteratedStringSymbol); | 51 var s = GET_PRIVATE(iterator, stringIteratorIteratedStringSymbol); |
57 if (!IS_UNDEFINED(s)) { | 52 if (!IS_UNDEFINED(s)) { |
58 var position = GET_PRIVATE(iterator, stringIteratorNextIndexSymbol); | 53 var position = GET_PRIVATE(iterator, stringIteratorNextIndexSymbol); |
59 var length = TO_UINT32(s.length); | 54 var length = TO_UINT32(s.length); |
60 if (position >= length) { | 55 if (position >= length) { |
61 SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol, UNDEFINED); | 56 SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol, UNDEFINED); |
62 } else { | 57 } else { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 'next', StringIteratorNext | 89 'next', StringIteratorNext |
95 ]); | 90 ]); |
96 %AddNamedProperty(StringIterator.prototype, toStringTagSymbol, | 91 %AddNamedProperty(StringIterator.prototype, toStringTagSymbol, |
97 "String Iterator", READ_ONLY | DONT_ENUM); | 92 "String Iterator", READ_ONLY | DONT_ENUM); |
98 | 93 |
99 utils.SetFunctionName(StringPrototypeIterator, iteratorSymbol); | 94 utils.SetFunctionName(StringPrototypeIterator, iteratorSymbol); |
100 %AddNamedProperty(GlobalString.prototype, iteratorSymbol, | 95 %AddNamedProperty(GlobalString.prototype, iteratorSymbol, |
101 StringPrototypeIterator, DONT_ENUM); | 96 StringPrototypeIterator, DONT_ENUM); |
102 | 97 |
103 }) | 98 }) |
OLD | NEW |