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 var $iteratorCreateResultObject; | |
6 var $arrayValues; | |
7 | |
8 (function() { | |
9 | |
10 "use strict"; | 5 "use strict"; |
11 | 6 |
12 %CheckIsBootstrapping(); | |
13 | 7 |
14 var GlobalArray = global.Array; | 8 // This file relies on the fact that the following declaration has been made |
15 var GlobalObject = global.Object; | 9 // in runtime.js: |
| 10 // var $Array = global.Array; |
16 | 11 |
17 macro TYPED_ARRAYS(FUNCTION) | |
18 FUNCTION(Uint8Array) | |
19 FUNCTION(Int8Array) | |
20 FUNCTION(Uint16Array) | |
21 FUNCTION(Int16Array) | |
22 FUNCTION(Uint32Array) | |
23 FUNCTION(Int32Array) | |
24 FUNCTION(Float32Array) | |
25 FUNCTION(Float64Array) | |
26 FUNCTION(Uint8ClampedArray) | |
27 endmacro | |
28 | |
29 macro COPY_FROM_GLOBAL(NAME) | |
30 var GlobalNAME = global.NAME; | |
31 endmacro | |
32 | |
33 TYPED_ARRAYS(COPY_FROM_GLOBAL) | |
34 | 12 |
35 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object"); | 13 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object"); |
36 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next"); | 14 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next"); |
37 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind"); | 15 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind"); |
38 | 16 |
39 | 17 |
40 function ArrayIterator() {} | 18 function ArrayIterator() {} |
41 | 19 |
42 | 20 |
43 // TODO(wingo): Update section numbers when ES6 has stabilized. The | 21 // TODO(wingo): Update section numbers when ES6 has stabilized. The |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 function ArrayValues() { | 93 function ArrayValues() { |
116 return CreateArrayIterator(this, ITERATOR_KIND_VALUES); | 94 return CreateArrayIterator(this, ITERATOR_KIND_VALUES); |
117 } | 95 } |
118 | 96 |
119 | 97 |
120 function ArrayKeys() { | 98 function ArrayKeys() { |
121 return CreateArrayIterator(this, ITERATOR_KIND_KEYS); | 99 return CreateArrayIterator(this, ITERATOR_KIND_KEYS); |
122 } | 100 } |
123 | 101 |
124 | 102 |
125 %FunctionSetPrototype(ArrayIterator, new GlobalObject()); | 103 function SetUpArrayIterator() { |
126 %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator'); | 104 %CheckIsBootstrapping(); |
127 | 105 |
128 InstallFunctions(ArrayIterator.prototype, DONT_ENUM, [ | 106 %FunctionSetPrototype(ArrayIterator, new $Object()); |
129 'next', ArrayIteratorNext | 107 %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator'); |
130 ]); | |
131 %FunctionSetName(ArrayIteratorIterator, '[Symbol.iterator]'); | |
132 %AddNamedProperty(ArrayIterator.prototype, symbolIterator, | |
133 ArrayIteratorIterator, DONT_ENUM); | |
134 %AddNamedProperty(ArrayIterator.prototype, symbolToStringTag, | |
135 "Array Iterator", READ_ONLY | DONT_ENUM); | |
136 | 108 |
137 InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ | 109 InstallFunctions(ArrayIterator.prototype, DONT_ENUM, [ |
138 // No 'values' since it breaks webcompat: http://crbug.com/409858 | 110 'next', ArrayIteratorNext |
139 'entries', ArrayEntries, | 111 ]); |
140 'keys', ArrayKeys | 112 %FunctionSetName(ArrayIteratorIterator, '[Symbol.iterator]'); |
141 ]); | 113 %AddNamedProperty(ArrayIterator.prototype, symbolIterator, |
| 114 ArrayIteratorIterator, DONT_ENUM); |
| 115 %AddNamedProperty(ArrayIterator.prototype, symbolToStringTag, |
| 116 "Array Iterator", READ_ONLY | DONT_ENUM); |
| 117 } |
| 118 SetUpArrayIterator(); |
142 | 119 |
143 %AddNamedProperty(GlobalArray.prototype, symbolIterator, ArrayValues, | 120 |
144 DONT_ENUM); | 121 function ExtendArrayPrototype() { |
| 122 %CheckIsBootstrapping(); |
| 123 |
| 124 InstallFunctions($Array.prototype, DONT_ENUM, [ |
| 125 // No 'values' since it breaks webcompat: http://crbug.com/409858 |
| 126 'entries', ArrayEntries, |
| 127 'keys', ArrayKeys |
| 128 ]); |
| 129 |
| 130 %AddNamedProperty($Array.prototype, symbolIterator, ArrayValues, DONT_ENUM); |
| 131 } |
| 132 ExtendArrayPrototype(); |
| 133 |
| 134 |
| 135 function ExtendTypedArrayPrototypes() { |
| 136 %CheckIsBootstrapping(); |
| 137 |
| 138 macro TYPED_ARRAYS(FUNCTION) |
| 139 FUNCTION(Uint8Array) |
| 140 FUNCTION(Int8Array) |
| 141 FUNCTION(Uint16Array) |
| 142 FUNCTION(Int16Array) |
| 143 FUNCTION(Uint32Array) |
| 144 FUNCTION(Int32Array) |
| 145 FUNCTION(Float32Array) |
| 146 FUNCTION(Float64Array) |
| 147 FUNCTION(Uint8ClampedArray) |
| 148 endmacro |
145 | 149 |
146 macro EXTEND_TYPED_ARRAY(NAME) | 150 macro EXTEND_TYPED_ARRAY(NAME) |
147 %AddNamedProperty(GlobalNAME.prototype, 'entries', ArrayEntries, DONT_ENUM); | 151 %AddNamedProperty($NAME.prototype, 'entries', ArrayEntries, DONT_ENUM); |
148 %AddNamedProperty(GlobalNAME.prototype, 'values', ArrayValues, DONT_ENUM); | 152 %AddNamedProperty($NAME.prototype, 'values', ArrayValues, DONT_ENUM); |
149 %AddNamedProperty(GlobalNAME.prototype, 'keys', ArrayKeys, DONT_ENUM); | 153 %AddNamedProperty($NAME.prototype, 'keys', ArrayKeys, DONT_ENUM); |
150 %AddNamedProperty(GlobalNAME.prototype, symbolIterator, ArrayValues, | 154 %AddNamedProperty($NAME.prototype, symbolIterator, ArrayValues, DONT_ENUM); |
151 DONT_ENUM); | |
152 endmacro | 155 endmacro |
153 | 156 |
154 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) | 157 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) |
155 | 158 } |
156 $iteratorCreateResultObject = CreateIteratorResultObject; | 159 ExtendTypedArrayPrototypes(); |
157 $arrayValues = ArrayValues; | |
158 | |
159 })(); | |
OLD | NEW |