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

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

Issue 10836258: Improved constructor inlining unit tests. (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 11 matching lines...) Expand all
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 --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(closure) { 32 function TestInlinedConstructor(constructor, closure) {
33 var result; 33 var result;
34 var counter = { value:0 }; 34 var counter = { value:0 };
35 result = closure(11, 12, counter); 35
36 result = closure(constructor, 11, 12, counter);
36 assertEquals(23, result); 37 assertEquals(23, result);
37 assertEquals(1, counter.value); 38 assertEquals(1, counter.value);
38 result = closure(23, 19, counter); 39
40 result = closure(constructor, 23, 19, counter);
39 assertEquals(42, result); 41 assertEquals(42, result);
40 assertEquals(2, counter.value); 42 assertEquals(2, counter.value);
43
41 %OptimizeFunctionOnNextCall(closure); 44 %OptimizeFunctionOnNextCall(closure);
42 result = closure(1, 42, counter) 45 result = closure(constructor, 1, 42, counter);
43 assertEquals(43, result); 46 assertEquals(43, result);
44 assertEquals(3, counter.value); 47 assertEquals(3, counter.value);
45 result = closure("foo", "bar", counter) 48
49 result = closure(constructor, "foo", "bar", counter);
46 assertEquals("foobar", result) 50 assertEquals("foobar", result)
47 assertEquals(4, counter.value); 51 assertEquals(4, counter.value);
52
53 %DeoptimizeFunction(closure);
54 %ClearFunctionTypeFeedback(closure);
55 }
56
57 function value_context(constructor, a, b, counter) {
58 var obj = new constructor(a, b, counter);
59 return obj.x;
60 }
61
62 function test_context(constructor, a, b, counter) {
63 if (!new constructor(a, b, counter)) {
64 assertUnreachable("should not happen");
65 }
66 return a + b;
67 }
68
69 function effect_context(constructor, a, b, counter) {
70 new constructor(a, b, counter);
71 return a + b;
48 } 72 }
49 73
50 function TestInAllContexts(constructor) { 74 function TestInAllContexts(constructor) {
51 function value_context(a, b, counter) { 75 TestInlinedConstructor(constructor, value_context);
52 var obj = new constructor(a, b, counter); 76 TestInlinedConstructor(constructor, test_context);
53 return obj.x; 77 TestInlinedConstructor(constructor, effect_context);
54 }
55 function test_context(a, b, counter) {
56 if (!new constructor(a, b, counter)) {
57 assertUnreachable("should not happen");
58 }
59 return a + b;
60 }
61 function effect_context(a, b, counter) {
62 new constructor(a, b, counter);
63 return a + b;
64 }
65 TestInlinedConstructor(value_context);
66 TestInlinedConstructor(test_context);
67 TestInlinedConstructor(effect_context);
68 %DeoptimizeFunction(value_context);
69 %DeoptimizeFunction(test_context);
70 %DeoptimizeFunction(effect_context);
71 %ClearFunctionTypeFeedback(value_context);
72 %ClearFunctionTypeFeedback(test_context);
73 %ClearFunctionTypeFeedback(effect_context);
74 } 78 }
75 79
76 80
77 // Test constructor returning nothing in all contexts. 81 // Test constructor returning nothing in all contexts.
78 function c1(a, b, counter) { 82 function c1(a, b, counter) {
79 this.x = a + b; 83 this.x = a + b;
80 counter.value++; 84 counter.value++;
81 } 85 }
82 TestInAllContexts(c1); 86 TestInAllContexts(c1);
83 87
84 88
85 // Test constructor returning an object in all contexts. 89 // Test constructor returning an object in all contexts.
86 function c2(a, b, counter) { 90 function c2(a, b, counter) {
87 var obj = new Object(); 91 var obj = {};
88 obj.x = a + b; 92 obj.x = a + b;
89 counter.value++; 93 counter.value++;
90 return obj; 94 return obj;
91 } 95 }
92 TestInAllContexts(c2); 96 TestInAllContexts(c2);
93 97
94 98
95 // Test constructor returning a primitive value in all contexts. 99 // Test constructor returning a primitive value in all contexts.
96 function c3(a, b, counter) { 100 function c3(a, b, counter) {
97 this.x = a + b; 101 this.x = a + b;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 149
146 150
147 // Regression test: Inlined constructors called as functions do not get their 151 // Regression test: Inlined constructors called as functions do not get their
148 // implicit receiver object set to undefined, even in strict mode. 152 // implicit receiver object set to undefined, even in strict mode.
149 function c_strict(a, b, counter) { 153 function c_strict(a, b, counter) {
150 "use strict"; 154 "use strict";
151 this.x = a + b; 155 this.x = a + b;
152 counter.value++; 156 counter.value++;
153 } 157 }
154 TestInAllContexts(c_strict); 158 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