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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 TestSlice(10, 100, -10); | 106 TestSlice(10, 100, -10); |
107 } | 107 } |
108 | 108 |
109 TestArrayBufferSlice(); | 109 TestArrayBufferSlice(); |
110 | 110 |
111 // Typed arrays | 111 // Typed arrays |
112 | 112 |
113 function TestTypedArray(proto, elementSize, typicalElement) { | 113 function TestTypedArray(proto, elementSize, typicalElement) { |
114 var ab = new ArrayBuffer(256*elementSize); | 114 var ab = new ArrayBuffer(256*elementSize); |
115 | 115 |
| 116 var a0 = new proto(30); |
| 117 assertSame(elementSize, a0.BYTES_PER_ELEMENT); |
| 118 assertSame(30, a0.length); |
| 119 assertSame(30*elementSize, a0.byteLength); |
| 120 assertSame(0, a0.byteOffset); |
| 121 assertSame(30*elementSize, a0.buffer.byteLength); |
| 122 |
| 123 var aLen0 = new proto(0); |
| 124 assertSame(elementSize, aLen0.BYTES_PER_ELEMENT); |
| 125 assertSame(0, aLen0.length); |
| 126 assertSame(0, aLen0.byteLength); |
| 127 assertSame(0, aLen0.byteOffset); |
| 128 assertSame(0, aLen0.buffer.byteLength); |
| 129 |
| 130 var aOverBufferLen0 = new proto(ab, 128*elementSize, 0); |
| 131 assertSame(ab, aOverBufferLen0.buffer); |
| 132 assertSame(elementSize, aOverBufferLen0.BYTES_PER_ELEMENT); |
| 133 assertSame(0, aOverBufferLen0.length); |
| 134 assertSame(0, aOverBufferLen0.byteLength); |
| 135 assertSame(128*elementSize, aOverBufferLen0.byteOffset); |
| 136 |
116 var a1 = new proto(ab, 128*elementSize, 128); | 137 var a1 = new proto(ab, 128*elementSize, 128); |
117 assertSame(ab, a1.buffer); | 138 assertSame(ab, a1.buffer); |
118 assertSame(elementSize, a1.BYTES_PER_ELEMENT); | 139 assertSame(elementSize, a1.BYTES_PER_ELEMENT); |
119 assertSame(128, a1.length); | 140 assertSame(128, a1.length); |
120 assertSame(128*elementSize, a1.byteLength); | 141 assertSame(128*elementSize, a1.byteLength); |
121 assertSame(128*elementSize, a1.byteOffset); | 142 assertSame(128*elementSize, a1.byteOffset); |
122 | 143 |
123 | 144 |
124 var a2 = new proto(ab, 64*elementSize, 128); | 145 var a2 = new proto(ab, 64*elementSize, 128); |
125 assertSame(ab, a2.buffer); | 146 assertSame(ab, a2.buffer); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 243 } |
223 for (var i = 0; i < 20; i++) { | 244 for (var i = 0; i < 20; i++) { |
224 TestProperty(m, i, 'val' + i); | 245 TestProperty(m, i, 'val' + i); |
225 TestProperty(m, 'foo' + i, 'bar' + i); | 246 TestProperty(m, 'foo' + i, 'bar' + i); |
226 } | 247 } |
227 } | 248 } |
228 TestArbitrary(new ArrayBuffer(256)); | 249 TestArbitrary(new ArrayBuffer(256)); |
229 | 250 |
230 // Test direct constructor call | 251 // Test direct constructor call |
231 assertTrue(ArrayBuffer() instanceof ArrayBuffer); | 252 assertTrue(ArrayBuffer() instanceof ArrayBuffer); |
OLD | NEW |