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 10 matching lines...) Expand all Loading... | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --allow-natives-syntax | 28 // Flags: --allow-natives-syntax |
29 | 29 |
30 // Test CompareIC stubs for normal and strict equality comparison of known | 30 // Test CompareIC stubs for normal and strict equality comparison of known |
31 // objects in slow mode. These objects share the same map even though they | 31 // objects in slow mode. These objects share the same map even though they |
Hannes Payer (out of office)
2013/10/02 13:33:19
in fast mode?
| |
32 // might have completely different properties. | 32 // might have completely different properties. |
33 | 33 |
34 function lt(a, b) { | |
35 return a < b; | |
36 } | |
37 | |
38 function gt(a, b) { | |
39 return a > b; | |
40 } | |
41 | |
34 function eq(a, b) { | 42 function eq(a, b) { |
35 return a == b; | 43 return a == b; |
36 } | 44 } |
37 | 45 |
38 function eq_strict(a, b) { | 46 function eq_strict(a, b) { |
39 return a === b; | 47 return a === b; |
40 } | 48 } |
41 | 49 |
42 function test(a, b) { | 50 function test(a, b, less, greater) { |
43 // Check CompareIC for equality of known objects. | 51 // Check CompareIC for equality of known objects. |
44 assertTrue(eq(a, a)); | 52 assertTrue(eq(a, a)); |
45 assertTrue(eq(b, b)); | 53 assertTrue(eq(b, b)); |
46 assertFalse(eq(a, b)); | 54 assertFalse(eq(a, b)); |
47 // Check CompareIC for strict equality of known objects. | |
48 assertTrue(eq_strict(a, a)); | 55 assertTrue(eq_strict(a, a)); |
49 assertTrue(eq_strict(b, b)); | 56 assertTrue(eq_strict(b, b)); |
50 assertFalse(eq_strict(a, b)); | 57 assertFalse(eq_strict(a, b)); |
58 assertEquals(lt(a, b), less); | |
59 assertEquals(gt(a, b), greater); | |
60 assertEquals(lt(b, a), greater); | |
61 assertEquals(gt(b, a), less); | |
51 } | 62 } |
52 | 63 |
53 // Prepare two objects in slow mode that have the same map. | 64 var obj1 = {toString: function() {return "1";}}; |
54 var obj1 = %OptimizeObjectForAddingMultipleProperties({}, 1); | 65 var obj2 = {toString: function() {return "2";}}; |
55 var obj2 = %OptimizeObjectForAddingMultipleProperties({}, 1); | |
56 | 66 |
57 // Test original objects. | 67 var less = obj1 < obj2; |
58 assertTrue(%HaveSameMap(obj1, obj2)); | 68 var greater = obj1 > obj2; |
59 test(obj1, obj2); | |
60 | 69 |
61 // Test after adding property to first object. | 70 test(obj1, obj2, less, greater); |
71 test(obj1, obj2, less, greater); | |
72 test(obj1, obj2, less, greater); | |
73 %OptimizeFunctionOnNextCall(test); | |
74 test(obj1, obj2, less, greater); | |
75 test(obj1, obj2, less, greater); | |
76 | |
62 obj1.x = 1; | 77 obj1.x = 1; |
63 assertTrue(%HaveSameMap(obj1, obj2)); | 78 test(obj1, obj2, less, greater); |
64 test(obj1, obj2); | |
65 | 79 |
66 // Test after adding property to second object. | |
67 obj2.y = 2; | 80 obj2.y = 2; |
68 assertTrue(%HaveSameMap(obj1, obj2)); | 81 test(obj1, obj2, less, greater); |
69 test(obj1, obj2); | 82 |
83 var obj1 = {test: 3}; | |
84 var obj2 = {test2: 3}; | |
85 | |
86 var less = obj1 < obj2; | |
87 var greater = obj1 > obj2; | |
88 | |
89 test(obj1, obj2, less, greater); | |
90 test(obj1, obj2, less, greater); | |
91 test(obj1, obj2, less, greater); | |
92 %OptimizeFunctionOnNextCall(test); | |
93 test(obj1, obj2, less, greater); | |
94 test(obj1, obj2, less, greater); | |
95 | |
96 obj1.toString = function() {return "1"}; | |
97 var less = obj1 < obj2; | |
98 var greater = obj1 > obj2; | |
99 test(obj1, obj2, less, greater); | |
100 %OptimizeFunctionOnNextCall(test); | |
101 test(obj1, obj2, less, greater); | |
102 | |
103 obj2.toString = function() {return "2"}; | |
104 var less = true; | |
105 var greater = false; | |
106 | |
107 test(obj1, obj2, less, greater); | |
108 obj2.y = 2; | |
109 test(obj1, obj2, less, greater); | |
OLD | NEW |