| 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 = NEW_PRIVATE("iterator_object"); | 39 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object"); |
| 40 var arrayIteratorNextIndexSymbol = NEW_PRIVATE("iterator_next"); | 40 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next"); |
| 41 var arrayIterationKindSymbol = NEW_PRIVATE("iterator_kind"); | 41 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind"); |
| 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 SET_PRIVATE(iterator, iteratorObjectSymbol, object); | 49 SET_PRIVATE(iterator, arrayIteratorObjectSymbol, object); |
| 50 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, 0); | 50 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, 0); |
| 51 SET_PRIVATE(iterator, arrayIterationKindSymbol, kind); | 51 SET_PRIVATE(iterator, arrayIterationKindSymbol, kind); |
| 52 return iterator; | 52 return iterator; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // 15.19.4.3.4 CreateItrResultObject | 55 // 15.19.4.3.4 CreateItrResultObject |
| 56 function CreateIteratorResultObject(value, done) { | 56 function CreateIteratorResultObject(value, done) { |
| 57 return {value: value, done: done}; | 57 return {value: value, done: done}; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // 15.4.5.2.2 ArrayIterator.prototype.next( ) | 60 // 15.4.5.2.2 ArrayIterator.prototype.next( ) |
| 61 function ArrayIteratorNext() { | 61 function ArrayIteratorNext() { |
| 62 var iterator = ToObject(this); | 62 var iterator = ToObject(this); |
| 63 var array = GET_PRIVATE(iterator, iteratorObjectSymbol); | 63 var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol); |
| 64 if (!array) { | 64 if (!array) { |
| 65 throw MakeTypeError('incompatible_method_receiver', | 65 throw MakeTypeError('incompatible_method_receiver', |
| 66 ['Array Iterator.prototype.next']); | 66 ['Array Iterator.prototype.next']); |
| 67 } | 67 } |
| 68 | 68 |
| 69 var index = GET_PRIVATE(iterator, arrayIteratorNextIndexSymbol); | 69 var index = GET_PRIVATE(iterator, arrayIteratorNextIndexSymbol); |
| 70 var itemKind = GET_PRIVATE(iterator, arrayIterationKindSymbol); | 70 var itemKind = GET_PRIVATE(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. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |