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 25 matching lines...) Expand all Loading... |
36 TYPED_ARRAYS(DECLARE_GLOBALS) | 36 TYPED_ARRAYS(DECLARE_GLOBALS) |
37 | 37 |
38 var MathMax; | 38 var MathMax; |
39 var MathMin; | 39 var MathMin; |
40 | 40 |
41 utils.Import(function(from) { | 41 utils.Import(function(from) { |
42 MathMax = from.MathMax; | 42 MathMax = from.MathMax; |
43 MathMin = from.MathMin; | 43 MathMin = from.MathMin; |
44 }); | 44 }); |
45 | 45 |
| 46 var InternalArray = utils.InternalArray; |
| 47 |
46 // --------------- Typed Arrays --------------------- | 48 // --------------- Typed Arrays --------------------- |
47 | 49 |
48 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) | 50 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
49 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { | 51 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
50 if (!IS_UNDEFINED(byteOffset)) { | 52 if (!IS_UNDEFINED(byteOffset)) { |
51 byteOffset = | 53 byteOffset = |
52 $toPositiveInteger(byteOffset, kInvalidTypedArrayLength); | 54 $toPositiveInteger(byteOffset, kInvalidTypedArrayLength); |
53 } | 55 } |
54 if (!IS_UNDEFINED(length)) { | 56 if (!IS_UNDEFINED(length)) { |
55 length = $toPositiveInteger(length, kInvalidTypedArrayLength); | 57 length = $toPositiveInteger(length, kInvalidTypedArrayLength); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 125 } |
124 if (!initialized) { | 126 if (!initialized) { |
125 for (var i = 0; i < l; i++) { | 127 for (var i = 0; i < l; i++) { |
126 // It is crucial that we let any execptions from arrayLike[i] | 128 // It is crucial that we let any execptions from arrayLike[i] |
127 // propagate outside the function. | 129 // propagate outside the function. |
128 obj[i] = arrayLike[i]; | 130 obj[i] = arrayLike[i]; |
129 } | 131 } |
130 } | 132 } |
131 } | 133 } |
132 | 134 |
| 135 function NAMEConstructByIterable(obj, iterable, iteratorFn) { |
| 136 var list = new InternalArray(); |
| 137 // Reading the Symbol.iterator property of iterable twice would be |
| 138 // observable with getters, so instead, we call the function which |
| 139 // was already looked up, and wrap it in another iterable. The |
| 140 // __proto__ of the new iterable is set to null to avoid any chance |
| 141 // of modifications to Object.prototype being observable here. |
| 142 var iterator = %_CallFunction(iterable, iteratorFn); |
| 143 var newIterable = { |
| 144 __proto__: null, |
| 145 [symbolIterator]() { return iterator; } |
| 146 }; |
| 147 for (var value of newIterable) { |
| 148 list.push(value); |
| 149 } |
| 150 NAMEConstructByArrayLike(obj, list); |
| 151 } |
| 152 |
133 function NAMEConstructor(arg1, arg2, arg3) { | 153 function NAMEConstructor(arg1, arg2, arg3) { |
134 if (%_IsConstructCall()) { | 154 if (%_IsConstructCall()) { |
135 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { | 155 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { |
136 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); | 156 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); |
137 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || | 157 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || |
138 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { | 158 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { |
139 NAMEConstructByLength(this, arg1); | 159 NAMEConstructByLength(this, arg1); |
140 } else { | 160 } else { |
141 NAMEConstructByArrayLike(this, arg1); | 161 var iteratorFn = arg1[symbolIterator]; |
| 162 if (IS_UNDEFINED(iteratorFn) || iteratorFn === $arrayValues) { |
| 163 NAMEConstructByArrayLike(this, arg1); |
| 164 } else { |
| 165 NAMEConstructByIterable(this, arg1, iteratorFn); |
| 166 } |
142 } | 167 } |
143 } else { | 168 } else { |
144 throw MakeTypeError(kConstructorNotFunction, "NAME") | 169 throw MakeTypeError(kConstructorNotFunction, "NAME") |
145 } | 170 } |
146 } | 171 } |
147 | 172 |
148 function NAME_GetBuffer() { | 173 function NAME_GetBuffer() { |
149 if (!(%_ClassOf(this) === 'NAME')) { | 174 if (!(%_ClassOf(this) === 'NAME')) { |
150 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.buffer", this); | 175 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.buffer", this); |
151 } | 176 } |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 "setUint32", DataViewSetUint32JS, | 498 "setUint32", DataViewSetUint32JS, |
474 | 499 |
475 "getFloat32", DataViewGetFloat32JS, | 500 "getFloat32", DataViewGetFloat32JS, |
476 "setFloat32", DataViewSetFloat32JS, | 501 "setFloat32", DataViewSetFloat32JS, |
477 | 502 |
478 "getFloat64", DataViewGetFloat64JS, | 503 "getFloat64", DataViewGetFloat64JS, |
479 "setFloat64", DataViewSetFloat64JS | 504 "setFloat64", DataViewSetFloat64JS |
480 ]); | 505 ]); |
481 | 506 |
482 }) | 507 }) |
OLD | NEW |