OLD | NEW |
1 // Copyright 2012 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 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 var a = new Int32Array(2); | 42 var a = new Int32Array(2); |
43 for (var i = 0; i < 5; i++) { | 43 for (var i = 0; i < 5; i++) { |
44 f(a); | 44 f(a); |
45 } | 45 } |
46 %OptimizeFunctionOnNextCall(f); | 46 %OptimizeFunctionOnNextCall(f); |
47 f(a); | 47 f(a); |
48 | 48 |
49 assertEquals(0, a[0]); | 49 assertEquals(0, a[0]); |
50 assertEquals(0, a[1]); | 50 assertEquals(0, a[1]); |
51 | 51 |
52 // No-parameter constructor should fail right now. | |
53 function abfunc1() { | |
54 return new ArrayBuffer(); | |
55 } | |
56 assertThrows(abfunc1); | |
57 | |
58 // Test derivation from an ArrayBuffer | 52 // Test derivation from an ArrayBuffer |
59 var ab = new ArrayBuffer(12); | 53 var ab = new ArrayBuffer(12); |
60 assertInstance(ab, ArrayBuffer); | 54 assertInstance(ab, ArrayBuffer); |
61 var derived_uint8 = new Uint8Array(ab); | 55 var derived_uint8 = new Uint8Array(ab); |
62 assertInstance(derived_uint8, Uint8Array); | 56 assertInstance(derived_uint8, Uint8Array); |
63 assertSame(ab, derived_uint8.buffer); | 57 assertSame(ab, derived_uint8.buffer); |
64 assertEquals(12, derived_uint8.length); | 58 assertEquals(12, derived_uint8.length); |
65 assertEquals(12, derived_uint8.byteLength); | 59 assertEquals(12, derived_uint8.byteLength); |
66 assertEquals(0, derived_uint8.byteOffset); | 60 assertEquals(0, derived_uint8.byteOffset); |
67 assertEquals(1, derived_uint8.BYTES_PER_ELEMENT); | 61 assertEquals(1, derived_uint8.BYTES_PER_ELEMENT); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 assertEquals(a.byteLength, a.buffer.byteLength); | 148 assertEquals(a.byteLength, a.buffer.byteLength); |
155 assertEquals(a.length * a.BYTES_PER_ELEMENT, a.buffer.byteLength); | 149 assertEquals(a.length * a.BYTES_PER_ELEMENT, a.buffer.byteLength); |
156 | 150 |
157 // Test that an implicitly created buffer is a valid buffer. | 151 // Test that an implicitly created buffer is a valid buffer. |
158 a = new Float64Array(7); | 152 a = new Float64Array(7); |
159 assertSame(a.buffer, (new Uint16Array(a.buffer)).buffer); | 153 assertSame(a.buffer, (new Uint16Array(a.buffer)).buffer); |
160 assertSame(a.buffer, (new Float32Array(a.buffer,4)).buffer); | 154 assertSame(a.buffer, (new Float32Array(a.buffer,4)).buffer); |
161 assertSame(a.buffer, (new Int8Array(a.buffer,3,51)).buffer); | 155 assertSame(a.buffer, (new Int8Array(a.buffer,3,51)).buffer); |
162 assertInstance(a.buffer, ArrayBuffer); | 156 assertInstance(a.buffer, ArrayBuffer); |
163 | 157 |
164 // Test the correct behavior of the |BYTES_PER_ELEMENT| property (which is | 158 // Test the correct behavior of the |BYTES_PER_ELEMENT| property |
165 // "constant", but not read-only). | |
166 a = new Int32Array(2); | 159 a = new Int32Array(2); |
167 assertEquals(4, a.BYTES_PER_ELEMENT); | 160 assertEquals(4, a.BYTES_PER_ELEMENT); |
168 a.BYTES_PER_ELEMENT = 42; | |
169 assertEquals(42, a.BYTES_PER_ELEMENT); | |
170 a = new Uint8Array(2); | 161 a = new Uint8Array(2); |
171 assertEquals(1, a.BYTES_PER_ELEMENT); | 162 assertEquals(1, a.BYTES_PER_ELEMENT); |
172 a = new Int16Array(2); | 163 a = new Int16Array(2); |
173 assertEquals(2, a.BYTES_PER_ELEMENT); | 164 assertEquals(2, a.BYTES_PER_ELEMENT); |
174 | 165 |
175 // Test Float64Arrays. | 166 // Test Float64Arrays. |
176 function get(a, index) { | 167 function get(a, index) { |
177 return a[index]; | 168 return a[index]; |
178 } | 169 } |
179 function set(a, index, value) { | 170 function set(a, index, value) { |
(...skipping 15 matching lines...) Expand all Loading... |
195 assertEquals(3.5, array[1]); | 186 assertEquals(3.5, array[1]); |
196 } | 187 } |
197 %OptimizeFunctionOnNextCall(get); | 188 %OptimizeFunctionOnNextCall(get); |
198 assertEquals(2.5, get(array, 0)); | 189 assertEquals(2.5, get(array, 0)); |
199 assertEquals(3.5, get(array, 1)); | 190 assertEquals(3.5, get(array, 1)); |
200 } | 191 } |
201 | 192 |
202 // Test non-number parameters. | 193 // Test non-number parameters. |
203 var array_with_length_from_non_number = new Int32Array("2"); | 194 var array_with_length_from_non_number = new Int32Array("2"); |
204 assertEquals(2, array_with_length_from_non_number.length); | 195 assertEquals(2, array_with_length_from_non_number.length); |
205 array_with_length_from_non_number = new Int32Array(undefined); | |
206 assertEquals(0, array_with_length_from_non_number.length); | |
207 var foo = { valueOf: function() { return 3; } }; | |
208 array_with_length_from_non_number = new Int32Array(foo); | |
209 assertEquals(3, array_with_length_from_non_number.length); | |
210 foo = { toString: function() { return "4"; } }; | |
211 array_with_length_from_non_number = new Int32Array(foo); | |
212 assertEquals(4, array_with_length_from_non_number.length); | |
213 | |
214 | 196 |
215 // Test loads and stores. | 197 // Test loads and stores. |
216 types = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, | 198 types = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, |
217 Uint32Array, Uint8ClampedArray, Float32Array, Float64Array]; | 199 Uint32Array, Uint8ClampedArray, Float32Array, Float64Array]; |
218 | 200 |
219 test_result_nan = [NaN, 0, 0, 0, 0, 0, 0, 0, NaN, NaN]; | 201 test_result_nan = [NaN, 0, 0, 0, 0, 0, 0, 0, NaN, NaN]; |
220 test_result_low_int = [-1, -1, 255, -1, 65535, -1, 0xFFFFFFFF, 0, -1, -1]; | 202 test_result_low_int = [-1, -1, 255, -1, 65535, -1, 0xFFFFFFFF, 0, -1, -1]; |
221 test_result_low_double = [-1.25, -1, 255, -1, 65535, -1, 0xFFFFFFFF, 0, -1.25, -
1.25]; | 203 test_result_low_double = [-1.25, -1, 255, -1, 65535, -1, 0xFFFFFFFF, 0, -1.25, -
1.25]; |
222 test_result_middle = [253.75, -3, 253, 253, 253, 253, 253, 254, 253.75, 253.75]; | 204 test_result_middle = [253.75, -3, 253, 253, 253, 253, 253, 254, 253.75, 253.75]; |
223 test_result_high_int = [256, 0, 0, 256, 256, 256, 256, 255, 256, 256]; | 205 test_result_high_int = [256, 0, 0, 256, 256, 256, 256, 255, 256, 256]; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 run_test(test_store_middle_tagged, a, test_result_middle[t]); | 334 run_test(test_store_middle_tagged, a, test_result_middle[t]); |
353 run_test(test_store_high_double, a, test_result_high_double[t]); | 335 run_test(test_store_high_double, a, test_result_high_double[t]); |
354 run_test(test_store_high_tagged, a, test_result_high_double[t]); | 336 run_test(test_store_high_tagged, a, test_result_high_double[t]); |
355 | 337 |
356 // Test the correct behavior of the |length| property (which is read-only). | 338 // Test the correct behavior of the |length| property (which is read-only). |
357 if (t != 0) { | 339 if (t != 0) { |
358 assertEquals(kElementCount, a.length); | 340 assertEquals(kElementCount, a.length); |
359 a.length = 2; | 341 a.length = 2; |
360 assertEquals(kElementCount, a.length); | 342 assertEquals(kElementCount, a.length); |
361 assertTrue(delete a.length); | 343 assertTrue(delete a.length); |
362 a.length = 2; | |
363 assertEquals(2, a.length); | |
364 | 344 |
365 // Make sure bounds checks are handled correctly for external arrays. | 345 // Make sure bounds checks are handled correctly for external arrays. |
366 run_bounds_test(a); | 346 run_bounds_test(a); |
367 run_bounds_test(a); | 347 run_bounds_test(a); |
368 run_bounds_test(a); | 348 run_bounds_test(a); |
369 %OptimizeFunctionOnNextCall(run_bounds_test); | 349 %OptimizeFunctionOnNextCall(run_bounds_test); |
370 run_bounds_test(a); | 350 run_bounds_test(a); |
371 %DeoptimizeFunction(run_bounds_test); | 351 %DeoptimizeFunction(run_bounds_test); |
372 gc(); // Makes V8 forget about type information for test_func. | 352 gc(); // Makes V8 forget about type information for test_func. |
373 | 353 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 assertEquals(0, a.length); | 425 assertEquals(0, a.length); |
446 a[0] = 1; | 426 a[0] = 1; |
447 assertEquals(undefined, a[0]); | 427 assertEquals(undefined, a[0]); |
448 a = new Uint16Array(0); | 428 a = new Uint16Array(0); |
449 assertInstance(a, Uint16Array); | 429 assertInstance(a, Uint16Array); |
450 assertEquals(0, a.byteLength); | 430 assertEquals(0, a.byteLength); |
451 assertEquals(0, a.length); | 431 assertEquals(0, a.length); |
452 a[0] = 1; | 432 a[0] = 1; |
453 assertEquals(undefined, a[0]); | 433 assertEquals(undefined, a[0]); |
454 | 434 |
455 | |
456 // Check construction from arrays. | 435 // Check construction from arrays. |
457 a = new Uint32Array([]); | 436 a = new Uint32Array([]); |
458 assertInstance(a, Uint32Array); | 437 assertInstance(a, Uint32Array); |
459 assertEquals(0, a.length); | 438 assertEquals(0, a.length); |
460 assertEquals(0, a.byteLength); | 439 assertEquals(0, a.byteLength); |
461 assertEquals(0, a.buffer.byteLength); | 440 assertEquals(0, a.buffer.byteLength); |
462 assertEquals(4, a.BYTES_PER_ELEMENT); | 441 assertEquals(4, a.BYTES_PER_ELEMENT); |
463 assertInstance(a.buffer, ArrayBuffer); | 442 assertInstance(a.buffer, ArrayBuffer); |
464 a = new Uint16Array([1,2,3]); | 443 a = new Uint16Array([1,2,3]); |
465 assertInstance(a, Uint16Array); | 444 assertInstance(a, Uint16Array); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 assertSame(a.buffer, aa.buffer); | 511 assertSame(a.buffer, aa.buffer); |
533 aa = a.subarray(0,-8); | 512 aa = a.subarray(0,-8); |
534 assertInstance(aa, Uint16Array); | 513 assertInstance(aa, Uint16Array); |
535 assertEquals(0, aa.length); | 514 assertEquals(0, aa.length); |
536 assertEquals(0, aa.byteLength); | 515 assertEquals(0, aa.byteLength); |
537 assertEquals(2, aa.BYTES_PER_ELEMENT); | 516 assertEquals(2, aa.BYTES_PER_ELEMENT); |
538 assertSame(a.buffer, aa.buffer); | 517 assertSame(a.buffer, aa.buffer); |
539 | 518 |
540 assertThrows(function(){ a.subarray.call({}, 0) }); | 519 assertThrows(function(){ a.subarray.call({}, 0) }); |
541 assertThrows(function(){ a.subarray.call([], 0) }); | 520 assertThrows(function(){ a.subarray.call([], 0) }); |
542 assertThrows(function(){ a.subarray.call(a) }); | |
543 | |
544 | 521 |
545 // Call constructors directly as functions, and through .call and .apply | 522 // Call constructors directly as functions, and through .call and .apply |
546 | 523 |
547 b = ArrayBuffer(100) | 524 b = ArrayBuffer(100) |
548 a = Int8Array(b, 5, 77) | 525 a = Int8Array(b, 5, 77) |
549 assertInstance(b, ArrayBuffer) | 526 assertInstance(b, ArrayBuffer) |
550 assertInstance(a, Int8Array) | 527 assertInstance(a, Int8Array) |
551 assertSame(b, a.buffer) | 528 assertSame(b, a.buffer) |
552 assertEquals(5, a.byteOffset) | 529 assertEquals(5, a.byteOffset) |
553 assertEquals(77, a.byteLength) | 530 assertEquals(77, a.byteLength) |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 684 |
708 built_in_array = new Array(1.5, 2, 3, 4, 5, 6); | 685 built_in_array = new Array(1.5, 2, 3, 4, 5, 6); |
709 assertEquals(1.5, goo(built_in_array, 0)); | 686 assertEquals(1.5, goo(built_in_array, 0)); |
710 assertEquals(1.5, goo(built_in_array, 0)); | 687 assertEquals(1.5, goo(built_in_array, 0)); |
711 %OptimizeFunctionOnNextCall(goo); | 688 %OptimizeFunctionOnNextCall(goo); |
712 %OptimizeFunctionOnNextCall(boo); | 689 %OptimizeFunctionOnNextCall(boo); |
713 boo(built_in_array, 0, 2.5); | 690 boo(built_in_array, 0, 2.5); |
714 assertEquals(2.5, goo(built_in_array, 0)); | 691 assertEquals(2.5, goo(built_in_array, 0)); |
715 %ClearFunctionTypeFeedback(goo); | 692 %ClearFunctionTypeFeedback(goo); |
716 %ClearFunctionTypeFeedback(boo); | 693 %ClearFunctionTypeFeedback(boo); |
OLD | NEW |