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 18 matching lines...) Expand all Loading... |
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; | 34 var ARRAY_ITERATOR_KIND_KEYS = 1; |
35 var ARRAY_ITERATOR_KIND_VALUES = 2; | 35 var ARRAY_ITERATOR_KIND_VALUES = 2; |
36 var ARRAY_ITERATOR_KIND_ENTRIES = 3; | 36 var ARRAY_ITERATOR_KIND_ENTRIES = 3; |
37 // The spec draft also has "sparse" but it is never used. | 37 // The spec draft also has "sparse" but it is never used. |
38 | 38 |
39 var iteratorObjectSymbol = %CreateSymbol(void 0); | 39 var iteratorObjectSymbol = %CreateSymbol(UNDEFINED); |
40 var arrayIteratorNextIndexSymbol = %CreateSymbol(void 0); | 40 var arrayIteratorNextIndexSymbol = %CreateSymbol(UNDEFINED); |
41 var arrayIterationKindSymbol = %CreateSymbol(void 0); | 41 var arrayIterationKindSymbol = %CreateSymbol(UNDEFINED); |
42 | 42 |
43 function ArrayIterator() {} | 43 function ArrayIterator() {} |
44 | 44 |
45 // 15.4.5.1 CreateArrayIterator Abstract Operation | 45 // 15.4.5.1 CreateArrayIterator Abstract Operation |
46 function CreateArrayIterator(array, kind) { | 46 function CreateArrayIterator(array, kind) { |
47 var object = ToObject(array); | 47 var object = ToObject(array); |
48 var iterator = new ArrayIterator; | 48 var iterator = new ArrayIterator; |
49 iterator[iteratorObjectSymbol] = object; | 49 iterator[iteratorObjectSymbol] = object; |
50 iterator[arrayIteratorNextIndexSymbol] = 0; | 50 iterator[arrayIteratorNextIndexSymbol] = 0; |
51 iterator[arrayIterationKindSymbol] = kind; | 51 iterator[arrayIterationKindSymbol] = kind; |
(...skipping 15 matching lines...) Expand all Loading... |
67 } | 67 } |
68 | 68 |
69 var index = iterator[arrayIteratorNextIndexSymbol]; | 69 var index = iterator[arrayIteratorNextIndexSymbol]; |
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(UNDEFINED, true); |
78 } | 78 } |
79 | 79 |
80 iterator[arrayIteratorNextIndexSymbol] = index + 1; | 80 iterator[arrayIteratorNextIndexSymbol] = index + 1; |
81 | 81 |
82 if (itemKind == ARRAY_ITERATOR_KIND_VALUES) | 82 if (itemKind == ARRAY_ITERATOR_KIND_VALUES) |
83 return CreateIteratorResultObject(array[index], false); | 83 return CreateIteratorResultObject(array[index], false); |
84 | 84 |
85 if (itemKind == ARRAY_ITERATOR_KIND_ENTRIES) | 85 if (itemKind == ARRAY_ITERATOR_KIND_ENTRIES) |
86 return CreateIteratorResultObject([index, array[index]], false); | 86 return CreateIteratorResultObject([index, array[index]], false); |
87 | 87 |
(...skipping 29 matching lines...) Expand all Loading... |
117 %CheckIsBootstrapping(); | 117 %CheckIsBootstrapping(); |
118 | 118 |
119 InstallFunctions($Array.prototype, DONT_ENUM, $Array( | 119 InstallFunctions($Array.prototype, DONT_ENUM, $Array( |
120 'entries', ArrayEntries, | 120 'entries', ArrayEntries, |
121 'values', ArrayValues, | 121 'values', ArrayValues, |
122 'keys', ArrayKeys | 122 'keys', ArrayKeys |
123 )); | 123 )); |
124 } | 124 } |
125 | 125 |
126 ExtendArrayPrototype(); | 126 ExtendArrayPrototype(); |
OLD | NEW |