| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 assertEquals(a.length * a.BYTES_PER_ELEMENT, a.buffer.byteLength); | 152 assertEquals(a.length * a.BYTES_PER_ELEMENT, a.buffer.byteLength); |
| 153 a = new Float64Array(7); | 153 a = new Float64Array(7); |
| 154 assertEquals(a.byteLength, a.buffer.byteLength); | 154 assertEquals(a.byteLength, a.buffer.byteLength); |
| 155 assertEquals(a.length * a.BYTES_PER_ELEMENT, a.buffer.byteLength); | 155 assertEquals(a.length * a.BYTES_PER_ELEMENT, a.buffer.byteLength); |
| 156 | 156 |
| 157 // Test that an implicitly created buffer is a valid buffer. | 157 // Test that an implicitly created buffer is a valid buffer. |
| 158 a = new Float64Array(7); | 158 a = new Float64Array(7); |
| 159 assertSame(a.buffer, (new Uint16Array(a.buffer)).buffer); | 159 assertSame(a.buffer, (new Uint16Array(a.buffer)).buffer); |
| 160 assertSame(a.buffer, (new Float32Array(a.buffer,4)).buffer); | 160 assertSame(a.buffer, (new Float32Array(a.buffer,4)).buffer); |
| 161 assertSame(a.buffer, (new Int8Array(a.buffer,3,51)).buffer); | 161 assertSame(a.buffer, (new Int8Array(a.buffer,3,51)).buffer); |
| 162 assertInstance(a.buffer, ArrayBuffer); |
| 162 | 163 |
| 163 // Test the correct behavior of the |BYTES_PER_ELEMENT| property (which is | 164 // Test the correct behavior of the |BYTES_PER_ELEMENT| property (which is |
| 164 // "constant", but not read-only). | 165 // "constant", but not read-only). |
| 165 a = new Int32Array(2); | 166 a = new Int32Array(2); |
| 166 assertEquals(4, a.BYTES_PER_ELEMENT); | 167 assertEquals(4, a.BYTES_PER_ELEMENT); |
| 167 a.BYTES_PER_ELEMENT = 42; | 168 a.BYTES_PER_ELEMENT = 42; |
| 168 assertEquals(42, a.BYTES_PER_ELEMENT); | 169 assertEquals(42, a.BYTES_PER_ELEMENT); |
| 169 a = new Uint8Array(2); | 170 a = new Uint8Array(2); |
| 170 assertEquals(1, a.BYTES_PER_ELEMENT); | 171 assertEquals(1, a.BYTES_PER_ELEMENT); |
| 171 a = new Int16Array(2); | 172 a = new Int16Array(2); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 assertEquals(undefined, a[0]); | 453 assertEquals(undefined, a[0]); |
| 453 | 454 |
| 454 | 455 |
| 455 // Check construction from arrays. | 456 // Check construction from arrays. |
| 456 a = new Uint32Array([]); | 457 a = new Uint32Array([]); |
| 457 assertInstance(a, Uint32Array); | 458 assertInstance(a, Uint32Array); |
| 458 assertEquals(0, a.length); | 459 assertEquals(0, a.length); |
| 459 assertEquals(0, a.byteLength); | 460 assertEquals(0, a.byteLength); |
| 460 assertEquals(0, a.buffer.byteLength); | 461 assertEquals(0, a.buffer.byteLength); |
| 461 assertEquals(4, a.BYTES_PER_ELEMENT); | 462 assertEquals(4, a.BYTES_PER_ELEMENT); |
| 463 assertInstance(a.buffer, ArrayBuffer); |
| 462 a = new Uint16Array([1,2,3]); | 464 a = new Uint16Array([1,2,3]); |
| 463 assertInstance(a, Uint16Array); | 465 assertInstance(a, Uint16Array); |
| 464 assertEquals(3, a.length); | 466 assertEquals(3, a.length); |
| 465 assertEquals(6, a.byteLength); | 467 assertEquals(6, a.byteLength); |
| 466 assertEquals(6, a.buffer.byteLength); | 468 assertEquals(6, a.buffer.byteLength); |
| 467 assertEquals(2, a.BYTES_PER_ELEMENT); | 469 assertEquals(2, a.BYTES_PER_ELEMENT); |
| 468 assertEquals(1, a[0]); | 470 assertEquals(1, a[0]); |
| 469 assertEquals(3, a[2]); | 471 assertEquals(3, a[2]); |
| 472 assertInstance(a.buffer, ArrayBuffer); |
| 470 a = new Uint32Array(a); | 473 a = new Uint32Array(a); |
| 471 assertInstance(a, Uint32Array); | 474 assertInstance(a, Uint32Array); |
| 472 assertEquals(3, a.length); | 475 assertEquals(3, a.length); |
| 473 assertEquals(12, a.byteLength); | 476 assertEquals(12, a.byteLength); |
| 474 assertEquals(12, a.buffer.byteLength); | 477 assertEquals(12, a.buffer.byteLength); |
| 475 assertEquals(4, a.BYTES_PER_ELEMENT); | 478 assertEquals(4, a.BYTES_PER_ELEMENT); |
| 476 assertEquals(1, a[0]); | 479 assertEquals(1, a[0]); |
| 477 assertEquals(3, a[2]); | 480 assertEquals(3, a[2]); |
| 478 | 481 assertInstance(a.buffer, ArrayBuffer); |
| 479 | 482 |
| 480 // Check subarrays. | 483 // Check subarrays. |
| 481 a = new Uint16Array([1,2,3,4,5,6]); | 484 a = new Uint16Array([1,2,3,4,5,6]); |
| 482 aa = a.subarray(3); | 485 aa = a.subarray(3); |
| 483 assertInstance(aa, Uint16Array); | 486 assertInstance(aa, Uint16Array); |
| 484 assertEquals(3, aa.length); | 487 assertEquals(3, aa.length); |
| 485 assertEquals(6, aa.byteLength); | 488 assertEquals(6, aa.byteLength); |
| 486 assertEquals(2, aa.BYTES_PER_ELEMENT); | 489 assertEquals(2, aa.BYTES_PER_ELEMENT); |
| 487 assertSame(a.buffer, aa.buffer); | 490 assertSame(a.buffer, aa.buffer); |
| 488 aa = a.subarray(3,5); | 491 aa = a.subarray(3,5); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 aa = a.subarray(0,-8); | 533 aa = a.subarray(0,-8); |
| 531 assertInstance(aa, Uint16Array); | 534 assertInstance(aa, Uint16Array); |
| 532 assertEquals(0, aa.length); | 535 assertEquals(0, aa.length); |
| 533 assertEquals(0, aa.byteLength); | 536 assertEquals(0, aa.byteLength); |
| 534 assertEquals(2, aa.BYTES_PER_ELEMENT); | 537 assertEquals(2, aa.BYTES_PER_ELEMENT); |
| 535 assertSame(a.buffer, aa.buffer); | 538 assertSame(a.buffer, aa.buffer); |
| 536 | 539 |
| 537 assertThrows(function(){ a.subarray.call({}, 0) }); | 540 assertThrows(function(){ a.subarray.call({}, 0) }); |
| 538 assertThrows(function(){ a.subarray.call([], 0) }); | 541 assertThrows(function(){ a.subarray.call([], 0) }); |
| 539 assertThrows(function(){ a.subarray.call(a) }); | 542 assertThrows(function(){ a.subarray.call(a) }); |
| OLD | NEW |