Chromium Code Reviews| 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 | |
|
Dmitry Lomov (no reviews)
2013/05/07 13:21:29
This does not fail per ES6 spec
| |
| 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; | 161 a.BYTES_PER_ELEMENT = 42; |
|
rossberg
2013/05/07 13:58:05
Did you want to remove this line, too?
| |
| 169 assertEquals(42, a.BYTES_PER_ELEMENT); | |
|
Dmitry Lomov (no reviews)
2013/05/07 13:21:29
Property is readonly per ES6 spec.
| |
| 170 a = new Uint8Array(2); | 162 a = new Uint8Array(2); |
| 171 assertEquals(1, a.BYTES_PER_ELEMENT); | 163 assertEquals(1, a.BYTES_PER_ELEMENT); |
| 172 a = new Int16Array(2); | 164 a = new Int16Array(2); |
| 173 assertEquals(2, a.BYTES_PER_ELEMENT); | 165 assertEquals(2, a.BYTES_PER_ELEMENT); |
| 174 | 166 |
| 175 // Test Float64Arrays. | 167 // Test Float64Arrays. |
| 176 function get(a, index) { | 168 function get(a, index) { |
| 177 return a[index]; | 169 return a[index]; |
| 178 } | 170 } |
| 179 function set(a, index, value) { | 171 function set(a, index, value) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 195 assertEquals(3.5, array[1]); | 187 assertEquals(3.5, array[1]); |
| 196 } | 188 } |
| 197 %OptimizeFunctionOnNextCall(get); | 189 %OptimizeFunctionOnNextCall(get); |
| 198 assertEquals(2.5, get(array, 0)); | 190 assertEquals(2.5, get(array, 0)); |
| 199 assertEquals(3.5, get(array, 1)); | 191 assertEquals(3.5, get(array, 1)); |
| 200 } | 192 } |
| 201 | 193 |
| 202 // Test non-number parameters. | 194 // Test non-number parameters. |
| 203 var array_with_length_from_non_number = new Int32Array("2"); | 195 var array_with_length_from_non_number = new Int32Array("2"); |
| 204 assertEquals(2, array_with_length_from_non_number.length); | 196 assertEquals(2, array_with_length_from_non_number.length); |
| 205 array_with_length_from_non_number = new Int32Array(undefined); | |
|
Dmitry Lomov (no reviews)
2013/05/07 13:21:29
Spec is currently unclear on what should happen fo
| |
| 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 | 197 |
| 215 // Test loads and stores. | 198 // Test loads and stores. |
| 216 types = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, | 199 types = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, |
| 217 Uint32Array, Uint8ClampedArray, Float32Array, Float64Array]; | 200 Uint32Array, Uint8ClampedArray, Float32Array, Float64Array]; |
| 218 | 201 |
| 219 test_result_nan = [NaN, 0, 0, 0, 0, 0, 0, 0, NaN, NaN]; | 202 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]; | 203 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]; | 204 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]; | 205 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]; | 206 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]); | 335 run_test(test_store_middle_tagged, a, test_result_middle[t]); |
| 353 run_test(test_store_high_double, a, test_result_high_double[t]); | 336 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]); | 337 run_test(test_store_high_tagged, a, test_result_high_double[t]); |
| 355 | 338 |
| 356 // Test the correct behavior of the |length| property (which is read-only). | 339 // Test the correct behavior of the |length| property (which is read-only). |
| 357 if (t != 0) { | 340 if (t != 0) { |
| 358 assertEquals(kElementCount, a.length); | 341 assertEquals(kElementCount, a.length); |
| 359 a.length = 2; | 342 a.length = 2; |
| 360 assertEquals(kElementCount, a.length); | 343 assertEquals(kElementCount, a.length); |
| 361 assertTrue(delete a.length); | 344 assertTrue(delete a.length); |
| 362 a.length = 2; | |
| 363 assertEquals(2, a.length); | |
|
Dmitry Lomov (no reviews)
2013/05/07 13:21:29
'length' is now a property on the prototype so del
| |
| 364 | 345 |
| 365 // Make sure bounds checks are handled correctly for external arrays. | 346 // Make sure bounds checks are handled correctly for external arrays. |
| 366 run_bounds_test(a); | 347 run_bounds_test(a); |
| 367 run_bounds_test(a); | 348 run_bounds_test(a); |
| 368 run_bounds_test(a); | 349 run_bounds_test(a); |
| 369 %OptimizeFunctionOnNextCall(run_bounds_test); | 350 %OptimizeFunctionOnNextCall(run_bounds_test); |
| 370 run_bounds_test(a); | 351 run_bounds_test(a); |
| 371 %DeoptimizeFunction(run_bounds_test); | 352 %DeoptimizeFunction(run_bounds_test); |
| 372 gc(); // Makes V8 forget about type information for test_func. | 353 gc(); // Makes V8 forget about type information for test_func. |
| 373 | 354 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 assertSame(a.buffer, aa.buffer); | 513 assertSame(a.buffer, aa.buffer); |
| 533 aa = a.subarray(0,-8); | 514 aa = a.subarray(0,-8); |
| 534 assertInstance(aa, Uint16Array); | 515 assertInstance(aa, Uint16Array); |
| 535 assertEquals(0, aa.length); | 516 assertEquals(0, aa.length); |
| 536 assertEquals(0, aa.byteLength); | 517 assertEquals(0, aa.byteLength); |
| 537 assertEquals(2, aa.BYTES_PER_ELEMENT); | 518 assertEquals(2, aa.BYTES_PER_ELEMENT); |
| 538 assertSame(a.buffer, aa.buffer); | 519 assertSame(a.buffer, aa.buffer); |
| 539 | 520 |
| 540 assertThrows(function(){ a.subarray.call({}, 0) }); | 521 assertThrows(function(){ a.subarray.call({}, 0) }); |
| 541 assertThrows(function(){ a.subarray.call([], 0) }); | 522 assertThrows(function(){ a.subarray.call([], 0) }); |
| 542 assertThrows(function(){ a.subarray.call(a) }); | |
| 543 | |
|
Dmitry Lomov (no reviews)
2013/05/07 13:21:29
a.subarray() is a valid call per ES6 (returns a co
| |
| 544 | 523 |
| 545 // Call constructors directly as functions, and through .call and .apply | 524 // Call constructors directly as functions, and through .call and .apply |
| 546 | 525 |
| 547 b = ArrayBuffer(100) | 526 b = ArrayBuffer(100) |
| 548 a = Int8Array(b, 5, 77) | 527 a = Int8Array(b, 5, 77) |
| 549 assertInstance(b, ArrayBuffer) | 528 assertInstance(b, ArrayBuffer) |
| 550 assertInstance(a, Int8Array) | 529 assertInstance(a, Int8Array) |
| 551 assertSame(b, a.buffer) | 530 assertSame(b, a.buffer) |
| 552 assertEquals(5, a.byteOffset) | 531 assertEquals(5, a.byteOffset) |
| 553 assertEquals(77, a.byteLength) | 532 assertEquals(77, a.byteLength) |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 | 686 |
| 708 built_in_array = new Array(1.5, 2, 3, 4, 5, 6); | 687 built_in_array = new Array(1.5, 2, 3, 4, 5, 6); |
| 709 assertEquals(1.5, goo(built_in_array, 0)); | 688 assertEquals(1.5, goo(built_in_array, 0)); |
| 710 assertEquals(1.5, goo(built_in_array, 0)); | 689 assertEquals(1.5, goo(built_in_array, 0)); |
| 711 %OptimizeFunctionOnNextCall(goo); | 690 %OptimizeFunctionOnNextCall(goo); |
| 712 %OptimizeFunctionOnNextCall(boo); | 691 %OptimizeFunctionOnNextCall(boo); |
| 713 boo(built_in_array, 0, 2.5); | 692 boo(built_in_array, 0, 2.5); |
| 714 assertEquals(2.5, goo(built_in_array, 0)); | 693 assertEquals(2.5, goo(built_in_array, 0)); |
| 715 %ClearFunctionTypeFeedback(goo); | 694 %ClearFunctionTypeFeedback(goo); |
| 716 %ClearFunctionTypeFeedback(boo); | 695 %ClearFunctionTypeFeedback(boo); |
| OLD | NEW |