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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // 'AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // 'AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
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 | |
30 // This file relies on the fact that the following declaration has been made | 31 // This file relies on the fact that the following declaration has been made |
31 // in runtime.js: | 32 // in runtime.js: |
32 // var $Array = global.Array; | 33 // var $Array = global.Array; |
33 | 34 |
35 | |
34 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object"); | 36 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object"); |
35 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next"); | 37 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next"); |
36 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind"); | 38 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind"); |
37 | 39 |
40 | |
38 function ArrayIterator() {} | 41 function ArrayIterator() {} |
39 | 42 |
43 | |
40 // 15.4.5.1 CreateArrayIterator Abstract Operation | 44 // 15.4.5.1 CreateArrayIterator Abstract Operation |
41 function CreateArrayIterator(array, kind) { | 45 function CreateArrayIterator(array, kind) { |
42 var object = ToObject(array); | 46 var object = ToObject(array); |
43 var iterator = new ArrayIterator; | 47 var iterator = new ArrayIterator; |
44 SET_PRIVATE(iterator, arrayIteratorObjectSymbol, object); | 48 SET_PRIVATE(iterator, arrayIteratorObjectSymbol, object); |
45 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, 0); | 49 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, 0); |
46 SET_PRIVATE(iterator, arrayIterationKindSymbol, kind); | 50 SET_PRIVATE(iterator, arrayIterationKindSymbol, kind); |
47 return iterator; | 51 return iterator; |
48 } | 52 } |
49 | 53 |
54 | |
50 // 15.19.4.3.4 CreateItrResultObject | 55 // 15.19.4.3.4 CreateItrResultObject |
51 function CreateIteratorResultObject(value, done) { | 56 function CreateIteratorResultObject(value, done) { |
52 return {value: value, done: done}; | 57 return {value: value, done: done}; |
53 } | 58 } |
54 | 59 |
60 | |
55 // 15.4.5.2.2 ArrayIterator.prototype.next( ) | 61 // 15.4.5.2.2 ArrayIterator.prototype.next( ) |
56 function ArrayIteratorNext() { | 62 function ArrayIteratorNext() { |
57 var iterator = ToObject(this); | 63 var iterator = ToObject(this); |
58 var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol); | 64 var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol); |
59 if (!array) { | 65 if (!array) { |
60 throw MakeTypeError('incompatible_method_receiver', | 66 throw MakeTypeError('incompatible_method_receiver', |
61 ['Array Iterator.prototype.next']); | 67 ['Array Iterator.prototype.next']); |
62 } | 68 } |
63 | 69 |
64 var index = GET_PRIVATE(iterator, arrayIteratorNextIndexSymbol); | 70 var index = GET_PRIVATE(iterator, arrayIteratorNextIndexSymbol); |
(...skipping 11 matching lines...) Expand all Loading... | |
76 | 82 |
77 if (itemKind == ITERATOR_KIND_VALUES) | 83 if (itemKind == ITERATOR_KIND_VALUES) |
78 return CreateIteratorResultObject(array[index], false); | 84 return CreateIteratorResultObject(array[index], false); |
79 | 85 |
80 if (itemKind == ITERATOR_KIND_ENTRIES) | 86 if (itemKind == ITERATOR_KIND_ENTRIES) |
81 return CreateIteratorResultObject([index, array[index]], false); | 87 return CreateIteratorResultObject([index, array[index]], false); |
82 | 88 |
83 return CreateIteratorResultObject(index, false); | 89 return CreateIteratorResultObject(index, false); |
84 } | 90 } |
85 | 91 |
92 | |
86 function ArrayEntries() { | 93 function ArrayEntries() { |
87 return CreateArrayIterator(this, ITERATOR_KIND_ENTRIES); | 94 return CreateArrayIterator(this, ITERATOR_KIND_ENTRIES); |
88 } | 95 } |
89 | 96 |
97 | |
90 function ArrayValues() { | 98 function ArrayValues() { |
91 return CreateArrayIterator(this, ITERATOR_KIND_VALUES); | 99 return CreateArrayIterator(this, ITERATOR_KIND_VALUES); |
92 } | 100 } |
93 | 101 |
102 | |
94 function ArrayKeys() { | 103 function ArrayKeys() { |
95 return CreateArrayIterator(this, ITERATOR_KIND_KEYS); | 104 return CreateArrayIterator(this, ITERATOR_KIND_KEYS); |
96 } | 105 } |
97 | 106 |
107 | |
98 function SetUpArrayIterator() { | 108 function SetUpArrayIterator() { |
99 %CheckIsBootstrapping(); | 109 %CheckIsBootstrapping(); |
100 | 110 |
111 delete ArrayIterator.prototype.constructor; | |
arv (Not doing code reviews)
2014/04/25 16:45:30
I don't see where the constructor is added to this
arv (Not doing code reviews)
2014/04/28 21:12:54
Doh! The constructor is set by default for all fun
| |
101 %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator'); | 112 %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator'); |
102 %FunctionSetReadOnlyPrototype(ArrayIterator); | |
arv (Not doing code reviews)
2014/04/25 16:45:30
This is not in the spec and now there is no way to
| |
103 | 113 |
104 InstallFunctions(ArrayIterator.prototype, DONT_ENUM, $Array( | 114 InstallFunctions(ArrayIterator.prototype, DONT_ENUM, $Array( |
105 'next', ArrayIteratorNext | 115 'next', ArrayIteratorNext |
106 )); | 116 )); |
107 } | 117 } |
118 SetUpArrayIterator(); | |
108 | 119 |
109 SetUpArrayIterator(); | |
110 | 120 |
111 function ExtendArrayPrototype() { | 121 function ExtendArrayPrototype() { |
112 %CheckIsBootstrapping(); | 122 %CheckIsBootstrapping(); |
113 | 123 |
114 InstallFunctions($Array.prototype, DONT_ENUM, $Array( | 124 InstallFunctions($Array.prototype, DONT_ENUM, $Array( |
115 'entries', ArrayEntries, | 125 'entries', ArrayEntries, |
116 'values', ArrayValues, | 126 'values', ArrayValues, |
117 'keys', ArrayKeys | 127 'keys', ArrayKeys |
118 )); | 128 )); |
119 } | 129 } |
120 | |
121 ExtendArrayPrototype(); | 130 ExtendArrayPrototype(); |
OLD | NEW |