| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 var byteLength = l * ELEMENT_SIZE; | 194 var byteLength = l * ELEMENT_SIZE; |
| 195 if (byteLength > %_TypedArrayMaxSizeInHeap()) { | 195 if (byteLength > %_TypedArrayMaxSizeInHeap()) { |
| 196 var buffer = new GlobalArrayBuffer(byteLength); | 196 var buffer = new GlobalArrayBuffer(byteLength); |
| 197 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength, true); | 197 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength, true); |
| 198 } else { | 198 } else { |
| 199 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, true); | 199 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, true); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 function NAMEConstructByArrayLike(obj, arrayLike) { | 203 function NAMEConstructByArrayLike(obj, arrayLike, length) { |
| 204 var length = arrayLike.length; | |
| 205 var l = ToPositiveInteger(length, kInvalidTypedArrayLength); | 204 var l = ToPositiveInteger(length, kInvalidTypedArrayLength); |
| 206 | 205 |
| 207 if (l > %_MaxSmi()) { | 206 if (l > %_MaxSmi()) { |
| 208 throw MakeRangeError(kInvalidTypedArrayLength); | 207 throw MakeRangeError(kInvalidTypedArrayLength); |
| 209 } | 208 } |
| 210 var initialized = false; | 209 var initialized = false; |
| 211 var byteLength = l * ELEMENT_SIZE; | 210 var byteLength = l * ELEMENT_SIZE; |
| 212 if (byteLength <= %_TypedArrayMaxSizeInHeap()) { | 211 if (byteLength <= %_TypedArrayMaxSizeInHeap()) { |
| 213 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, false); | 212 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, false); |
| 214 } else { | 213 } else { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 234 var iterator = %_Call(iteratorFn, iterable); | 233 var iterator = %_Call(iteratorFn, iterable); |
| 235 var newIterable = { | 234 var newIterable = { |
| 236 __proto__: null | 235 __proto__: null |
| 237 }; | 236 }; |
| 238 // TODO(littledan): Computed properties don't work yet in nosnap. | 237 // TODO(littledan): Computed properties don't work yet in nosnap. |
| 239 // Rephrase when they do. | 238 // Rephrase when they do. |
| 240 newIterable[iteratorSymbol] = function() { return iterator; } | 239 newIterable[iteratorSymbol] = function() { return iterator; } |
| 241 for (var value of newIterable) { | 240 for (var value of newIterable) { |
| 242 list.push(value); | 241 list.push(value); |
| 243 } | 242 } |
| 244 NAMEConstructByArrayLike(obj, list); | 243 NAMEConstructByArrayLike(obj, list, list.length); |
| 245 } | 244 } |
| 246 | 245 |
| 247 // ES#sec-typedarray-typedarray TypedArray ( typedArray ) | 246 // ES#sec-typedarray-typedarray TypedArray ( typedArray ) |
| 248 function NAMEConstructByTypedArray(obj, typedArray) { | 247 function NAMEConstructByTypedArray(obj, typedArray) { |
| 249 // TODO(littledan): Throw on detached typedArray | 248 // TODO(littledan): Throw on detached typedArray |
| 250 var srcData = %TypedArrayGetBuffer(typedArray); | 249 var srcData = %TypedArrayGetBuffer(typedArray); |
| 251 var length = %_TypedArrayGetLength(typedArray); | 250 var length = %_TypedArrayGetLength(typedArray); |
| 252 var byteLength = %_ArrayBufferViewGetByteLength(typedArray); | 251 var byteLength = %_ArrayBufferViewGetByteLength(typedArray); |
| 253 var newByteLength = length * ELEMENT_SIZE; | 252 var newByteLength = length * ELEMENT_SIZE; |
| 253 NAMEConstructByArrayLike(obj, typedArray, length); |
| 254 var bufferConstructor = SpeciesConstructor(srcData, GlobalArrayBuffer); | 254 var bufferConstructor = SpeciesConstructor(srcData, GlobalArrayBuffer); |
| 255 var data = new GlobalArrayBuffer(newByteLength); | |
| 256 var prototype = bufferConstructor.prototype; | 255 var prototype = bufferConstructor.prototype; |
| 257 // TODO(littledan): Use the right prototype based on bufferConstructor's realm | 256 // TODO(littledan): Use the right prototype based on bufferConstructor's realm |
| 258 if (IS_RECEIVER(prototype) && prototype !== GlobalArrayBufferPrototype) { | 257 if (IS_RECEIVER(prototype) && prototype !== GlobalArrayBufferPrototype) { |
| 259 %InternalSetPrototype(data, prototype); | 258 %InternalSetPrototype(%TypedArrayGetBuffer(obj), prototype); |
| 260 } | |
| 261 %_TypedArrayInitialize(obj, ARRAY_ID, data, 0, newByteLength, true); | |
| 262 // Note: The separate CloneArrayBuffer path in the spec ensures | |
| 263 // that NaNs are not canonicalized, but because V8 does not | |
| 264 // canonicalize NaNs, we do not have to do anything different. | |
| 265 // TODO(littledan): Make a fastpath based on memcpy | |
| 266 for (var i = 0; i < length; i++) { | |
| 267 obj[i] = typedArray[i]; | |
| 268 } | 259 } |
| 269 } | 260 } |
| 270 | 261 |
| 271 function NAMEConstructor(arg1, arg2, arg3) { | 262 function NAMEConstructor(arg1, arg2, arg3) { |
| 272 if (!IS_UNDEFINED(new.target)) { | 263 if (!IS_UNDEFINED(new.target)) { |
| 273 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { | 264 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { |
| 274 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); | 265 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); |
| 275 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || | 266 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || |
| 276 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { | 267 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { |
| 277 NAMEConstructByLength(this, arg1); | 268 NAMEConstructByLength(this, arg1); |
| 278 } else if (IS_TYPEDARRAY(arg1)) { | 269 } else if (IS_TYPEDARRAY(arg1)) { |
| 279 NAMEConstructByTypedArray(this, arg1); | 270 NAMEConstructByTypedArray(this, arg1); |
| 280 } else { | 271 } else { |
| 281 var iteratorFn = arg1[iteratorSymbol]; | 272 var iteratorFn = arg1[iteratorSymbol]; |
| 282 if (IS_UNDEFINED(iteratorFn) || iteratorFn === ArrayValues) { | 273 if (IS_UNDEFINED(iteratorFn)) { |
| 283 NAMEConstructByArrayLike(this, arg1); | 274 NAMEConstructByArrayLike(this, arg1, arg1.length); |
| 284 } else { | 275 } else { |
| 285 NAMEConstructByIterable(this, arg1, iteratorFn); | 276 NAMEConstructByIterable(this, arg1, iteratorFn); |
| 286 } | 277 } |
| 287 } | 278 } |
| 288 } else { | 279 } else { |
| 289 throw MakeTypeError(kConstructorNotFunction, "NAME") | 280 throw MakeTypeError(kConstructorNotFunction, "NAME") |
| 290 } | 281 } |
| 291 } | 282 } |
| 292 | 283 |
| 293 // TODO(littledan): Remove this performance workaround BUG(chromium:579905) | 284 // TODO(littledan): Remove this performance workaround BUG(chromium:579905) |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 "setUint32", DataViewSetUint32JS, | 997 "setUint32", DataViewSetUint32JS, |
| 1007 | 998 |
| 1008 "getFloat32", DataViewGetFloat32JS, | 999 "getFloat32", DataViewGetFloat32JS, |
| 1009 "setFloat32", DataViewSetFloat32JS, | 1000 "setFloat32", DataViewSetFloat32JS, |
| 1010 | 1001 |
| 1011 "getFloat64", DataViewGetFloat64JS, | 1002 "getFloat64", DataViewGetFloat64JS, |
| 1012 "setFloat64", DataViewSetFloat64JS | 1003 "setFloat64", DataViewSetFloat64JS |
| 1013 ]); | 1004 ]); |
| 1014 | 1005 |
| 1015 }) | 1006 }) |
| OLD | NEW |