OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 102 |
103 function ArrayValues() { | 103 function ArrayValues() { |
104 return CreateArrayIterator(this, ITERATOR_KIND_VALUES); | 104 return CreateArrayIterator(this, ITERATOR_KIND_VALUES); |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 function ArrayKeys() { | 108 function ArrayKeys() { |
109 return CreateArrayIterator(this, ITERATOR_KIND_KEYS); | 109 return CreateArrayIterator(this, ITERATOR_KIND_KEYS); |
110 } | 110 } |
111 | 111 |
| 112 // TODO(littledan): Check for detached TypedArray in these three methods |
| 113 function TypedArrayEntries() { |
| 114 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
| 115 return %_Call(ArrayEntries, this); |
| 116 } |
| 117 |
| 118 |
| 119 function TypedArrayValues() { |
| 120 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
| 121 return %_Call(ArrayValues, this); |
| 122 } |
| 123 |
| 124 |
| 125 function TypedArrayKeys() { |
| 126 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
| 127 return %_Call(ArrayKeys, this); |
| 128 } |
| 129 |
112 | 130 |
113 %FunctionSetPrototype(ArrayIterator, {__proto__: IteratorPrototype}); | 131 %FunctionSetPrototype(ArrayIterator, {__proto__: IteratorPrototype}); |
114 %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator'); | 132 %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator'); |
115 | 133 |
116 utils.InstallFunctions(ArrayIterator.prototype, DONT_ENUM, [ | 134 utils.InstallFunctions(ArrayIterator.prototype, DONT_ENUM, [ |
117 'next', ArrayIteratorNext | 135 'next', ArrayIteratorNext |
118 ]); | 136 ]); |
119 utils.SetFunctionName(ArrayIteratorIterator, iteratorSymbol); | 137 utils.SetFunctionName(ArrayIteratorIterator, iteratorSymbol); |
120 %AddNamedProperty(ArrayIterator.prototype, toStringTagSymbol, | 138 %AddNamedProperty(ArrayIterator.prototype, toStringTagSymbol, |
121 "Array Iterator", READ_ONLY | DONT_ENUM); | 139 "Array Iterator", READ_ONLY | DONT_ENUM); |
122 | 140 |
123 utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ | 141 utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ |
124 // No 'values' since it breaks webcompat: http://crbug.com/409858 | 142 // No 'values' since it breaks webcompat: http://crbug.com/409858 |
125 'entries', ArrayEntries, | 143 'entries', ArrayEntries, |
126 'keys', ArrayKeys | 144 'keys', ArrayKeys |
127 ]); | 145 ]); |
128 | 146 |
129 // TODO(adam): Remove this call once 'values' is in the above | 147 // TODO(adam): Remove this call once 'values' is in the above |
130 // InstallFunctions block, as it'll be redundant. | 148 // InstallFunctions block, as it'll be redundant. |
131 utils.SetFunctionName(ArrayValues, 'values'); | 149 utils.SetFunctionName(ArrayValues, 'values'); |
132 | 150 |
133 %AddNamedProperty(GlobalArray.prototype, iteratorSymbol, ArrayValues, | 151 %AddNamedProperty(GlobalArray.prototype, iteratorSymbol, ArrayValues, |
134 DONT_ENUM); | 152 DONT_ENUM); |
135 | 153 |
| 154 utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [ |
| 155 'entries', TypedArrayEntries, |
| 156 'keys', TypedArrayKeys, |
| 157 'values', TypedArrayValues |
| 158 ]); |
136 %AddNamedProperty(GlobalTypedArray.prototype, | 159 %AddNamedProperty(GlobalTypedArray.prototype, |
137 'entries', ArrayEntries, DONT_ENUM); | 160 iteratorSymbol, TypedArrayValues, DONT_ENUM); |
138 %AddNamedProperty(GlobalTypedArray.prototype, 'values', ArrayValues, DONT_ENUM); | |
139 %AddNamedProperty(GlobalTypedArray.prototype, 'keys', ArrayKeys, DONT_ENUM); | |
140 %AddNamedProperty(GlobalTypedArray.prototype, | |
141 iteratorSymbol, ArrayValues, DONT_ENUM); | |
142 | 161 |
143 // ------------------------------------------------------------------- | 162 // ------------------------------------------------------------------- |
144 // Exports | 163 // Exports |
145 | 164 |
146 utils.Export(function(to) { | 165 utils.Export(function(to) { |
147 to.ArrayValues = ArrayValues; | 166 to.ArrayValues = ArrayValues; |
148 }); | 167 }); |
149 | 168 |
150 %InstallToContext(["array_values_iterator", ArrayValues]); | 169 %InstallToContext(["array_values_iterator", ArrayValues]); |
151 | 170 |
152 }) | 171 }) |
OLD | NEW |