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