| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Test that parameters keep their names in the output. | 4 // Test that parameters keep their names in the output. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 import 'compiler_helper.dart'; | 8 import 'compiler_helper.dart'; |
| 9 import 'parser_helper.dart'; | 9 import 'parser_helper.dart'; |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 const String TEST_INVOCATION2 = r""" | 25 const String TEST_INVOCATION2 = r""" |
| 26 main() { | 26 main() { |
| 27 var o = null; | 27 var o = null; |
| 28 o(1, 2); | 28 o(1, 2); |
| 29 } | 29 } |
| 30 """; | 30 """; |
| 31 | 31 |
| 32 const String TEST_BAILOUT = r""" | 32 const String TEST_BAILOUT = r""" |
| 33 class A { | 33 class A { |
| 34 var x; | 34 var x; |
| 35 foo(_) { // make sure only g has no arguments | 35 foo() { |
| 36 var f = function g() { return 499; }; | 36 var f = function g() { return 499; }; |
| 37 return 499 + x + f(); | 37 return 499 + x + f(); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 main() { new A().foo(1); } | 41 main() { new A().foo(); } |
| 42 """; | 42 """; |
| 43 | 43 |
| 44 closureInvocation(bool minify, String prefix) { | 44 closureInvocation() { |
| 45 String generated = compile(TEST_INVOCATION0, minify: minify); | 45 String generated = compile(TEST_INVOCATION0); |
| 46 Expect.isTrue(generated.contains(".$prefix\$0()")); | 46 Expect.isTrue(generated.contains(r".call$0()")); |
| 47 generated = compile(TEST_INVOCATION1, minify: minify); | 47 generated = compile(TEST_INVOCATION1); |
| 48 Expect.isTrue(generated.contains(".$prefix\$1(1)")); | 48 Expect.isTrue(generated.contains(r".call$1(1)")); |
| 49 generated = compile(TEST_INVOCATION2, minify: minify); | 49 generated = compile(TEST_INVOCATION2); |
| 50 Expect.isTrue(generated.contains(".$prefix\$2(1,${minify ? "" : " "}2)")); | 50 Expect.isTrue(generated.contains(r".call$2(1, 2)")); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Make sure that the bailout version does not introduce a second version of | 53 // Make sure that the bailout version does not introduce a second version of |
| 54 // the closure. | 54 // the closure. |
| 55 closureBailout(bool minify, String prefix) { | 55 closureBailout() { |
| 56 asyncTest(() => compileAll(TEST_BAILOUT, minify: minify) | 56 asyncTest(() => compileAll(TEST_BAILOUT).then((generated) { |
| 57 .then((generated) { | 57 RegExp regexp = new RegExp(r'call\$0: function'); |
| 58 RegExp regexp = new RegExp("$prefix\\\$0:${minify ? "" : " "}function"); | |
| 59 Iterator<Match> matches = regexp.allMatches(generated).iterator; | 58 Iterator<Match> matches = regexp.allMatches(generated).iterator; |
| 60 checkNumberOfMatches(matches, 1); | 59 checkNumberOfMatches(matches, 1); |
| 61 })); | 60 })); |
| 62 } | 61 } |
| 63 | 62 |
| 64 main() { | 63 main() { |
| 65 closureInvocation(false, "call"); | 64 closureInvocation(); |
| 66 closureInvocation(true, ""); | 65 closureBailout(); |
| 67 closureBailout(false, "call"); | |
| 68 closureBailout(true, ""); | |
| 69 } | 66 } |
| OLD | NEW |