Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
|
Jakob Kummerow
2012/01/11 13:54:27
2012
| |
| 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 function abfunc2() { | |
| 64 new Uint32Array(ab,3); | |
| 65 } | |
| 66 assertThrows(abfunc2); | |
| 67 | |
| 68 // If a given byteOffset and length references an area beyond the end of the | |
| 69 // ArrayBuffer an exception is raised. | |
| 70 function abfunc3() { | |
| 71 new Uint32Array(ab,4,3); | |
| 72 } | |
| 73 assertThrows(abfunc3); | |
| 74 function abfunc4() { | |
| 75 new Uint32Array(ab,13); | |
|
Jakob Kummerow
2012/01/11 13:54:27
s/13/16/ to avoid triggering the "offset must be m
danno
2012/01/11 15:10:20
Done.
| |
| 76 } | |
| 77 assertThrows(abfunc4); | |
| 78 | |
| 79 // The given byteOffset must be a multiple of the element size of the specific | |
| 80 // type, otherwise an exception is raised. | |
| 81 function abfunc5() { | |
|
Jakob Kummerow
2012/01/11 13:54:27
nit: AFAICS, abfunc5 and abfunc2 test the same thi
danno
2012/01/11 15:10:20
Done.
| |
| 82 new Uint32Array(ab,5); | |
| 83 } | |
| 84 assertThrows(abfunc5); | |
| 85 | |
| 86 // If length is not explicitly specified, the length of the ArrayBuffer minus | |
| 87 // the byteOffset must be a multiple of the element size of the specific type, | |
| 88 // or an exception is raised. | |
| 89 var ab2 = new ArrayBuffer(13); | |
| 90 function abfunc6() { | |
| 91 new Uint32Array(ab,1); | |
|
Jakob Kummerow
2012/01/11 13:54:27
This doesn't test what the comment says (13-1 is,
| |
| 92 } | |
| 93 assertThrows(abfunc6); | |
| 94 | |
| 46 // Test the correct behavior of the |BYTES_PER_ELEMENT| property (which is | 95 // Test the correct behavior of the |BYTES_PER_ELEMENT| property (which is |
| 47 // "constant", but not read-only). | 96 // "constant", but not read-only). |
| 48 a = new Int32Array(2); | 97 a = new Int32Array(2); |
| 49 assertEquals(4, a.BYTES_PER_ELEMENT); | 98 assertEquals(4, a.BYTES_PER_ELEMENT); |
| 50 a.BYTES_PER_ELEMENT = 42; | 99 a.BYTES_PER_ELEMENT = 42; |
| 51 assertEquals(42, a.BYTES_PER_ELEMENT); | 100 assertEquals(42, a.BYTES_PER_ELEMENT); |
| 52 a = new Uint8Array(2); | 101 a = new Uint8Array(2); |
| 53 assertEquals(1, a.BYTES_PER_ELEMENT); | 102 assertEquals(1, a.BYTES_PER_ELEMENT); |
| 54 a = new Int16Array(2); | 103 a = new Int16Array(2); |
| 55 assertEquals(2, a.BYTES_PER_ELEMENT); | 104 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; | 315 return a[0] = a[0] = 1; |
| 267 } | 316 } |
| 268 | 317 |
| 269 array_load_set_smi_check2(a); | 318 array_load_set_smi_check2(a); |
| 270 %OptimizeFunctionOnNextCall(array_load_set_smi_check2); | 319 %OptimizeFunctionOnNextCall(array_load_set_smi_check2); |
| 271 array_load_set_smi_check2(a); | 320 array_load_set_smi_check2(a); |
| 272 array_load_set_smi_check2(0); | 321 array_load_set_smi_check2(0); |
| 273 %DeoptimizeFunction(array_load_set_smi_check2); | 322 %DeoptimizeFunction(array_load_set_smi_check2); |
| 274 gc(); // Makes V8 forget about type information for array_load_set_smi_check. | 323 gc(); // Makes V8 forget about type information for array_load_set_smi_check. |
| 275 } | 324 } |
| OLD | NEW |