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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 var itemKind = iterator[arrayIterationKindSymbol]; | 70 var itemKind = iterator[arrayIterationKindSymbol]; |
71 var length = TO_UINT32(array.length); | 71 var length = TO_UINT32(array.length); |
72 | 72 |
73 // "sparse" is never used. | 73 // "sparse" is never used. |
74 | 74 |
75 if (index >= length) { | 75 if (index >= length) { |
76 iterator[arrayIteratorNextIndexSymbol] = 1 / 0; // Infinity | 76 iterator[arrayIteratorNextIndexSymbol] = 1 / 0; // Infinity |
77 return CreateIteratorResultObject(void 0, true); | 77 return CreateIteratorResultObject(void 0, true); |
78 } | 78 } |
79 | 79 |
| 80 var elementKey = ToString(index); |
80 iterator[arrayIteratorNextIndexSymbol] = index + 1; | 81 iterator[arrayIteratorNextIndexSymbol] = index + 1; |
81 | 82 |
82 if (itemKind == ARRAY_ITERATOR_KIND_VALUES) | 83 if (itemKind == ARRAY_ITERATOR_KIND_VALUES) |
83 return CreateIteratorResultObject(array[index], false); | 84 return CreateIteratorResultObject(array[elementKey], false); |
84 | 85 |
85 if (itemKind == ARRAY_ITERATOR_KIND_ENTRIES) | 86 if (itemKind == ARRAY_ITERATOR_KIND_ENTRIES) |
86 return CreateIteratorResultObject([index, array[index]], false); | 87 return CreateIteratorResultObject([elementKey, array[elementKey]], false); |
87 | 88 |
88 return CreateIteratorResultObject(index, false); | 89 return CreateIteratorResultObject(elementKey, false); |
89 } | 90 } |
90 | 91 |
91 function ArrayEntries() { | 92 function ArrayEntries() { |
92 return CreateArrayIterator(this, ARRAY_ITERATOR_KIND_ENTRIES); | 93 return CreateArrayIterator(this, ARRAY_ITERATOR_KIND_ENTRIES); |
93 } | 94 } |
94 | 95 |
95 function ArrayValues() { | 96 function ArrayValues() { |
96 return CreateArrayIterator(this, ARRAY_ITERATOR_KIND_VALUES); | 97 return CreateArrayIterator(this, ARRAY_ITERATOR_KIND_VALUES); |
97 } | 98 } |
98 | 99 |
(...skipping 18 matching lines...) Expand all Loading... |
117 %CheckIsBootstrapping(); | 118 %CheckIsBootstrapping(); |
118 | 119 |
119 InstallFunctions($Array.prototype, DONT_ENUM, $Array( | 120 InstallFunctions($Array.prototype, DONT_ENUM, $Array( |
120 'entries', ArrayEntries, | 121 'entries', ArrayEntries, |
121 'values', ArrayValues, | 122 'values', ArrayValues, |
122 'keys', ArrayKeys | 123 'keys', ArrayKeys |
123 )); | 124 )); |
124 } | 125 } |
125 | 126 |
126 ExtendArrayPrototype(); | 127 ExtendArrayPrototype(); |
OLD | NEW |