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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 if (bufferByteLength % elementSize !== 0) { | 103 if (bufferByteLength % elementSize !== 0) { |
104 throw MakeRangeError("invalid_typed_array_alignment", | 104 throw MakeRangeError("invalid_typed_array_alignment", |
105 "byte length", name, elementSize); | 105 "byte length", name, elementSize); |
106 } | 106 } |
107 newByteLength = bufferByteLength - offset; | 107 newByteLength = bufferByteLength - offset; |
108 newLength = newByteLength / elementSize; | 108 newLength = newByteLength / elementSize; |
109 } else { | 109 } else { |
110 var newLength = TO_POSITIVE_INTEGER(length); | 110 var newLength = TO_POSITIVE_INTEGER(length); |
111 newByteLength = newLength * elementSize; | 111 newByteLength = newLength * elementSize; |
112 } | 112 } |
113 if (newByteLength > bufferByteLength) { | 113 if (offset + newByteLength > bufferByteLength) { |
114 throw MakeRangeError("invalid_typed_array_length"); | 114 throw MakeRangeError("invalid_typed_array_length"); |
115 } | 115 } |
116 %TypedArrayInitialize(obj, arrayId, buffer, offset, newByteLength); | 116 %TypedArrayInitialize(obj, arrayId, buffer, offset, newByteLength); |
117 } | 117 } |
118 | 118 |
119 function ConstructByLength(obj, length) { | 119 function ConstructByLength(obj, length) { |
120 var l = IS_UNDEFINED(length) ? 0 : TO_POSITIVE_INTEGER(length); | 120 var l = IS_UNDEFINED(length) ? 0 : TO_POSITIVE_INTEGER(length); |
121 var byteLength = l * elementSize; | 121 var byteLength = l * elementSize; |
122 var buffer = new $ArrayBuffer(byteLength); | 122 var buffer = new $ArrayBuffer(byteLength); |
123 %TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength); | 123 %TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. | 210 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
211 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); | 211 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); |
212 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); | 212 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); |
213 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); | 213 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); |
214 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); | 214 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); |
215 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); | 215 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); |
216 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); | 216 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); |
217 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); | 217 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); |
218 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); | 218 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); |
219 SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1); | 219 SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1); |
OLD | NEW |