Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: test/mjsunit/compiler/inline-construct.js

Issue 10825382: Extend constructor inlining test case. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
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 --inline-construct 28 // Flags: --allow-natives-syntax --inline-construct
29 29
30 // Test inlining of constructor calls. 30 // Test inlining of constructor calls.
31 31
32 function TestInlinedConstructor(constructor, closure) { 32 function TestInlinedConstructor(constructor, closure) {
33 var result; 33 var result;
34 var counter = { value:0 }; 34 var counter = { value:0 };
35 var noDeopt = { deopt:0 };
36 var forceDeopt = { /*empty*/ };
35 37
36 result = closure(constructor, 11, 12, counter); 38 result = closure(constructor, 11, noDeopt, counter);
37 assertEquals(23, result); 39 assertEquals(11, result);
38 assertEquals(1, counter.value); 40 assertEquals(1, counter.value);
39 41
40 result = closure(constructor, 23, 19, counter); 42 result = closure(constructor, 23, noDeopt, counter);
41 assertEquals(42, result); 43 assertEquals(23, result);
42 assertEquals(2, counter.value); 44 assertEquals(2, counter.value);
43 45
44 %OptimizeFunctionOnNextCall(closure); 46 %OptimizeFunctionOnNextCall(closure);
45 result = closure(constructor, 1, 42, counter); 47 result = closure(constructor, 42, noDeopt, counter);
46 assertEquals(43, result); 48 assertEquals(42, result);
47 assertEquals(3, counter.value); 49 assertEquals(3, counter.value);
48 50
49 result = closure(constructor, "foo", "bar", counter); 51 result = closure(constructor, 127, forceDeopt, counter);
50 assertEquals("foobar", result) 52 assertEquals(127, result)
51 assertEquals(4, counter.value); 53 assertEquals(4, counter.value);
52 54
53 %DeoptimizeFunction(closure); 55 %DeoptimizeFunction(closure);
54 %ClearFunctionTypeFeedback(closure); 56 %ClearFunctionTypeFeedback(closure);
57 %ClearFunctionTypeFeedback(constructor);
55 } 58 }
56 59
57 function value_context(constructor, a, b, counter) { 60 function value_context(constructor, val, deopt, counter) {
58 var obj = new constructor(a, b, counter); 61 var obj = new constructor(val, deopt, counter);
59 return obj.x; 62 return obj.x;
60 } 63 }
61 64
62 function test_context(constructor, a, b, counter) { 65 function test_context(constructor, val, deopt, counter) {
63 if (!new constructor(a, b, counter)) { 66 if (!new constructor(val, deopt, counter)) {
64 assertUnreachable("should not happen"); 67 assertUnreachable("should not happen");
65 } 68 }
66 return a + b; 69 return val;
67 } 70 }
68 71
69 function effect_context(constructor, a, b, counter) { 72 function effect_context(constructor, val, deopt, counter) {
70 new constructor(a, b, counter); 73 new constructor(val, deopt, counter);
71 return a + b; 74 return val;
72 } 75 }
73 76
74 function TestInAllContexts(constructor) { 77 function TestInAllContexts(constructor) {
75 TestInlinedConstructor(constructor, value_context); 78 TestInlinedConstructor(constructor, value_context);
76 TestInlinedConstructor(constructor, test_context); 79 TestInlinedConstructor(constructor, test_context);
77 TestInlinedConstructor(constructor, effect_context); 80 TestInlinedConstructor(constructor, effect_context);
78 } 81 }
79 82
80 83
81 // Test constructor returning nothing in all contexts. 84 // Test constructor returning nothing in all contexts.
82 function c1(a, b, counter) { 85 function c1(val, deopt, counter) {
83 this.x = a + b; 86 deopt.deopt;
87 this.x = val;
84 counter.value++; 88 counter.value++;
85 } 89 }
86 TestInAllContexts(c1); 90 TestInAllContexts(c1);
87 91
88 92
89 // Test constructor returning an object in all contexts. 93 // Test constructor returning an object in all contexts.
90 function c2(a, b, counter) { 94 function c2(val, deopt, counter) {
91 var obj = {}; 95 var obj = {};
92 obj.x = a + b; 96 deopt.deopt;
97 obj.x = val;
93 counter.value++; 98 counter.value++;
94 return obj; 99 return obj;
95 } 100 }
96 TestInAllContexts(c2); 101 TestInAllContexts(c2);
97 102
98 103
99 // Test constructor returning a primitive value in all contexts. 104 // Test constructor returning a primitive value in all contexts.
100 function c3(a, b, counter) { 105 function c3(val, deopt, counter) {
101 this.x = a + b; 106 deopt.deopt;
107 this.x = val;
102 counter.value++; 108 counter.value++;
103 return "not an object"; 109 return "not an object";
104 } 110 }
105 TestInAllContexts(c3); 111 TestInAllContexts(c3);
106 112
107 113
108 // Test constructor called with too many arguments. 114 // Test constructor called with too many arguments.
109 function c_too_many(a, b) { 115 function c_too_many(a, b) {
110 this.x = a + b; 116 this.x = a + b;
111 } 117 }
(...skipping 18 matching lines...) Expand all
130 return obj.x; 136 return obj.x;
131 } 137 }
132 assertEquals(12, f_too_few(11)); 138 assertEquals(12, f_too_few(11));
133 assertEquals(24, f_too_few(23)); 139 assertEquals(24, f_too_few(23));
134 %OptimizeFunctionOnNextCall(f_too_few); 140 %OptimizeFunctionOnNextCall(f_too_few);
135 assertEquals(2, f_too_few(1)); 141 assertEquals(2, f_too_few(1));
136 assertEquals("foo1", f_too_few("foo")) 142 assertEquals("foo1", f_too_few("foo"))
137 143
138 144
139 // Test constructor that cannot be inlined. 145 // Test constructor that cannot be inlined.
140 function c_unsupported_syntax(a, b, counter) { 146 function c_unsupported_syntax(val, deopt, counter) {
141 try { 147 try {
142 this.x = a + b; 148 deopt.deopt;
149 this.x = val;
143 counter.value++; 150 counter.value++;
144 } catch(e) { 151 } catch(e) {
145 throw new Error(); 152 throw new Error();
146 } 153 }
147 } 154 }
148 TestInAllContexts(c_unsupported_syntax); 155 TestInAllContexts(c_unsupported_syntax);
149 156
150 157
151 // Regression test: Inlined constructors called as functions do not get their 158 // Regression test: Inlined constructors called as functions do not get their
152 // implicit receiver object set to undefined, even in strict mode. 159 // implicit receiver object set to undefined, even in strict mode.
153 function c_strict(a, b, counter) { 160 function c_strict(val, deopt, counter) {
154 "use strict"; 161 "use strict";
155 this.x = a + b; 162 deopt.deopt;
163 this.x = val;
156 counter.value++; 164 counter.value++;
157 } 165 }
158 TestInAllContexts(c_strict); 166 TestInAllContexts(c_strict);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698