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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 var result = new $ArrayBuffer(newLen); | 79 var result = new $ArrayBuffer(newLen); |
80 | 80 |
81 %ArrayBufferSliceImpl(this, result, first); | 81 %ArrayBufferSliceImpl(this, result, first); |
82 return result; | 82 return result; |
83 } | 83 } |
84 | 84 |
85 // --------------- Typed Arrays --------------------- | 85 // --------------- Typed Arrays --------------------- |
86 | 86 |
87 function CreateTypedArrayConstructor(name, elementSize, arrayId, constructor) { | 87 function CreateTypedArrayConstructor(name, elementSize, arrayId, constructor) { |
88 function ConstructByArrayBuffer(obj, buffer, byteOffset, length) { | 88 function ConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
89 var offset = IS_UNDEFINED(byteOffset) | 89 var offset = IS_UNDEFINED(byteOffset) ? 0 : TO_POSITIVE_INTEGER(byteOffset); |
90 ? 0 : offset = TO_POSITIVE_INTEGER(byteOffset); | |
91 | 90 |
92 if (offset % elementSize !== 0) { | 91 if (offset % elementSize !== 0) { |
93 throw MakeRangeError("invalid_typed_array_alignment", | 92 throw MakeRangeError("invalid_typed_array_alignment", |
94 "start offset", name, elementSize); | 93 "start offset", name, elementSize); |
95 } | 94 } |
96 var bufferByteLength = %ArrayBufferGetByteLength(buffer); | 95 var bufferByteLength = %ArrayBufferGetByteLength(buffer); |
97 if (offset >= bufferByteLength) { | 96 if (offset >= bufferByteLength) { |
98 throw MakeRangeError("invalid_typed_array_offset"); | 97 throw MakeRangeError("invalid_typed_array_offset"); |
99 } | 98 } |
100 | 99 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. | 195 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
197 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); | 196 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); |
198 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); | 197 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); |
199 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); | 198 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); |
200 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); | 199 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); |
201 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); | 200 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); |
202 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); | 201 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); |
203 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); | 202 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); |
204 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); | 203 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); |
205 | 204 |
OLD | NEW |