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 var iterator = %_CallFunction(iterable, iteratorFn); | |
138 var current = iterator.next(); | |
139 while (!current.done) { | |
arv (Not doing code reviews)
2015/06/12 10:04:50
The main benefit of using for-of is that you get e
| |
140 list.push(current.value); | |
caitp (gmail)
2015/06/12 02:47:21
Sorry to nitpick, but this is missing a piece of t
Dan Ehrenberg
2015/06/12 15:30:54
Done.
| |
141 current = iterator.next(); | |
142 } | |
143 NAMEConstructByArrayLike(obj, list); | |
144 } | |
145 | |
133 function NAMEConstructor(arg1, arg2, arg3) { | 146 function NAMEConstructor(arg1, arg2, arg3) { |
134 if (%_IsConstructCall()) { | 147 if (%_IsConstructCall()) { |
135 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { | 148 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { |
136 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); | 149 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); |
137 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || | 150 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || |
138 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { | 151 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { |
139 NAMEConstructByLength(this, arg1); | 152 NAMEConstructByLength(this, arg1); |
140 } else { | 153 } else { |
141 NAMEConstructByArrayLike(this, arg1); | 154 var iteratorFn = arg1[symbolIterator]; |
155 if (IS_UNDEFINED(iteratorFn) || iteratorFn === $arrayValues) { | |
156 NAMEConstructByArrayLike(this, arg1); | |
157 } else { | |
158 // TODO(littledan): The code here is lazy and looks up @@iterator | |
159 // twice. Currently, that's fine, but it'll be observable with proxies. | |
160 NAMEConstructByIterable(this, arg1, iteratorFn); | |
161 } | |
142 } | 162 } |
143 } else { | 163 } else { |
144 throw MakeTypeError(kConstructorNotFunction, "NAME") | 164 throw MakeTypeError(kConstructorNotFunction, "NAME") |
145 } | 165 } |
146 } | 166 } |
147 | 167 |
148 function NAME_GetBuffer() { | 168 function NAME_GetBuffer() { |
149 if (!(%_ClassOf(this) === 'NAME')) { | 169 if (!(%_ClassOf(this) === 'NAME')) { |
150 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.buffer", this); | 170 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.buffer", this); |
151 } | 171 } |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 "setUint32", DataViewSetUint32JS, | 493 "setUint32", DataViewSetUint32JS, |
474 | 494 |
475 "getFloat32", DataViewGetFloat32JS, | 495 "getFloat32", DataViewGetFloat32JS, |
476 "setFloat32", DataViewSetFloat32JS, | 496 "setFloat32", DataViewSetFloat32JS, |
477 | 497 |
478 "getFloat64", DataViewGetFloat64JS, | 498 "getFloat64", DataViewGetFloat64JS, |
479 "setFloat64", DataViewSetFloat64JS | 499 "setFloat64", DataViewSetFloat64JS |
480 ]); | 500 ]); |
481 | 501 |
482 }) | 502 }) |
OLD | NEW |