Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { | 51 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
| 52 var offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length") | 52 var bufferByteLength = buffer.byteLength; |
| 53 var offset; | |
| 54 if (IS_UNDEFINED(byteOffset)) { | |
| 55 offset = 0; | |
| 56 } else { | |
| 57 offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length"); | |
| 53 | 58 |
| 54 if (offset % ELEMENT_SIZE !== 0) { | 59 if (offset % ELEMENT_SIZE !== 0) { |
| 55 throw MakeRangeError("invalid_typed_array_alignment", | 60 throw MakeRangeError("invalid_typed_array_alignment", |
| 56 "start offset", "NAME", ELEMENT_SIZE); | 61 "start offset", "NAME", ELEMENT_SIZE); |
| 57 } | 62 } |
| 58 var bufferByteLength = buffer.byteLength; | 63 if (offset > bufferByteLength) { |
| 59 if (offset > bufferByteLength) { | 64 throw MakeRangeError("invalid_typed_array_offset"); |
| 60 throw MakeRangeError("invalid_typed_array_offset"); | 65 } |
| 61 } | 66 } |
| 62 | 67 |
| 63 var newByteLength; | 68 var newByteLength; |
| 64 var newLength; | 69 var newLength; |
| 65 if (IS_UNDEFINED(length)) { | 70 if (IS_UNDEFINED(length)) { |
| 66 if (bufferByteLength % ELEMENT_SIZE !== 0) { | 71 if (bufferByteLength % ELEMENT_SIZE !== 0) { |
| 67 throw MakeRangeError("invalid_typed_array_alignment", | 72 throw MakeRangeError("invalid_typed_array_alignment", |
| 68 "byte length", "NAME", ELEMENT_SIZE); | 73 "byte length", "NAME", ELEMENT_SIZE); |
| 69 } | 74 } |
| 70 newByteLength = bufferByteLength - offset; | 75 newByteLength = bufferByteLength - offset; |
| 71 newLength = newByteLength / ELEMENT_SIZE; | 76 newLength = newByteLength / ELEMENT_SIZE; |
| 72 } else { | 77 } else { |
| 73 var newLength = ToPositiveInteger(length, "invalid_typed_array_length"); | 78 var newLength = ToPositiveInteger(length, "invalid_typed_array_length"); |
| 74 newByteLength = newLength * ELEMENT_SIZE; | 79 newByteLength = newLength * ELEMENT_SIZE; |
| 75 } | 80 } |
| 76 if (offset + newByteLength > bufferByteLength) { | 81 if (offset + newByteLength > bufferByteLength) { |
| 77 throw MakeRangeError("invalid_typed_array_length"); | 82 throw MakeRangeError("invalid_typed_array_length"); |
| 78 } | 83 } |
| 79 %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); | 84 %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); |
| 80 } | 85 } |
| 81 | 86 |
| 82 function NAMEConstructByLength(obj, length) { | 87 function NAMEConstructByLength(obj, length) { |
| 83 var l = ToPositiveInteger(length, "invalid_typed_array_length"); | 88 var l = IS_UNDEFINED(length) ? |
| 89 0 : ToPositiveInteger(length, "invalid_typed_array_length"); | |
| 84 var byteLength = l * ELEMENT_SIZE; | 90 var byteLength = l * ELEMENT_SIZE; |
| 85 var buffer = new $ArrayBuffer(byteLength); | 91 var buffer = new $ArrayBuffer(byteLength); |
| 86 %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); | 92 %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); |
| 87 } | 93 } |
| 88 | 94 |
| 89 function NAMEConstructByArrayLike(obj, arrayLike) { | 95 function NAMEConstructByArrayLike(obj, arrayLike) { |
| 90 var length = arrayLike.length; | 96 var length = arrayLike.length; |
| 91 var l = ToPositiveInteger(length, "invalid_typed_array_length"); | 97 var l = ToPositiveInteger(length, "invalid_typed_array_length"); |
| 92 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { | 98 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { |
| 93 for (var i = 0; i < l; i++) { | 99 for (var i = 0; i < l; i++) { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 // --------------------------- DataView ----------------------------- | 300 // --------------------------- DataView ----------------------------- |
| 295 | 301 |
| 296 var $DataView = global.DataView; | 302 var $DataView = global.DataView; |
| 297 | 303 |
| 298 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 | 304 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |
| 299 if (%_IsConstructCall()) { | 305 if (%_IsConstructCall()) { |
| 300 if (!IS_ARRAYBUFFER(buffer)) { | 306 if (!IS_ARRAYBUFFER(buffer)) { |
| 301 throw MakeTypeError('data_view_not_array_buffer', []); | 307 throw MakeTypeError('data_view_not_array_buffer', []); |
| 302 } | 308 } |
| 303 var bufferByteLength = %ArrayBufferGetByteLength(buffer); | 309 var bufferByteLength = %ArrayBufferGetByteLength(buffer); |
| 304 var offset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset'); | 310 var offset = IS_UNDEFINED(byteOffset) ? |
| 311 0 : ToPositiveInteger(byteOffset, 'invalid_data_view_offset'); | |
|
Yang
2013/11/07 10:14:11
I think we use 4 space indent after linebreak. I s
| |
| 305 if (offset > bufferByteLength) { | 312 if (offset > bufferByteLength) { |
| 306 throw MakeRangeError('invalid_data_view_offset'); | 313 throw MakeRangeError('invalid_data_view_offset'); |
| 307 } | 314 } |
| 308 var length = IS_UNDEFINED(byteLength) ? | 315 var length = IS_UNDEFINED(byteLength) ? |
| 309 bufferByteLength - offset : TO_INTEGER(byteLength); | 316 bufferByteLength - offset : TO_INTEGER(byteLength); |
| 310 if (length < 0 || offset + length > bufferByteLength) { | 317 if (length < 0 || offset + length > bufferByteLength) { |
| 311 throw new MakeRangeError('invalid_data_view_length'); | 318 throw new MakeRangeError('invalid_data_view_length'); |
| 312 } | 319 } |
| 313 %DataViewInitialize(this, buffer, offset, length); | 320 %DataViewInitialize(this, buffer, offset, length); |
| 314 } else { | 321 } else { |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 | 602 |
| 596 "getFloat32", DataViewGetFloat32, | 603 "getFloat32", DataViewGetFloat32, |
| 597 "setFloat32", DataViewSetFloat32, | 604 "setFloat32", DataViewSetFloat32, |
| 598 | 605 |
| 599 "getFloat64", DataViewGetFloat64, | 606 "getFloat64", DataViewGetFloat64, |
| 600 "setFloat64", DataViewSetFloat64 | 607 "setFloat64", DataViewSetFloat64 |
| 601 )); | 608 )); |
| 602 } | 609 } |
| 603 | 610 |
| 604 SetupDataView(); | 611 SetupDataView(); |
| OLD | NEW |