| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 FUNCTION(3, Uint16Array, 2) | 41 FUNCTION(3, Uint16Array, 2) |
| 42 FUNCTION(4, Int16Array, 2) | 42 FUNCTION(4, Int16Array, 2) |
| 43 FUNCTION(5, Uint32Array, 4) | 43 FUNCTION(5, Uint32Array, 4) |
| 44 FUNCTION(6, Int32Array, 4) | 44 FUNCTION(6, Int32Array, 4) |
| 45 FUNCTION(7, Float32Array, 4) | 45 FUNCTION(7, Float32Array, 4) |
| 46 FUNCTION(8, Float64Array, 8) | 46 FUNCTION(8, Float64Array, 8) |
| 47 FUNCTION(9, Uint8ClampedArray, 1) | 47 FUNCTION(9, Uint8ClampedArray, 1) |
| 48 endmacro | 48 endmacro |
| 49 | 49 |
| 50 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) | 50 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 51 function NAMEConstructor(arg1, arg2, arg3) { | 51 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
| 52 function ConstructByArrayBuffer(obj, buffer, byteOffset, length) { | 52 var offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length") |
| 53 var offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length") | |
| 54 | 53 |
| 55 if (offset % ELEMENT_SIZE !== 0) { | 54 if (offset % ELEMENT_SIZE !== 0) { |
| 56 throw MakeRangeError("invalid_typed_array_alignment", | 55 throw MakeRangeError("invalid_typed_array_alignment", |
| 57 "start offset", "NAME", ELEMENT_SIZE); | 56 "start offset", "NAME", ELEMENT_SIZE); |
| 58 } | 57 } |
| 59 var bufferByteLength = %ArrayBufferGetByteLength(buffer); | 58 var bufferByteLength = buffer.byteLength; |
| 60 if (offset > bufferByteLength) { | 59 if (offset > bufferByteLength) { |
| 61 throw MakeRangeError("invalid_typed_array_offset"); | 60 throw MakeRangeError("invalid_typed_array_offset"); |
| 62 } | |
| 63 | |
| 64 var newByteLength; | |
| 65 var newLength; | |
| 66 if (IS_UNDEFINED(length)) { | |
| 67 if (bufferByteLength % ELEMENT_SIZE !== 0) { | |
| 68 throw MakeRangeError("invalid_typed_array_alignment", | |
| 69 "byte length", "NAME", ELEMENT_SIZE); | |
| 70 } | |
| 71 newByteLength = bufferByteLength - offset; | |
| 72 newLength = newByteLength / ELEMENT_SIZE; | |
| 73 } else { | |
| 74 var newLength = ToPositiveInteger(length, "invalid_typed_array_length"); | |
| 75 newByteLength = newLength * ELEMENT_SIZE; | |
| 76 } | |
| 77 if (offset + newByteLength > bufferByteLength) { | |
| 78 throw MakeRangeError("invalid_typed_array_length"); | |
| 79 } | |
| 80 %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); | |
| 81 } | 61 } |
| 82 | 62 |
| 83 function ConstructByLength(obj, length) { | 63 var newByteLength; |
| 84 var l = ToPositiveInteger(length, "invalid_typed_array_length"); | 64 var newLength; |
| 85 var byteLength = l * ELEMENT_SIZE; | 65 if (IS_UNDEFINED(length)) { |
| 86 var buffer = new $ArrayBuffer(byteLength); | 66 if (bufferByteLength % ELEMENT_SIZE !== 0) { |
| 87 %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); | 67 throw MakeRangeError("invalid_typed_array_alignment", |
| 68 "byte length", "NAME", ELEMENT_SIZE); |
| 69 } |
| 70 newByteLength = bufferByteLength - offset; |
| 71 newLength = newByteLength / ELEMENT_SIZE; |
| 72 } else { |
| 73 var newLength = ToPositiveInteger(length, "invalid_typed_array_length"); |
| 74 newByteLength = newLength * ELEMENT_SIZE; |
| 88 } | 75 } |
| 76 if (offset + newByteLength > bufferByteLength) { |
| 77 throw MakeRangeError("invalid_typed_array_length"); |
| 78 } |
| 79 %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); |
| 80 } |
| 89 | 81 |
| 90 function ConstructByArrayLike(obj, arrayLike) { | 82 function NAMEConstructByLength(obj, length) { |
| 91 var length = arrayLike.length; | 83 var l = ToPositiveInteger(length, "invalid_typed_array_length"); |
| 92 var l = ToPositiveInteger(length, "invalid_typed_array_length"); | 84 var byteLength = l * ELEMENT_SIZE; |
| 93 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { | 85 var buffer = new $ArrayBuffer(byteLength); |
| 94 for (var i = 0; i < l; i++) { | 86 %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); |
| 95 // It is crucial that we let any execptions from arrayLike[i] | 87 } |
| 96 // propagate outside the function. | 88 |
| 97 obj[i] = arrayLike[i]; | 89 function NAMEConstructByArrayLike(obj, arrayLike) { |
| 98 } | 90 var length = arrayLike.length; |
| 91 var l = ToPositiveInteger(length, "invalid_typed_array_length"); |
| 92 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { |
| 93 for (var i = 0; i < l; i++) { |
| 94 // It is crucial that we let any execptions from arrayLike[i] |
| 95 // propagate outside the function. |
| 96 obj[i] = arrayLike[i]; |
| 99 } | 97 } |
| 100 } | 98 } |
| 99 } |
| 100 |
| 101 function NAMEConstructor(arg1, arg2, arg3) { |
| 101 | 102 |
| 102 if (%_IsConstructCall()) { | 103 if (%_IsConstructCall()) { |
| 103 if (IS_ARRAYBUFFER(arg1)) { | 104 if (IS_ARRAYBUFFER(arg1)) { |
| 104 ConstructByArrayBuffer(this, arg1, arg2, arg3); | 105 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); |
| 105 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || | 106 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || |
| 106 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { | 107 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { |
| 107 ConstructByLength(this, arg1); | 108 NAMEConstructByLength(this, arg1); |
| 108 } else { | 109 } else { |
| 109 ConstructByArrayLike(this, arg1); | 110 NAMEConstructByArrayLike(this, arg1); |
| 110 } | 111 } |
| 111 } else { | 112 } else { |
| 112 throw MakeTypeError("constructor_not_function", ["NAME"]) | 113 throw MakeTypeError("constructor_not_function", ["NAME"]) |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 endmacro | 116 endmacro |
| 116 | 117 |
| 117 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) | 118 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) |
| 118 | 119 |
| 119 function TypedArrayGetBuffer() { | 120 function TypedArrayGetBuffer() { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 InstallGetter(constructor.prototype, "byteOffset", TypedArrayGetByteOffset); | 278 InstallGetter(constructor.prototype, "byteOffset", TypedArrayGetByteOffset); |
| 278 InstallGetter(constructor.prototype, "byteLength", TypedArrayGetByteLength); | 279 InstallGetter(constructor.prototype, "byteLength", TypedArrayGetByteLength); |
| 279 InstallGetter(constructor.prototype, "length", TypedArrayGetLength); | 280 InstallGetter(constructor.prototype, "length", TypedArrayGetLength); |
| 280 | 281 |
| 281 InstallFunctions(constructor.prototype, DONT_ENUM, $Array( | 282 InstallFunctions(constructor.prototype, DONT_ENUM, $Array( |
| 282 "subarray", CreateSubArray(elementSize, constructor), | 283 "subarray", CreateSubArray(elementSize, constructor), |
| 283 "set", TypedArraySet | 284 "set", TypedArraySet |
| 284 )); | 285 )); |
| 285 } | 286 } |
| 286 | 287 |
| 287 | |
| 288 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) | 288 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 289 SetupTypedArray (global.NAME, NAMEConstructor, ELEMENT_SIZE); | 289 SetupTypedArray (global.NAME, NAMEConstructor, ELEMENT_SIZE); |
| 290 endmacro | 290 endmacro |
| 291 | 291 |
| 292 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 292 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
| 293 | 293 |
| 294 // --------------------------- DataView ----------------------------- | 294 // --------------------------- DataView ----------------------------- |
| 295 | 295 |
| 296 var $DataView = global.DataView; | 296 var $DataView = global.DataView; |
| 297 | 297 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 | 595 |
| 596 "getFloat32", DataViewGetFloat32, | 596 "getFloat32", DataViewGetFloat32, |
| 597 "setFloat32", DataViewSetFloat32, | 597 "setFloat32", DataViewSetFloat32, |
| 598 | 598 |
| 599 "getFloat64", DataViewGetFloat64, | 599 "getFloat64", DataViewGetFloat64, |
| 600 "setFloat64", DataViewSetFloat64 | 600 "setFloat64", DataViewSetFloat64 |
| 601 )); | 601 )); |
| 602 } | 602 } |
| 603 | 603 |
| 604 SetupDataView(); | 604 SetupDataView(); |
| OLD | NEW |