| 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 |
| 11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
| 12 // Imports | 12 // Imports |
| 13 | 13 |
| 14 var ArrayValues; |
| 14 var GlobalArray = global.Array; | 15 var GlobalArray = global.Array; |
| 15 var GlobalArrayBuffer = global.ArrayBuffer; | 16 var GlobalArrayBuffer = global.ArrayBuffer; |
| 16 var GlobalDataView = global.DataView; | 17 var GlobalDataView = global.DataView; |
| 17 var GlobalObject = global.Object; | 18 var GlobalObject = global.Object; |
| 19 var InternalArray = utils.InternalArray; |
| 18 var iteratorSymbol = utils.ImportNow("iterator_symbol"); | 20 var iteratorSymbol = utils.ImportNow("iterator_symbol"); |
| 21 var ToPositiveInteger; |
| 19 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 22 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
| 20 | 23 |
| 21 macro TYPED_ARRAYS(FUNCTION) | 24 macro TYPED_ARRAYS(FUNCTION) |
| 22 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. | 25 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
| 23 FUNCTION(1, Uint8Array, 1) | 26 FUNCTION(1, Uint8Array, 1) |
| 24 FUNCTION(2, Int8Array, 1) | 27 FUNCTION(2, Int8Array, 1) |
| 25 FUNCTION(3, Uint16Array, 2) | 28 FUNCTION(3, Uint16Array, 2) |
| 26 FUNCTION(4, Int16Array, 2) | 29 FUNCTION(4, Int16Array, 2) |
| 27 FUNCTION(5, Uint32Array, 4) | 30 FUNCTION(5, Uint32Array, 4) |
| 28 FUNCTION(6, Int32Array, 4) | 31 FUNCTION(6, Int32Array, 4) |
| 29 FUNCTION(7, Float32Array, 4) | 32 FUNCTION(7, Float32Array, 4) |
| 30 FUNCTION(8, Float64Array, 8) | 33 FUNCTION(8, Float64Array, 8) |
| 31 FUNCTION(9, Uint8ClampedArray, 1) | 34 FUNCTION(9, Uint8ClampedArray, 1) |
| 32 endmacro | 35 endmacro |
| 33 | 36 |
| 34 macro DECLARE_GLOBALS(INDEX, NAME, SIZE) | 37 macro DECLARE_GLOBALS(INDEX, NAME, SIZE) |
| 35 var GlobalNAME = global.NAME; | 38 var GlobalNAME = global.NAME; |
| 36 endmacro | 39 endmacro |
| 37 | 40 |
| 38 TYPED_ARRAYS(DECLARE_GLOBALS) | 41 TYPED_ARRAYS(DECLARE_GLOBALS) |
| 39 | 42 |
| 40 var InternalArray = utils.InternalArray; | 43 utils.Import(function(from) { |
| 44 ArrayValues = from.ArrayValues; |
| 45 ToPositiveInteger = from.ToPositiveInteger; |
| 46 }); |
| 41 | 47 |
| 42 // --------------- Typed Arrays --------------------- | 48 // --------------- Typed Arrays --------------------- |
| 43 | 49 |
| 44 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) | 50 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 45 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { | 51 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
| 46 if (!IS_UNDEFINED(byteOffset)) { | 52 if (!IS_UNDEFINED(byteOffset)) { |
| 47 byteOffset = | 53 byteOffset = ToPositiveInteger(byteOffset, kInvalidTypedArrayLength); |
| 48 $toPositiveInteger(byteOffset, kInvalidTypedArrayLength); | |
| 49 } | 54 } |
| 50 if (!IS_UNDEFINED(length)) { | 55 if (!IS_UNDEFINED(length)) { |
| 51 length = $toPositiveInteger(length, kInvalidTypedArrayLength); | 56 length = ToPositiveInteger(length, kInvalidTypedArrayLength); |
| 52 } | 57 } |
| 53 | 58 |
| 54 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); | 59 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); |
| 55 var offset; | 60 var offset; |
| 56 if (IS_UNDEFINED(byteOffset)) { | 61 if (IS_UNDEFINED(byteOffset)) { |
| 57 offset = 0; | 62 offset = 0; |
| 58 } else { | 63 } else { |
| 59 offset = byteOffset; | 64 offset = byteOffset; |
| 60 | 65 |
| 61 if (offset % ELEMENT_SIZE !== 0) { | 66 if (offset % ELEMENT_SIZE !== 0) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 82 } | 87 } |
| 83 if ((offset + newByteLength > bufferByteLength) | 88 if ((offset + newByteLength > bufferByteLength) |
| 84 || (newLength > %_MaxSmi())) { | 89 || (newLength > %_MaxSmi())) { |
| 85 throw MakeRangeError(kInvalidTypedArrayLength); | 90 throw MakeRangeError(kInvalidTypedArrayLength); |
| 86 } | 91 } |
| 87 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength, true); | 92 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength, true); |
| 88 } | 93 } |
| 89 | 94 |
| 90 function NAMEConstructByLength(obj, length) { | 95 function NAMEConstructByLength(obj, length) { |
| 91 var l = IS_UNDEFINED(length) ? | 96 var l = IS_UNDEFINED(length) ? |
| 92 0 : $toPositiveInteger(length, kInvalidTypedArrayLength); | 97 0 : ToPositiveInteger(length, kInvalidTypedArrayLength); |
| 93 if (l > %_MaxSmi()) { | 98 if (l > %_MaxSmi()) { |
| 94 throw MakeRangeError(kInvalidTypedArrayLength); | 99 throw MakeRangeError(kInvalidTypedArrayLength); |
| 95 } | 100 } |
| 96 var byteLength = l * ELEMENT_SIZE; | 101 var byteLength = l * ELEMENT_SIZE; |
| 97 if (byteLength > %_TypedArrayMaxSizeInHeap()) { | 102 if (byteLength > %_TypedArrayMaxSizeInHeap()) { |
| 98 var buffer = new GlobalArrayBuffer(byteLength); | 103 var buffer = new GlobalArrayBuffer(byteLength); |
| 99 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength, true); | 104 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength, true); |
| 100 } else { | 105 } else { |
| 101 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, true); | 106 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, true); |
| 102 } | 107 } |
| 103 } | 108 } |
| 104 | 109 |
| 105 function NAMEConstructByArrayLike(obj, arrayLike) { | 110 function NAMEConstructByArrayLike(obj, arrayLike) { |
| 106 var length = arrayLike.length; | 111 var length = arrayLike.length; |
| 107 var l = $toPositiveInteger(length, kInvalidTypedArrayLength); | 112 var l = ToPositiveInteger(length, kInvalidTypedArrayLength); |
| 108 | 113 |
| 109 if (l > %_MaxSmi()) { | 114 if (l > %_MaxSmi()) { |
| 110 throw MakeRangeError(kInvalidTypedArrayLength); | 115 throw MakeRangeError(kInvalidTypedArrayLength); |
| 111 } | 116 } |
| 112 var initialized = false; | 117 var initialized = false; |
| 113 var byteLength = l * ELEMENT_SIZE; | 118 var byteLength = l * ELEMENT_SIZE; |
| 114 if (byteLength <= %_TypedArrayMaxSizeInHeap()) { | 119 if (byteLength <= %_TypedArrayMaxSizeInHeap()) { |
| 115 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, false); | 120 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, false); |
| 116 } else { | 121 } else { |
| 117 initialized = | 122 initialized = |
| (...skipping 30 matching lines...) Expand all Loading... |
| 148 | 153 |
| 149 function NAMEConstructor(arg1, arg2, arg3) { | 154 function NAMEConstructor(arg1, arg2, arg3) { |
| 150 if (%_IsConstructCall()) { | 155 if (%_IsConstructCall()) { |
| 151 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { | 156 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { |
| 152 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); | 157 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); |
| 153 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || | 158 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || |
| 154 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { | 159 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { |
| 155 NAMEConstructByLength(this, arg1); | 160 NAMEConstructByLength(this, arg1); |
| 156 } else { | 161 } else { |
| 157 var iteratorFn = arg1[iteratorSymbol]; | 162 var iteratorFn = arg1[iteratorSymbol]; |
| 158 if (IS_UNDEFINED(iteratorFn) || iteratorFn === $arrayValues) { | 163 if (IS_UNDEFINED(iteratorFn) || iteratorFn === ArrayValues) { |
| 159 NAMEConstructByArrayLike(this, arg1); | 164 NAMEConstructByArrayLike(this, arg1); |
| 160 } else { | 165 } else { |
| 161 NAMEConstructByIterable(this, arg1, iteratorFn); | 166 NAMEConstructByIterable(this, arg1, iteratorFn); |
| 162 } | 167 } |
| 163 } | 168 } |
| 164 } else { | 169 } else { |
| 165 throw MakeTypeError(kConstructorNotFunction, "NAME") | 170 throw MakeTypeError(kConstructorNotFunction, "NAME") |
| 166 } | 171 } |
| 167 } | 172 } |
| 168 | 173 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 379 |
| 375 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 380 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
| 376 | 381 |
| 377 // --------------------------- DataView ----------------------------- | 382 // --------------------------- DataView ----------------------------- |
| 378 | 383 |
| 379 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 | 384 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |
| 380 if (%_IsConstructCall()) { | 385 if (%_IsConstructCall()) { |
| 381 // TODO(binji): support SharedArrayBuffers? | 386 // TODO(binji): support SharedArrayBuffers? |
| 382 if (!IS_ARRAYBUFFER(buffer)) throw MakeTypeError(kDataViewNotArrayBuffer); | 387 if (!IS_ARRAYBUFFER(buffer)) throw MakeTypeError(kDataViewNotArrayBuffer); |
| 383 if (!IS_UNDEFINED(byteOffset)) { | 388 if (!IS_UNDEFINED(byteOffset)) { |
| 384 byteOffset = $toPositiveInteger(byteOffset, kInvalidDataViewOffset); | 389 byteOffset = ToPositiveInteger(byteOffset, kInvalidDataViewOffset); |
| 385 } | 390 } |
| 386 if (!IS_UNDEFINED(byteLength)) { | 391 if (!IS_UNDEFINED(byteLength)) { |
| 387 byteLength = TO_INTEGER(byteLength); | 392 byteLength = TO_INTEGER(byteLength); |
| 388 } | 393 } |
| 389 | 394 |
| 390 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); | 395 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); |
| 391 | 396 |
| 392 var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset; | 397 var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset; |
| 393 if (offset > bufferByteLength) throw MakeRangeError(kInvalidDataViewOffset); | 398 if (offset > bufferByteLength) throw MakeRangeError(kInvalidDataViewOffset); |
| 394 | 399 |
| 395 var length = IS_UNDEFINED(byteLength) | 400 var length = IS_UNDEFINED(byteLength) |
| 396 ? bufferByteLength - offset | 401 ? bufferByteLength - offset |
| 397 : byteLength; | 402 : byteLength; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 endmacro | 444 endmacro |
| 440 | 445 |
| 441 | 446 |
| 442 macro DATA_VIEW_GETTER_SETTER(TYPENAME) | 447 macro DATA_VIEW_GETTER_SETTER(TYPENAME) |
| 443 function DataViewGetTYPENAMEJS(offset, little_endian) { | 448 function DataViewGetTYPENAMEJS(offset, little_endian) { |
| 444 if (!IS_DATAVIEW(this)) { | 449 if (!IS_DATAVIEW(this)) { |
| 445 throw MakeTypeError(kIncompatibleMethodReceiver, | 450 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 446 'DataView.getTYPENAME', this); | 451 'DataView.getTYPENAME', this); |
| 447 } | 452 } |
| 448 if (%_ArgumentsLength() < 1) throw MakeTypeError(kInvalidArgument); | 453 if (%_ArgumentsLength() < 1) throw MakeTypeError(kInvalidArgument); |
| 449 offset = $toPositiveInteger(offset, kInvalidDataViewAccessorOffset); | 454 offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); |
| 450 return %DataViewGetTYPENAME(this, offset, !!little_endian); | 455 return %DataViewGetTYPENAME(this, offset, !!little_endian); |
| 451 } | 456 } |
| 452 | 457 |
| 453 function DataViewSetTYPENAMEJS(offset, value, little_endian) { | 458 function DataViewSetTYPENAMEJS(offset, value, little_endian) { |
| 454 if (!IS_DATAVIEW(this)) { | 459 if (!IS_DATAVIEW(this)) { |
| 455 throw MakeTypeError(kIncompatibleMethodReceiver, | 460 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 456 'DataView.setTYPENAME', this); | 461 'DataView.setTYPENAME', this); |
| 457 } | 462 } |
| 458 if (%_ArgumentsLength() < 2) throw MakeTypeError(kInvalidArgument); | 463 if (%_ArgumentsLength() < 2) throw MakeTypeError(kInvalidArgument); |
| 459 offset = $toPositiveInteger(offset, kInvalidDataViewAccessorOffset); | 464 offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); |
| 460 %DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian); | 465 %DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian); |
| 461 } | 466 } |
| 462 endmacro | 467 endmacro |
| 463 | 468 |
| 464 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) | 469 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) |
| 465 | 470 |
| 466 // Setup the DataView constructor. | 471 // Setup the DataView constructor. |
| 467 %SetCode(GlobalDataView, DataViewConstructor); | 472 %SetCode(GlobalDataView, DataViewConstructor); |
| 468 %FunctionSetPrototype(GlobalDataView, new GlobalObject); | 473 %FunctionSetPrototype(GlobalDataView, new GlobalObject); |
| 469 | 474 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 499 "setUint32", DataViewSetUint32JS, | 504 "setUint32", DataViewSetUint32JS, |
| 500 | 505 |
| 501 "getFloat32", DataViewGetFloat32JS, | 506 "getFloat32", DataViewGetFloat32JS, |
| 502 "setFloat32", DataViewSetFloat32JS, | 507 "setFloat32", DataViewSetFloat32JS, |
| 503 | 508 |
| 504 "getFloat64", DataViewGetFloat64JS, | 509 "getFloat64", DataViewGetFloat64JS, |
| 505 "setFloat64", DataViewSetFloat64JS | 510 "setFloat64", DataViewSetFloat64JS |
| 506 ]); | 511 ]); |
| 507 | 512 |
| 508 }) | 513 }) |
| OLD | NEW |