Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: test/mjsunit/external-array.js

Issue 10694051: Implement typedarray.set and arraybuffer.slice for d8. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Handle overlapping for differing element sizes correctly. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/d8.cc ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 assertSame(b, a.buffer) 558 assertSame(b, a.buffer)
559 assertEquals(2, a.byteOffset) 559 assertEquals(2, a.byteOffset)
560 assertEquals(8, a.byteLength) 560 assertEquals(8, a.byteLength)
561 b = ArrayBuffer.apply(null, [1000]) 561 b = ArrayBuffer.apply(null, [1000])
562 a = Float32Array.apply(null, [b, 128, 1]) 562 a = Float32Array.apply(null, [b, 128, 1])
563 assertInstance(b, ArrayBuffer) 563 assertInstance(b, ArrayBuffer)
564 assertInstance(a, Float32Array) 564 assertInstance(a, Float32Array)
565 assertSame(b, a.buffer) 565 assertSame(b, a.buffer)
566 assertEquals(128, a.byteOffset) 566 assertEquals(128, a.byteOffset)
567 assertEquals(4, a.byteLength) 567 assertEquals(4, a.byteLength)
568
569
570 // Test array.set in different combinations.
571
572 function assertArrayPrefix(expected, array) {
573 for (var i = 0; i < expected.length; ++i) {
574 assertEquals(expected[i], array[i]);
575 }
576 }
577
578 var a11 = new Int16Array([1, 2, 3, 4, 0, -1])
579 var a12 = new Uint16Array(15)
580 a12.set(a11, 3)
581 assertArrayPrefix([0, 0, 0, 1, 2, 3, 4, 0, 0xffff, 0, 0], a12)
582 assertThrows(function(){ a11.set(a12) })
583
584 var a21 = [1, undefined, 10, NaN, 0, -1, {valueOf: function() {return 3}}]
585 var a22 = new Int32Array(12)
586 a22.set(a21, 2)
587 assertArrayPrefix([0, 0, 1, 0, 10, 0, 0, -1, 3, 0], a22)
588
589 var a31 = new Float32Array([2, 4, 6, 8, 11, NaN, 1/0, -3])
590 var a32 = a31.subarray(2, 6)
591 a31.set(a32, 4)
592 assertArrayPrefix([2, 4, 6, 8, 6, 8, 11, NaN], a31)
593 assertArrayPrefix([6, 8, 6, 8], a32)
594
595 var a4 = new Uint8ClampedArray([3,2,5,6])
596 a4.set(a4)
597 assertArrayPrefix([3, 2, 5, 6], a4)
598
599 // Cases with overlapping backing store but different element sizes.
600 var b = new ArrayBuffer(4)
601 var a5 = new Int16Array(b)
602 var a50 = new Int8Array(b)
603 var a51 = new Int8Array(b, 0, 2)
604 var a52 = new Int8Array(b, 1, 2)
605 var a53 = new Int8Array(b, 2, 2)
606
607 a5.set([0x5050, 0x0a0a])
608 assertArrayPrefix([0x50, 0x50, 0x0a, 0x0a], a50)
609 assertArrayPrefix([0x50, 0x50], a51)
610 assertArrayPrefix([0x50, 0x0a], a52)
611 assertArrayPrefix([0x0a, 0x0a], a53)
612
613 a50.set([0x50, 0x50, 0x0a, 0x0a])
614 a51.set(a5)
615 assertArrayPrefix([0x50, 0x0a, 0x0a, 0x0a], a50)
616
617 a50.set([0x50, 0x50, 0x0a, 0x0a])
618 a52.set(a5)
619 assertArrayPrefix([0x50, 0x50, 0x0a, 0x0a], a50)
620
621 a50.set([0x50, 0x50, 0x0a, 0x0a])
622 a53.set(a5)
623 assertArrayPrefix([0x50, 0x50, 0x50, 0x0a], a50)
624
625 a50.set([0x50, 0x51, 0x0a, 0x0b])
626 a5.set(a51)
627 assertArrayPrefix([0x0050, 0x0051], a5)
628
629 a50.set([0x50, 0x51, 0x0a, 0x0b])
630 a5.set(a52)
631 assertArrayPrefix([0x0051, 0x000a], a5)
632
633 a50.set([0x50, 0x51, 0x0a, 0x0b])
634 a5.set(a53)
635 assertArrayPrefix([0x000a, 0x000b], a5)
636
637 // Mixed types of same size.
638 var a61 = new Float32Array([1.2, 12.3])
639 var a62 = new Int32Array(2)
640 a62.set(a61)
641 assertArrayPrefix([1, 12], a62)
642 a61.set(a62)
643 assertArrayPrefix([1, 12], a61)
644
645 // Invalid source
646 assertThrows(function() { a.set(0) })
647 assertThrows(function() { a.set({}) })
648
649
650 // Test arraybuffer.slice
651
652 var a0 = new Int8Array([1, 2, 3, 4, 5, 6])
653 var b0 = a0.buffer
654
655 var b1 = b0.slice(0)
656 assertEquals(b0.byteLength, b1.byteLength)
657 assertArrayPrefix([1, 2, 3, 4, 5, 6], Int8Array(b1))
658
659 var b2 = b0.slice(3)
660 assertEquals(b0.byteLength - 3, b2.byteLength)
661 assertArrayPrefix([4, 5, 6], Int8Array(b2))
662
663 var b3 = b0.slice(2, 4)
664 assertEquals(2, b3.byteLength)
665 assertArrayPrefix([3, 4], Int8Array(b3))
OLDNEW
« no previous file with comments | « src/d8.cc ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698