| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 184 } |
| 185 | 185 |
| 186 for (i = 0; i < 128; i++) { | 186 for (i = 0; i < 128; i++) { |
| 187 assertSame(0, a4[i]); | 187 assertSame(0, a4[i]); |
| 188 } | 188 } |
| 189 | 189 |
| 190 for (i = 128; i < 256; i++) { | 190 for (i = 128; i < 256; i++) { |
| 191 assertSame(typicalElement, a4[i]); | 191 assertSame(typicalElement, a4[i]); |
| 192 } | 192 } |
| 193 | 193 |
| 194 assertThrows(function () { new proto(ab, 256*elementSize); }, RangeError); | 194 var aAtTheEnd = new proto(ab, 256*elementSize); |
| 195 assertSame(elementSize, aAtTheEnd.BYTES_PER_ELEMENT); |
| 196 assertSame(0, aAtTheEnd.length); |
| 197 assertSame(0, aAtTheEnd.byteLength); |
| 198 assertSame(256*elementSize, aAtTheEnd.byteOffset); |
| 199 |
| 200 assertThrows(function () { new proto(ab, 257*elementSize); }, RangeError); |
| 195 assertThrows( | 201 assertThrows( |
| 196 function () { new proto(ab, 128*elementSize, 192); }, | 202 function () { new proto(ab, 128*elementSize, 192); }, |
| 197 RangeError); | 203 RangeError); |
| 198 | 204 |
| 199 if (elementSize !== 1) { | 205 if (elementSize !== 1) { |
| 200 assertThrows(function() { new proto(ab, 128*elementSize - 1, 10); }, | 206 assertThrows(function() { new proto(ab, 128*elementSize - 1, 10); }, |
| 201 RangeError); | 207 RangeError); |
| 202 var unalignedArrayBuffer = new ArrayBuffer(10*elementSize + 1); | 208 var unalignedArrayBuffer = new ArrayBuffer(10*elementSize + 1); |
| 203 var goodArray = new proto(unalignedArrayBuffer, 0, 10); | 209 var goodArray = new proto(unalignedArrayBuffer, 0, 10); |
| 204 assertSame(10, goodArray.length); | 210 assertSame(10, goodArray.length); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 222 } | 228 } |
| 223 var aFromArray = new proto(jsArray); | 229 var aFromArray = new proto(jsArray); |
| 224 assertSame(elementSize, aFromArray.BYTES_PER_ELEMENT); | 230 assertSame(elementSize, aFromArray.BYTES_PER_ELEMENT); |
| 225 assertSame(30, aFromArray.length); | 231 assertSame(30, aFromArray.length); |
| 226 assertSame(30*elementSize, aFromArray.byteLength); | 232 assertSame(30*elementSize, aFromArray.byteLength); |
| 227 assertSame(0, aFromArray.byteOffset); | 233 assertSame(0, aFromArray.byteOffset); |
| 228 assertSame(30*elementSize, aFromArray.buffer.byteLength); | 234 assertSame(30*elementSize, aFromArray.buffer.byteLength); |
| 229 for (i = 0; i < 30; i++) { | 235 for (i = 0; i < 30; i++) { |
| 230 assertSame(typicalElement, aFromArray[i]); | 236 assertSame(typicalElement, aFromArray[i]); |
| 231 } | 237 } |
| 238 |
| 239 var abLen0 = new ArrayBuffer(0); |
| 240 var aOverAbLen0 = new proto(abLen0); |
| 241 assertSame(abLen0, aOverAbLen0.buffer); |
| 242 assertSame(elementSize, aOverAbLen0.BYTES_PER_ELEMENT); |
| 243 assertSame(0, aOverAbLen0.length); |
| 244 assertSame(0, aOverAbLen0.byteLength); |
| 245 assertSame(0, aOverAbLen0.byteOffset); |
| 232 } | 246 } |
| 233 | 247 |
| 234 TestTypedArray(Uint8Array, 1, 0xFF); | 248 TestTypedArray(Uint8Array, 1, 0xFF); |
| 235 TestTypedArray(Int8Array, 1, -0x7F); | 249 TestTypedArray(Int8Array, 1, -0x7F); |
| 236 TestTypedArray(Uint16Array, 2, 0xFFFF); | 250 TestTypedArray(Uint16Array, 2, 0xFFFF); |
| 237 TestTypedArray(Int16Array, 2, -0x7FFF); | 251 TestTypedArray(Int16Array, 2, -0x7FFF); |
| 238 TestTypedArray(Uint32Array, 4, 0xFFFFFFFF); | 252 TestTypedArray(Uint32Array, 4, 0xFFFFFFFF); |
| 239 TestTypedArray(Int32Array, 4, -0x7FFFFFFF); | 253 TestTypedArray(Int32Array, 4, -0x7FFFFFFF); |
| 240 TestTypedArray(Float32Array, 4, 0.5); | 254 TestTypedArray(Float32Array, 4, 0.5); |
| 241 TestTypedArray(Float64Array, 8, 0.5); | 255 TestTypedArray(Float64Array, 8, 0.5); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 309 } |
| 296 for (var i = 0; i < 20; i++) { | 310 for (var i = 0; i < 20; i++) { |
| 297 TestProperty(m, i, 'val' + i); | 311 TestProperty(m, i, 'val' + i); |
| 298 TestProperty(m, 'foo' + i, 'bar' + i); | 312 TestProperty(m, 'foo' + i, 'bar' + i); |
| 299 } | 313 } |
| 300 } | 314 } |
| 301 TestArbitrary(new ArrayBuffer(256)); | 315 TestArbitrary(new ArrayBuffer(256)); |
| 302 | 316 |
| 303 // Test direct constructor call | 317 // Test direct constructor call |
| 304 assertTrue(ArrayBuffer() instanceof ArrayBuffer); | 318 assertTrue(ArrayBuffer() instanceof ArrayBuffer); |
| OLD | NEW |