Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 | |
| 6 function make_dont_inline_comment(ident) { | |
| 7 ident = " ".repeat(ident); | |
| 8 var s = " Don't inline."; | |
| 9 s += s; | |
| 10 s += s; | |
| 11 var line = "//" + s; | |
| 12 for (var i = 0; i < 4; i++) { | |
| 13 line += "\n" + ident + line; | |
| 14 } | |
| 15 return line; | |
| 16 }; | |
| 17 | |
| 18 var CAN_INLINE_COMMENT = "// Let it be inlined."; | |
| 19 var DONT_INLINE_COMMENT = make_dont_inline_comment(2); | |
| 20 | |
| 21 | |
| 22 | |
| 23 var test_header = `// Copyright 2016 the V8 project authors. All rights reserved . | |
| 24 // Use of this source code is governed by a BSD-style license that can be | |
| 25 // found in the LICENSE file. | |
| 26 | |
| 27 // Flags: --allow-natives-syntax --harmony-tailcalls --no-turbo-inlining | |
| 28 | |
| 29 // | |
| 30 // This is an auto-generated file. Do not modify. | |
| 31 // See test/mjsunit/es6/tail-call-mega-generator.js for details. | |
| 32 // | |
| 33 "use strict"; | |
| 34 | |
| 35 Error.prepareStackTrace = (error,stack) => { | |
| 36 error.strace = stack; | |
| 37 return error.message + "\\n at " + stack.join("\\n at "); | |
| 38 } | |
| 39 | |
| 40 | |
| 41 function CheckStackTrace(expected) { | |
| 42 var e = new Error(); | |
| 43 e.stack; // prepare stack trace | |
| 44 var stack = e.strace; | |
| 45 assertEquals("CheckStackTrace", stack[0].getFunctionName()); | |
| 46 for (var i = 0; i < expected.length; i++) { | |
| 47 assertEquals(expected[i].name, stack[i + 1].getFunctionName()); | |
| 48 } | |
| 49 ${DONT_INLINE_COMMENT} | |
| 50 } | |
| 51 | |
| 52 function CheckArguments(expected, args) { | |
| 53 args = Array.prototype.slice.call(args); | |
| 54 assertEquals(expected, args); | |
| 55 ${DONT_INLINE_COMMENT} | |
| 56 } | |
| 57 | |
| 58 `; // var test_header | |
| 59 | |
| 60 | |
| 61 function ident_source(source, ident) { | |
| 62 ident = " ".repeat(ident); | |
| 63 return ident + source.replace(/\n/gi, "\n" + ident); | |
| 64 } | |
| 65 | |
| 66 | |
| 67 // | |
| 68 // Generates source for test/mjsunit/es6/tail-call-mega.js | |
| 69 // | |
| 70 function generate_test() { | |
| 71 | |
| 72 function f_template_normal(f_inlinable, f_args) { | |
| 73 var f_comment = f_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT; | |
| 74 var lines = [ | |
| 75 `function f(a) {`, | |
| 76 ` ${f_comment}`, | |
| 77 ` assertEquals(undefined, this);`, | |
| 78 ` CheckArguments([${f_args}], arguments);`, | |
| 79 ` CheckStackTrace([f, test]);`, | |
| 80 ` %DeoptimizeNow();`, | |
| 81 ` CheckArguments([${f_args}], arguments);`, | |
| 82 ` CheckStackTrace([f, test]);`, | |
| 83 ` return 42;`, | |
| 84 `}`, | |
| 85 ]; | |
| 86 return lines.join("\n"); | |
| 87 } | |
| 88 | |
| 89 function f_template_bound(f_inlinable, f_args) { | |
| 90 var f_comment = f_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT; | |
| 91 var lines = [ | |
| 92 `function ff(a) {`, | |
| 93 ` ${f_comment}`, | |
| 94 ` assertEquals(153, this.a);`, | |
| 95 ` CheckArguments([${f_args}], arguments);`, | |
| 96 ` CheckStackTrace([ff, test]);`, | |
| 97 ` %DeoptimizeNow();`, | |
| 98 ` CheckArguments([${f_args}], arguments);`, | |
| 99 ` CheckStackTrace([ff, test]);`, | |
| 100 ` return 42;`, | |
| 101 `}`, | |
| 102 `var f = ff.bind({a: 153});`, | |
| 103 ]; | |
| 104 return lines.join("\n"); | |
| 105 } | |
| 106 | |
| 107 function f_template_proxy(f_inlinable, f_args) { | |
| 108 var f_comment = f_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT; | |
| 109 var lines = [ | |
| 110 `function ff(a) {`, | |
| 111 ` ${f_comment}`, | |
| 112 ` assertEquals(undefined, this);`, | |
| 113 ` CheckArguments([${f_args}], arguments);`, | |
| 114 ` CheckStackTrace([f, test]);`, | |
| 115 ` %DeoptimizeNow();`, | |
| 116 ` CheckArguments([${f_args}], arguments);`, | |
| 117 ` CheckStackTrace([f, test]);`, | |
| 118 ` return 42;`, | |
| 119 `}`, | |
| 120 `var f = new Proxy(ff, {});`, | |
| 121 ]; | |
| 122 return lines.join("\n"); | |
| 123 } | |
| 124 | |
| 125 function g_template(g_inlinable, f_args, g_args) { | |
| 126 var g_comment = g_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT; | |
| 127 var lines = [ | |
| 128 `function g(a) {`, | |
| 129 ` ${g_comment}`, | |
| 130 ` CheckArguments([${g_args}], arguments);`, | |
| 131 ` return f(${f_args});`, | |
| 132 `}`, | |
| 133 ]; | |
| 134 return lines.join("\n"); | |
| 135 } | |
| 136 | |
| 137 function test_template(f_source, g_source, g_args, | |
| 138 f_inlinable, g_inlinable) { | |
| 139 f_source = ident_source(f_source, 2); | |
| 140 g_source = ident_source(g_source, 2); | |
| 141 | |
| 142 var lines = [ | |
| 143 `(function() {`, | |
| 144 f_source, | |
| 145 g_source, | |
| 146 ` function test() {`, | |
| 147 ` assertEquals(42, g(${g_args}));`, | |
| 148 ` }`, | |
| 149 ` ${f_inlinable ? "%SetForceInlineFlag(f)" : ""};`, | |
| 150 ` ${g_inlinable ? "%SetForceInlineFlag(g)" : ""};`, | |
| 151 ``, | |
| 152 ` test();`, | |
| 153 ` %OptimizeFunctionOnNextCall(test);`, | |
| 154 ` try { %OptimizeFunctionOnNextCall(f); } catch(e) {}`, | |
| 155 ` try { %OptimizeFunctionOnNextCall(ff); } catch(e) {}`, | |
| 156 ` %OptimizeFunctionOnNextCall(g);`, | |
| 157 ` test();`, | |
| 158 `})();`, | |
| 159 ``, | |
| 160 ]; | |
| 161 var source = lines.join("\n"); | |
| 162 return source; | |
| 163 } | |
| 164 | |
| 165 // TODO(v8:4698), TODO(ishell): support all commented cases. | |
| 166 var f_args_variants = ["", "1", "1, 2"]; | |
| 167 var g_args_variants = [/*"",*/ "10", /*"10, 20"*/]; | |
| 168 var f_inlinable_variants = [/*true,*/ false]; | |
| 169 var g_inlinable_variants = [true, false]; | |
| 170 var f_variants = [ | |
| 171 f_template_normal, | |
| 172 f_template_bound, | |
| 173 f_template_proxy | |
| 174 ]; | |
| 175 | |
| 176 f_variants.forEach((f_template) => { | |
| 177 f_args_variants.forEach((f_args) => { | |
| 178 g_args_variants.forEach((g_args) => { | |
| 179 f_inlinable_variants.forEach((f_inlinable) => { | |
| 180 g_inlinable_variants.forEach((g_inlinable) => { | |
| 181 var f_source = f_template(f_inlinable, f_args); | |
| 182 var g_source = g_template(g_inlinable, f_args, g_args); | |
| 183 var source = test_template(f_source, g_source, g_args, | |
| 184 f_inlinable, g_inlinable); | |
| 185 print(source); | |
| 186 }); | |
| 187 }); | |
| 188 }); | |
| 189 }); | |
| 190 }); | |
| 191 } | |
| 192 | |
| 193 print(test_header); | |
| 194 generate_test(); | |
|
Jarin
2016/02/18 07:51:41
How about running the generated test through eval
Igor Sheludko
2016/02/18 07:56:32
I did that initially, but when something fails in
| |
| 195 print("// The end."); | |
| OLD | NEW |