Chromium Code Reviews| 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 while (true) { | |
| 139 var current = iterator.next(); | |
| 140 if (!IS_OBJECT(current)) { | |
|
adamk
2015/06/12 18:06:45
I think you want IS_SPEC_OBJECT here.
The proper
Dan Ehrenberg
2015/06/13 00:11:40
How's this, just using for-of with a wrapper? We c
| |
| 141 throw MakeTypeError(kIteratorResultNotAnObject, current); | |
| 142 } | |
| 143 if (current.done) break; | |
| 144 list.push(current.value); | |
| 145 } | |
| 146 NAMEConstructByArrayLike(obj, list); | |
| 147 } | |
| 148 | |
| 133 function NAMEConstructor(arg1, arg2, arg3) { | 149 function NAMEConstructor(arg1, arg2, arg3) { |
| 134 if (%_IsConstructCall()) { | 150 if (%_IsConstructCall()) { |
| 135 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { | 151 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { |
| 136 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); | 152 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); |
| 137 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || | 153 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || |
| 138 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { | 154 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { |
| 139 NAMEConstructByLength(this, arg1); | 155 NAMEConstructByLength(this, arg1); |
| 140 } else { | 156 } else { |
| 141 NAMEConstructByArrayLike(this, arg1); | 157 var iteratorFn = arg1[symbolIterator]; |
| 158 if (IS_UNDEFINED(iteratorFn) || iteratorFn === $arrayValues) { | |
| 159 NAMEConstructByArrayLike(this, arg1); | |
| 160 } else { | |
| 161 // TODO(littledan): The code here is lazy and looks up @@iterator | |
| 162 // twice. Currently, that's fine, but it'll be observable with proxies. | |
| 163 NAMEConstructByIterable(this, arg1, iteratorFn); | |
| 164 } | |
| 142 } | 165 } |
| 143 } else { | 166 } else { |
| 144 throw MakeTypeError(kConstructorNotFunction, "NAME") | 167 throw MakeTypeError(kConstructorNotFunction, "NAME") |
| 145 } | 168 } |
| 146 } | 169 } |
| 147 | 170 |
| 148 function NAME_GetBuffer() { | 171 function NAME_GetBuffer() { |
| 149 if (!(%_ClassOf(this) === 'NAME')) { | 172 if (!(%_ClassOf(this) === 'NAME')) { |
| 150 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.buffer", this); | 173 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.buffer", this); |
| 151 } | 174 } |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 "setUint32", DataViewSetUint32JS, | 496 "setUint32", DataViewSetUint32JS, |
| 474 | 497 |
| 475 "getFloat32", DataViewGetFloat32JS, | 498 "getFloat32", DataViewGetFloat32JS, |
| 476 "setFloat32", DataViewSetFloat32JS, | 499 "setFloat32", DataViewSetFloat32JS, |
| 477 | 500 |
| 478 "getFloat64", DataViewGetFloat64JS, | 501 "getFloat64", DataViewGetFloat64JS, |
| 479 "setFloat64", DataViewSetFloat64JS | 502 "setFloat64", DataViewSetFloat64JS |
| 480 ]); | 503 ]); |
| 481 | 504 |
| 482 }) | 505 }) |
| OLD | NEW |