OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 13 matching lines...) Expand all Loading... |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 'use strict'; | 28 'use strict'; |
29 | 29 |
30 // This file relies on the fact that the following declaration has been made | 30 // This file relies on the fact that the following declaration has been made |
31 // in runtime.js: | 31 // in runtime.js: |
32 // var $Array = global.Array; | 32 // var $Array = global.Array; |
33 | 33 |
| 34 var ARRAY_ITERATOR_KIND_KEYS = 1; |
| 35 var ARRAY_ITERATOR_KIND_VALUES = 2; |
| 36 var ARRAY_ITERATOR_KIND_ENTRIES = 3; |
| 37 // The spec draft also has "sparse" but it is never used. |
| 38 |
34 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object"); | 39 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object"); |
35 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next"); | 40 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next"); |
36 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind"); | 41 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind"); |
37 | 42 |
38 function ArrayIterator() {} | 43 function ArrayIterator() {} |
39 | 44 |
40 // 15.4.5.1 CreateArrayIterator Abstract Operation | 45 // 15.4.5.1 CreateArrayIterator Abstract Operation |
41 function CreateArrayIterator(array, kind) { | 46 function CreateArrayIterator(array, kind) { |
42 var object = ToObject(array); | 47 var object = ToObject(array); |
43 var iterator = new ArrayIterator; | 48 var iterator = new ArrayIterator; |
(...skipping 23 matching lines...) Expand all Loading... |
67 | 72 |
68 // "sparse" is never used. | 73 // "sparse" is never used. |
69 | 74 |
70 if (index >= length) { | 75 if (index >= length) { |
71 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, INFINITY); | 76 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, INFINITY); |
72 return CreateIteratorResultObject(UNDEFINED, true); | 77 return CreateIteratorResultObject(UNDEFINED, true); |
73 } | 78 } |
74 | 79 |
75 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, index + 1); | 80 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, index + 1); |
76 | 81 |
77 if (itemKind == ITERATOR_KIND_VALUES) | 82 if (itemKind == ARRAY_ITERATOR_KIND_VALUES) |
78 return CreateIteratorResultObject(array[index], false); | 83 return CreateIteratorResultObject(array[index], false); |
79 | 84 |
80 if (itemKind == ITERATOR_KIND_ENTRIES) | 85 if (itemKind == ARRAY_ITERATOR_KIND_ENTRIES) |
81 return CreateIteratorResultObject([index, array[index]], false); | 86 return CreateIteratorResultObject([index, array[index]], false); |
82 | 87 |
83 return CreateIteratorResultObject(index, false); | 88 return CreateIteratorResultObject(index, false); |
84 } | 89 } |
85 | 90 |
86 function ArrayEntries() { | 91 function ArrayEntries() { |
87 return CreateArrayIterator(this, ITERATOR_KIND_ENTRIES); | 92 return CreateArrayIterator(this, ARRAY_ITERATOR_KIND_ENTRIES); |
88 } | 93 } |
89 | 94 |
90 function ArrayValues() { | 95 function ArrayValues() { |
91 return CreateArrayIterator(this, ITERATOR_KIND_VALUES); | 96 return CreateArrayIterator(this, ARRAY_ITERATOR_KIND_VALUES); |
92 } | 97 } |
93 | 98 |
94 function ArrayKeys() { | 99 function ArrayKeys() { |
95 return CreateArrayIterator(this, ITERATOR_KIND_KEYS); | 100 return CreateArrayIterator(this, ARRAY_ITERATOR_KIND_KEYS); |
96 } | 101 } |
97 | 102 |
98 function SetUpArrayIterator() { | 103 function SetUpArrayIterator() { |
99 %CheckIsBootstrapping(); | 104 %CheckIsBootstrapping(); |
100 | 105 |
101 %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator'); | 106 %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator'); |
102 %FunctionSetReadOnlyPrototype(ArrayIterator); | 107 %FunctionSetReadOnlyPrototype(ArrayIterator); |
103 | 108 |
104 InstallFunctions(ArrayIterator.prototype, DONT_ENUM, $Array( | 109 InstallFunctions(ArrayIterator.prototype, DONT_ENUM, $Array( |
105 'next', ArrayIteratorNext | 110 'next', ArrayIteratorNext |
106 )); | 111 )); |
107 } | 112 } |
108 | 113 |
109 SetUpArrayIterator(); | 114 SetUpArrayIterator(); |
110 | 115 |
111 function ExtendArrayPrototype() { | 116 function ExtendArrayPrototype() { |
112 %CheckIsBootstrapping(); | 117 %CheckIsBootstrapping(); |
113 | 118 |
114 InstallFunctions($Array.prototype, DONT_ENUM, $Array( | 119 InstallFunctions($Array.prototype, DONT_ENUM, $Array( |
115 'entries', ArrayEntries, | 120 'entries', ArrayEntries, |
116 'values', ArrayValues, | 121 'values', ArrayValues, |
117 'keys', ArrayKeys | 122 'keys', ArrayKeys |
118 )); | 123 )); |
119 } | 124 } |
120 | 125 |
121 ExtendArrayPrototype(); | 126 ExtendArrayPrototype(); |
OLD | NEW |