| 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, shared, exports) { | 5 (function(global, shared, exports) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| 11 var GlobalObject = global.Object; | |
| 12 var GlobalString = global.String; | 11 var GlobalString = global.String; |
| 13 | 12 |
| 14 //------------------------------------------------------------------- | 13 //------------------------------------------------------------------- |
| 15 | 14 |
| 16 var stringIteratorIteratedStringSymbol = | 15 var stringIteratorIteratedStringSymbol = |
| 17 GLOBAL_PRIVATE("StringIterator#iteratedString"); | 16 GLOBAL_PRIVATE("StringIterator#iteratedString"); |
| 18 var stringIteratorNextIndexSymbol = GLOBAL_PRIVATE("StringIterator#next"); | 17 var stringIteratorNextIndexSymbol = GLOBAL_PRIVATE("StringIterator#next"); |
| 19 | 18 |
| 20 | 19 |
| 21 function StringIterator() {} | 20 function StringIterator() {} |
| 22 | 21 |
| 23 | 22 |
| 24 // 21.1.5.1 CreateStringIterator Abstract Operation | 23 // 21.1.5.1 CreateStringIterator Abstract Operation |
| 25 function CreateStringIterator(string) { | 24 function CreateStringIterator(string) { |
| 26 var s = TO_STRING_INLINE(string); | 25 var s = TO_STRING_INLINE(string); |
| 27 var iterator = new StringIterator; | 26 var iterator = new StringIterator; |
| 28 SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol, s); | 27 SET_PRIVATE(iterator, stringIteratorIteratedStringSymbol, s); |
| 29 SET_PRIVATE(iterator, stringIteratorNextIndexSymbol, 0); | 28 SET_PRIVATE(iterator, stringIteratorNextIndexSymbol, 0); |
| 30 return iterator; | 29 return iterator; |
| 31 } | 30 } |
| 32 | 31 |
| 33 | 32 |
| 34 // 21.1.5.2.2 %StringIteratorPrototype%[@@iterator] | |
| 35 function StringIteratorIterator() { | |
| 36 return this; | |
| 37 } | |
| 38 | |
| 39 | |
| 40 // 21.1.5.2.1 %StringIteratorPrototype%.next( ) | 33 // 21.1.5.2.1 %StringIteratorPrototype%.next( ) |
| 41 function StringIteratorNext() { | 34 function StringIteratorNext() { |
| 42 var iterator = $toObject(this); | 35 var iterator = $toObject(this); |
| 43 | 36 |
| 44 if (!HAS_DEFINED_PRIVATE(iterator, stringIteratorNextIndexSymbol)) { | 37 if (!HAS_DEFINED_PRIVATE(iterator, stringIteratorNextIndexSymbol)) { |
| 45 throw MakeTypeError(kIncompatibleMethodReceiver, | 38 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 46 'String Iterator.prototype.next'); | 39 'String Iterator.prototype.next'); |
| 47 } | 40 } |
| 48 | 41 |
| 49 var s = GET_PRIVATE(iterator, stringIteratorIteratedStringSymbol); | 42 var s = GET_PRIVATE(iterator, stringIteratorIteratedStringSymbol); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 78 } | 71 } |
| 79 | 72 |
| 80 | 73 |
| 81 // 21.1.3.27 String.prototype [ @@iterator ]( ) | 74 // 21.1.3.27 String.prototype [ @@iterator ]( ) |
| 82 function StringPrototypeIterator() { | 75 function StringPrototypeIterator() { |
| 83 return CreateStringIterator(this); | 76 return CreateStringIterator(this); |
| 84 } | 77 } |
| 85 | 78 |
| 86 //------------------------------------------------------------------- | 79 //------------------------------------------------------------------- |
| 87 | 80 |
| 88 %FunctionSetPrototype(StringIterator, new GlobalObject()); | 81 %FunctionSetPrototype(StringIterator, {__proto__: $iteratorPrototype}); |
| 89 %FunctionSetInstanceClassName(StringIterator, 'String Iterator'); | 82 %FunctionSetInstanceClassName(StringIterator, 'String Iterator'); |
| 90 | 83 |
| 91 $installFunctions(StringIterator.prototype, DONT_ENUM, [ | 84 $installFunctions(StringIterator.prototype, DONT_ENUM, [ |
| 92 'next', StringIteratorNext | 85 'next', StringIteratorNext |
| 93 ]); | 86 ]); |
| 94 $setFunctionName(StringIteratorIterator, symbolIterator); | |
| 95 %AddNamedProperty(StringIterator.prototype, symbolIterator, | |
| 96 StringIteratorIterator, DONT_ENUM); | |
| 97 %AddNamedProperty(StringIterator.prototype, symbolToStringTag, | 87 %AddNamedProperty(StringIterator.prototype, symbolToStringTag, |
| 98 "String Iterator", READ_ONLY | DONT_ENUM); | 88 "String Iterator", READ_ONLY | DONT_ENUM); |
| 99 | 89 |
| 100 $setFunctionName(StringPrototypeIterator, symbolIterator); | 90 $setFunctionName(StringPrototypeIterator, symbolIterator); |
| 101 %AddNamedProperty(GlobalString.prototype, symbolIterator, | 91 %AddNamedProperty(GlobalString.prototype, symbolIterator, |
| 102 StringPrototypeIterator, DONT_ENUM); | 92 StringPrototypeIterator, DONT_ENUM); |
| 103 | 93 |
| 104 }) | 94 }) |
| OLD | NEW |