OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 | 7 |
8 // This file relies on the fact that the following declaration has been made | 8 // This file relies on the fact that the following declaration has been made |
9 // in runtime.js: | 9 // in runtime.js: |
10 // var $Array = global.Array; | 10 // var $Array = global.Array; |
11 | 11 |
12 | 12 |
13 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object"); | 13 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE_OWN("ArrayIterator#object"); |
14 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next"); | 14 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE_OWN("ArrayIterator#next"); |
15 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind"); | 15 var arrayIterationKindSymbol = GLOBAL_PRIVATE_OWN("ArrayIterator#kind"); |
| 16 |
| 17 var arrayEndOfIterationMarker = new $Object(); |
16 | 18 |
17 | 19 |
18 function ArrayIterator() {} | 20 function ArrayIterator() {} |
19 | 21 |
20 | 22 |
21 // TODO(wingo): Update section numbers when ES6 has stabilized. The | 23 // TODO(wingo): Update section numbers when ES6 has stabilized. The |
22 // section numbers below are already out of date as of the May 2014 | 24 // section numbers below are already out of date as of the May 2014 |
23 // draft. | 25 // draft. |
24 | 26 |
25 | 27 |
(...skipping 17 matching lines...) Expand all Loading... |
43 // 22.1.5.2.2 %ArrayIteratorPrototype%[@@iterator] | 45 // 22.1.5.2.2 %ArrayIteratorPrototype%[@@iterator] |
44 function ArrayIteratorIterator() { | 46 function ArrayIteratorIterator() { |
45 return this; | 47 return this; |
46 } | 48 } |
47 | 49 |
48 | 50 |
49 // 15.4.5.2.2 ArrayIterator.prototype.next( ) | 51 // 15.4.5.2.2 ArrayIterator.prototype.next( ) |
50 function ArrayIteratorNext() { | 52 function ArrayIteratorNext() { |
51 var iterator = ToObject(this); | 53 var iterator = ToObject(this); |
52 | 54 |
53 if (!HAS_PRIVATE(iterator, arrayIteratorObjectSymbol)) { | 55 if (!HAS_DEFINED_PRIVATE(iterator, arrayIteratorObjectSymbol)) { |
54 throw MakeTypeError('incompatible_method_receiver', | 56 throw MakeTypeError('incompatible_method_receiver', |
55 ['Array Iterator.prototype.next']); | 57 ['Array Iterator.prototype.next']); |
56 } | 58 } |
57 | 59 |
58 var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol); | 60 var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol); |
59 if (IS_UNDEFINED(array)) { | 61 if (array === arrayEndOfIterationMarker) { |
60 return CreateIteratorResultObject(UNDEFINED, true); | 62 return CreateIteratorResultObject(UNDEFINED, true); |
61 } | 63 } |
62 | 64 |
63 var index = GET_PRIVATE(iterator, arrayIteratorNextIndexSymbol); | 65 var index = GET_PRIVATE(iterator, arrayIteratorNextIndexSymbol); |
64 var itemKind = GET_PRIVATE(iterator, arrayIterationKindSymbol); | 66 var itemKind = GET_PRIVATE(iterator, arrayIterationKindSymbol); |
65 var length = TO_UINT32(array.length); | 67 var length = TO_UINT32(array.length); |
66 | 68 |
67 // "sparse" is never used. | 69 // "sparse" is never used. |
68 | 70 |
69 if (index >= length) { | 71 if (index >= length) { |
70 SET_PRIVATE(iterator, arrayIteratorObjectSymbol, UNDEFINED); | 72 SET_PRIVATE(iterator, arrayIteratorObjectSymbol, arrayEndOfIterationMarker); |
71 return CreateIteratorResultObject(UNDEFINED, true); | 73 return CreateIteratorResultObject(UNDEFINED, true); |
72 } | 74 } |
73 | 75 |
74 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, index + 1); | 76 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, index + 1); |
75 | 77 |
76 if (itemKind == ITERATOR_KIND_VALUES) { | 78 if (itemKind == ITERATOR_KIND_VALUES) { |
77 return CreateIteratorResultObject(array[index], false); | 79 return CreateIteratorResultObject(array[index], false); |
78 } | 80 } |
79 | 81 |
80 if (itemKind == ITERATOR_KIND_ENTRIES) { | 82 if (itemKind == ITERATOR_KIND_ENTRIES) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 macro EXTEND_TYPED_ARRAY(NAME) | 150 macro EXTEND_TYPED_ARRAY(NAME) |
149 %AddNamedProperty($NAME.prototype, 'entries', ArrayEntries, DONT_ENUM); | 151 %AddNamedProperty($NAME.prototype, 'entries', ArrayEntries, DONT_ENUM); |
150 %AddNamedProperty($NAME.prototype, 'values', ArrayValues, DONT_ENUM); | 152 %AddNamedProperty($NAME.prototype, 'values', ArrayValues, DONT_ENUM); |
151 %AddNamedProperty($NAME.prototype, 'keys', ArrayKeys, DONT_ENUM); | 153 %AddNamedProperty($NAME.prototype, 'keys', ArrayKeys, DONT_ENUM); |
152 %AddNamedProperty($NAME.prototype, symbolIterator, ArrayValues, DONT_ENUM); | 154 %AddNamedProperty($NAME.prototype, symbolIterator, ArrayValues, DONT_ENUM); |
153 endmacro | 155 endmacro |
154 | 156 |
155 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) | 157 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) |
156 } | 158 } |
157 ExtendTypedArrayPrototypes(); | 159 ExtendTypedArrayPrototypes(); |
OLD | NEW |