OLD | NEW |
1 // Copyright 2011 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 24 matching lines...) Expand all Loading... |
36 var a = new Int32Array(2); | 36 var a = new Int32Array(2); |
37 for (var i = 0; i < 5; i++) { | 37 for (var i = 0; i < 5; i++) { |
38 f(a); | 38 f(a); |
39 } | 39 } |
40 %OptimizeFunctionOnNextCall(f); | 40 %OptimizeFunctionOnNextCall(f); |
41 f(a); | 41 f(a); |
42 | 42 |
43 assertEquals(0, a[0]); | 43 assertEquals(0, a[0]); |
44 assertEquals(0, a[1]); | 44 assertEquals(0, a[1]); |
45 | 45 |
| 46 // No-parameter constructor should fail right now. |
| 47 function abfunc1() { |
| 48 return new ArrayBuffer(); |
| 49 } |
| 50 assertThrows(abfunc1); |
| 51 |
| 52 // Test derivation from an ArrayBuffer |
| 53 var ab = new ArrayBuffer(12); |
| 54 var derived_uint8 = new Uint8Array(ab); |
| 55 assertEquals(12, derived_uint8.length); |
| 56 var derived_uint32 = new Uint32Array(ab); |
| 57 assertEquals(3, derived_uint32.length); |
| 58 var derived_uint32_2 = new Uint32Array(ab,4); |
| 59 assertEquals(2, derived_uint32_2.length); |
| 60 var derived_uint32_3 = new Uint32Array(ab,4,1); |
| 61 assertEquals(1, derived_uint32_3.length); |
| 62 |
| 63 // If a given byteOffset and length references an area beyond the end of the |
| 64 // ArrayBuffer an exception is raised. |
| 65 function abfunc3() { |
| 66 new Uint32Array(ab,4,3); |
| 67 } |
| 68 assertThrows(abfunc3); |
| 69 function abfunc4() { |
| 70 new Uint32Array(ab,16); |
| 71 } |
| 72 assertThrows(abfunc4); |
| 73 |
| 74 // The given byteOffset must be a multiple of the element size of the specific |
| 75 // type, otherwise an exception is raised. |
| 76 function abfunc5() { |
| 77 new Uint32Array(ab,5); |
| 78 } |
| 79 assertThrows(abfunc5); |
| 80 |
| 81 // If length is not explicitly specified, the length of the ArrayBuffer minus |
| 82 // the byteOffset must be a multiple of the element size of the specific type, |
| 83 // or an exception is raised. |
| 84 var ab2 = new ArrayBuffer(13); |
| 85 function abfunc6() { |
| 86 new Uint32Array(ab2,4); |
| 87 } |
| 88 assertThrows(abfunc6); |
| 89 |
46 // Test the correct behavior of the |BYTES_PER_ELEMENT| property (which is | 90 // Test the correct behavior of the |BYTES_PER_ELEMENT| property (which is |
47 // "constant", but not read-only). | 91 // "constant", but not read-only). |
48 a = new Int32Array(2); | 92 a = new Int32Array(2); |
49 assertEquals(4, a.BYTES_PER_ELEMENT); | 93 assertEquals(4, a.BYTES_PER_ELEMENT); |
50 a.BYTES_PER_ELEMENT = 42; | 94 a.BYTES_PER_ELEMENT = 42; |
51 assertEquals(42, a.BYTES_PER_ELEMENT); | 95 assertEquals(42, a.BYTES_PER_ELEMENT); |
52 a = new Uint8Array(2); | 96 a = new Uint8Array(2); |
53 assertEquals(1, a.BYTES_PER_ELEMENT); | 97 assertEquals(1, a.BYTES_PER_ELEMENT); |
54 a = new Int16Array(2); | 98 a = new Int16Array(2); |
55 assertEquals(2, a.BYTES_PER_ELEMENT); | 99 assertEquals(2, a.BYTES_PER_ELEMENT); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 return a[0] = a[0] = 1; | 310 return a[0] = a[0] = 1; |
267 } | 311 } |
268 | 312 |
269 array_load_set_smi_check2(a); | 313 array_load_set_smi_check2(a); |
270 %OptimizeFunctionOnNextCall(array_load_set_smi_check2); | 314 %OptimizeFunctionOnNextCall(array_load_set_smi_check2); |
271 array_load_set_smi_check2(a); | 315 array_load_set_smi_check2(a); |
272 array_load_set_smi_check2(0); | 316 array_load_set_smi_check2(0); |
273 %DeoptimizeFunction(array_load_set_smi_check2); | 317 %DeoptimizeFunction(array_load_set_smi_check2); |
274 gc(); // Makes V8 forget about type information for array_load_set_smi_check. | 318 gc(); // Makes V8 forget about type information for array_load_set_smi_check. |
275 } | 319 } |
OLD | NEW |