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 26 matching lines...) Expand all Loading... |
37 | 37 |
38 // support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); | 38 // support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
39 support_smi_only_arrays = true; | 39 support_smi_only_arrays = true; |
40 | 40 |
41 if (support_smi_only_arrays) { | 41 if (support_smi_only_arrays) { |
42 print("Tests include smi-only arrays."); | 42 print("Tests include smi-only arrays."); |
43 } else { | 43 } else { |
44 print("Tests do NOT include smi-only arrays."); | 44 print("Tests do NOT include smi-only arrays."); |
45 } | 45 } |
46 | 46 |
47 function isHoley(obj) { | 47 if (support_smi_only_arrays) { |
48 if (%HasFastHoleyElements(obj)) return true; | |
49 return false; | |
50 } | |
51 | 48 |
52 function assertHoley(obj, name_opt) { | 49 function get_literal(x) { |
53 assertEquals(true, isHoley(obj), name_opt); | 50 var literal = [1, 2, x]; |
54 } | 51 return literal; |
55 | |
56 function assertNotHoley(obj, name_opt) { | |
57 assertEquals(false, isHoley(obj), name_opt); | |
58 } | |
59 | |
60 if (support_smi_only_arrays) { | |
61 function create_array(arg) { | |
62 return new Array(arg); | |
63 } | 52 } |
64 | 53 |
65 obj = create_array(0); | 54 get_literal(3); |
66 assertNotHoley(obj); | 55 get_literal(3); |
67 create_array(0); | 56 %OptimizeFunctionOnNextCall(get_literal); |
68 %OptimizeFunctionOnNextCall(create_array); | 57 a = get_literal(3); |
69 obj = create_array(10); | 58 assertTrue(2 != %GetOptimizationStatus(get_literal)); |
70 assertHoley(obj); | 59 assertTrue(%HasFastSmiElements(a)); |
| 60 a[0] = 3.5; |
| 61 |
| 62 // We should have transitioned the boilerplate array to double, and |
| 63 // crankshafted code should de-opt on the unexpected elements kind |
| 64 b = get_literal(3); |
| 65 assertTrue(%HasFastDoubleElements(b)); |
| 66 assertEquals([1, 2, 3], b); |
| 67 assertTrue(1 != %GetOptimizationStatus(get_literal)); |
| 68 |
| 69 // Optimize again |
| 70 get_literal(3); |
| 71 %OptimizeFunctionOnNextCall(get_literal); |
| 72 b = get_literal(3); |
| 73 assertTrue(%HasFastDoubleElements(b)); |
| 74 assertTrue(2 != %GetOptimizationStatus(get_literal)); |
71 } | 75 } |
72 | |
73 // The code below would assert in debug or crash in release | |
74 function f(length) { | |
75 return new Array(length) | |
76 } | |
77 | |
78 f(0); | |
79 f(0); | |
80 %OptimizeFunctionOnNextCall(f); | |
81 var a = f(10); | |
82 | |
83 function g(a) { | |
84 return a[0]; | |
85 } | |
86 | |
87 var b = [0]; | |
88 g(b); | |
89 g(b); | |
90 assertEquals(undefined, g(a)); | |
OLD | NEW |