Chromium Code Reviews| Index: test/mjsunit/es6/tail-call-megatest-generator.js |
| diff --git a/test/mjsunit/es6/tail-call-megatest-generator.js b/test/mjsunit/es6/tail-call-megatest-generator.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8f58744398d564d0da68521ad4a293c63f8f6224 |
| --- /dev/null |
| +++ b/test/mjsunit/es6/tail-call-megatest-generator.js |
| @@ -0,0 +1,195 @@ |
| +// Copyright 2016 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| + |
| +function make_dont_inline_comment(ident) { |
| + ident = " ".repeat(ident); |
| + var s = " Don't inline."; |
| + s += s; |
| + s += s; |
| + var line = "//" + s; |
| + for (var i = 0; i < 4; i++) { |
| + line += "\n" + ident + line; |
| + } |
| + return line; |
| +}; |
| + |
| +var CAN_INLINE_COMMENT = "// Let it be inlined."; |
| +var DONT_INLINE_COMMENT = make_dont_inline_comment(2); |
| + |
| + |
| + |
| +var test_header = `// Copyright 2016 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --allow-natives-syntax --harmony-tailcalls --no-turbo-inlining |
| + |
| +// |
| +// This is an auto-generated file. Do not modify. |
| +// See test/mjsunit/es6/tail-call-mega-generator.js for details. |
| +// |
| +"use strict"; |
| + |
| +Error.prepareStackTrace = (error,stack) => { |
| + error.strace = stack; |
| + return error.message + "\\n at " + stack.join("\\n at "); |
| +} |
| + |
| + |
| +function CheckStackTrace(expected) { |
| + var e = new Error(); |
| + e.stack; // prepare stack trace |
| + var stack = e.strace; |
| + assertEquals("CheckStackTrace", stack[0].getFunctionName()); |
| + for (var i = 0; i < expected.length; i++) { |
| + assertEquals(expected[i].name, stack[i + 1].getFunctionName()); |
| + } |
| + ${DONT_INLINE_COMMENT} |
| +} |
| + |
| +function CheckArguments(expected, args) { |
| + args = Array.prototype.slice.call(args); |
| + assertEquals(expected, args); |
| + ${DONT_INLINE_COMMENT} |
| +} |
| + |
| +`; // var test_header |
| + |
| + |
| +function ident_source(source, ident) { |
| + ident = " ".repeat(ident); |
| + return ident + source.replace(/\n/gi, "\n" + ident); |
| +} |
| + |
| + |
| +// |
| +// Generates source for test/mjsunit/es6/tail-call-mega.js |
| +// |
| +function generate_test() { |
| + |
| + function f_template_normal(f_inlinable, f_args) { |
| + var f_comment = f_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT; |
| + var lines = [ |
| + `function f(a) {`, |
| + ` ${f_comment}`, |
| + ` assertEquals(undefined, this);`, |
| + ` CheckArguments([${f_args}], arguments);`, |
| + ` CheckStackTrace([f, test]);`, |
| + ` %DeoptimizeNow();`, |
| + ` CheckArguments([${f_args}], arguments);`, |
| + ` CheckStackTrace([f, test]);`, |
| + ` return 42;`, |
| + `}`, |
| + ]; |
| + return lines.join("\n"); |
| + } |
| + |
| + function f_template_bound(f_inlinable, f_args) { |
| + var f_comment = f_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT; |
| + var lines = [ |
| + `function ff(a) {`, |
| + ` ${f_comment}`, |
| + ` assertEquals(153, this.a);`, |
| + ` CheckArguments([${f_args}], arguments);`, |
| + ` CheckStackTrace([ff, test]);`, |
| + ` %DeoptimizeNow();`, |
| + ` CheckArguments([${f_args}], arguments);`, |
| + ` CheckStackTrace([ff, test]);`, |
| + ` return 42;`, |
| + `}`, |
| + `var f = ff.bind({a: 153});`, |
| + ]; |
| + return lines.join("\n"); |
| + } |
| + |
| + function f_template_proxy(f_inlinable, f_args) { |
| + var f_comment = f_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT; |
| + var lines = [ |
| + `function ff(a) {`, |
| + ` ${f_comment}`, |
| + ` assertEquals(undefined, this);`, |
| + ` CheckArguments([${f_args}], arguments);`, |
| + ` CheckStackTrace([f, test]);`, |
| + ` %DeoptimizeNow();`, |
| + ` CheckArguments([${f_args}], arguments);`, |
| + ` CheckStackTrace([f, test]);`, |
| + ` return 42;`, |
| + `}`, |
| + `var f = new Proxy(ff, {});`, |
| + ]; |
| + return lines.join("\n"); |
| + } |
| + |
| + function g_template(g_inlinable, f_args, g_args) { |
| + var g_comment = g_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT; |
| + var lines = [ |
| + `function g(a) {`, |
| + ` ${g_comment}`, |
| + ` CheckArguments([${g_args}], arguments);`, |
| + ` return f(${f_args});`, |
| + `}`, |
| + ]; |
| + return lines.join("\n"); |
| + } |
| + |
| + function test_template(f_source, g_source, g_args, |
| + f_inlinable, g_inlinable) { |
| + f_source = ident_source(f_source, 2); |
| + g_source = ident_source(g_source, 2); |
| + |
| + var lines = [ |
| + `(function() {`, |
| + f_source, |
| + g_source, |
| + ` function test() {`, |
| + ` assertEquals(42, g(${g_args}));`, |
| + ` }`, |
| + ` ${f_inlinable ? "%SetForceInlineFlag(f)" : ""};`, |
| + ` ${g_inlinable ? "%SetForceInlineFlag(g)" : ""};`, |
| + ``, |
| + ` test();`, |
| + ` %OptimizeFunctionOnNextCall(test);`, |
| + ` try { %OptimizeFunctionOnNextCall(f); } catch(e) {}`, |
| + ` try { %OptimizeFunctionOnNextCall(ff); } catch(e) {}`, |
| + ` %OptimizeFunctionOnNextCall(g);`, |
| + ` test();`, |
| + `})();`, |
| + ``, |
| + ]; |
| + var source = lines.join("\n"); |
| + return source; |
| + } |
| + |
| + // TODO(v8:4698), TODO(ishell): support all commented cases. |
| + var f_args_variants = ["", "1", "1, 2"]; |
| + var g_args_variants = [/*"",*/ "10", /*"10, 20"*/]; |
| + var f_inlinable_variants = [/*true,*/ false]; |
| + var g_inlinable_variants = [true, false]; |
| + var f_variants = [ |
| + f_template_normal, |
| + f_template_bound, |
| + f_template_proxy |
| + ]; |
| + |
| + f_variants.forEach((f_template) => { |
| + f_args_variants.forEach((f_args) => { |
| + g_args_variants.forEach((g_args) => { |
| + f_inlinable_variants.forEach((f_inlinable) => { |
| + g_inlinable_variants.forEach((g_inlinable) => { |
| + var f_source = f_template(f_inlinable, f_args); |
| + var g_source = g_template(g_inlinable, f_args, g_args); |
| + var source = test_template(f_source, g_source, g_args, |
| + f_inlinable, g_inlinable); |
| + print(source); |
| + }); |
| + }); |
| + }); |
| + }); |
| + }); |
| +} |
| + |
| +print(test_header); |
| +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
|
| +print("// The end."); |