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 21 matching lines...) Expand all Loading... |
32 function TestByteLength(param, expectedByteLength) { | 32 function TestByteLength(param, expectedByteLength) { |
33 var ab = new ArrayBuffer(param); | 33 var ab = new ArrayBuffer(param); |
34 assertSame(expectedByteLength, ab.byteLength); | 34 assertSame(expectedByteLength, ab.byteLength); |
35 } | 35 } |
36 | 36 |
37 function TestArrayBufferCreation() { | 37 function TestArrayBufferCreation() { |
38 TestByteLength(1, 1); | 38 TestByteLength(1, 1); |
39 TestByteLength(256, 256); | 39 TestByteLength(256, 256); |
40 TestByteLength(2.567, 2); | 40 TestByteLength(2.567, 2); |
41 | 41 |
42 TestByteLength("abc", 0); | 42 TestByteLength("0", 0); |
43 | 43 |
44 TestByteLength(0, 0); | 44 TestByteLength(0, 0); |
45 | 45 |
46 assertThrows(function() { new ArrayBuffer(-10); }, RangeError); | 46 assertThrows(function() { new ArrayBuffer(-10); }, RangeError); |
47 assertThrows(function() { new ArrayBuffer(-2.567); }, RangeError); | 47 assertThrows(function() { new ArrayBuffer(-2.567); }, RangeError); |
48 | 48 |
49 /* TODO[dslomov]: Reenable the test | 49 /* TODO[dslomov]: Reenable the test |
50 assertThrows(function() { | 50 assertThrows(function() { |
51 var ab1 = new ArrayBuffer(0xFFFFFFFFFFFF) | 51 var ab1 = new ArrayBuffer(0xFFFFFFFFFFFF) |
52 }, RangeError); | 52 }, RangeError); |
53 */ | 53 */ |
54 | 54 |
55 var ab = new ArrayBuffer(); | 55 var ab = new ArrayBuffer(0); |
56 assertSame(0, ab.byteLength); | 56 assertSame(0, ab.byteLength); |
57 assertEquals("[object ArrayBuffer]", | 57 assertEquals("[object ArrayBuffer]", |
58 Object.prototype.toString.call(ab)); | 58 Object.prototype.toString.call(ab)); |
59 } | 59 } |
60 | 60 |
61 TestArrayBufferCreation(); | 61 TestArrayBufferCreation(); |
62 | 62 |
63 function TestByteLengthNotWritable() { | 63 function TestByteLengthNotWritable() { |
64 var ab = new ArrayBuffer(1024); | 64 var ab = new ArrayBuffer(1024); |
65 assertSame(1024, ab.byteLength); | 65 assertSame(1024, ab.byteLength); |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 function props(x) { | 722 function props(x) { |
723 var array = []; | 723 var array = []; |
724 for (var p in x) array.push(p); | 724 for (var p in x) array.push(p); |
725 return array.sort(); | 725 return array.sort(); |
726 } | 726 } |
727 assertArrayEquals([], props(func)); | 727 assertArrayEquals([], props(func)); |
728 assertArrayEquals([], props(func.prototype)); | 728 assertArrayEquals([], props(func.prototype)); |
729 if (obj) | 729 if (obj) |
730 assertArrayEquals([], props(obj)); | 730 assertArrayEquals([], props(obj)); |
731 } | 731 } |
732 TestEnumerable(ArrayBuffer, new ArrayBuffer()); | 732 TestEnumerable(ArrayBuffer, new ArrayBuffer(0)); |
733 for(i = 0; i < typedArrayConstructors.length; i++) { | 733 for(i = 0; i < typedArrayConstructors.length; i++) { |
734 TestEnumerable(typedArrayConstructors[i]); | 734 TestEnumerable(typedArrayConstructors[i]); |
735 } | 735 } |
736 TestEnumerable(DataView, new DataView(new ArrayBuffer())); | 736 TestEnumerable(DataView, new DataView(new ArrayBuffer(0))); |
737 | 737 |
738 // Test arbitrary properties on ArrayBuffer | 738 // Test arbitrary properties on ArrayBuffer |
739 function TestArbitrary(m) { | 739 function TestArbitrary(m) { |
740 function TestProperty(map, property, value) { | 740 function TestProperty(map, property, value) { |
741 map[property] = value; | 741 map[property] = value; |
742 assertEquals(value, map[property]); | 742 assertEquals(value, map[property]); |
743 } | 743 } |
744 for (var i = 0; i < 20; i++) { | 744 for (var i = 0; i < 20; i++) { |
745 TestProperty(m, 'key' + i, 'val' + i); | 745 TestProperty(m, 'key' + i, 'val' + i); |
746 TestProperty(m, 'foo' + i, 'bar' + i); | 746 TestProperty(m, 'foo' + i, 'bar' + i); |
747 } | 747 } |
748 } | 748 } |
749 TestArbitrary(new ArrayBuffer(256)); | 749 TestArbitrary(new ArrayBuffer(256)); |
750 for(i = 0; i < typedArrayConstructors.length; i++) { | 750 for(i = 0; i < typedArrayConstructors.length; i++) { |
751 TestArbitrary(new typedArrayConstructors[i](10)); | 751 TestArbitrary(new typedArrayConstructors[i](10)); |
752 } | 752 } |
753 TestArbitrary(new DataView(new ArrayBuffer(256))); | 753 TestArbitrary(new DataView(new ArrayBuffer(256))); |
754 | 754 |
755 | 755 |
756 // Test direct constructor call | 756 // Test direct constructor call |
757 assertThrows(function() { ArrayBuffer(); }, TypeError); | 757 assertThrows(function() { ArrayBuffer(0); }, TypeError); |
758 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); | 758 assertThrows(function() { DataView(new ArrayBuffer(0)); }, TypeError); |
759 | 759 |
760 function TestNonConfigurableProperties(constructor) { | 760 function TestNonConfigurableProperties(constructor) { |
761 var arr = new constructor([100]) | 761 var arr = new constructor([100]) |
762 assertFalse(Object.getOwnPropertyDescriptor(arr,"0").configurable) | 762 assertFalse(Object.getOwnPropertyDescriptor(arr,"0").configurable) |
763 assertFalse(delete arr[0]) | 763 assertFalse(delete arr[0]) |
764 } | 764 } |
765 | 765 |
766 for(i = 0; i < typedArrayConstructors.length; i++) { | 766 for(i = 0; i < typedArrayConstructors.length; i++) { |
767 TestNonConfigurableProperties(typedArrayConstructors[i]); | 767 TestNonConfigurableProperties(typedArrayConstructors[i]); |
768 } | 768 } |
OLD | NEW |