| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 | 4 |
| 5 import 'compiler_helper.dart'; | 5 import 'compiler_helper.dart'; |
| 6 | 6 |
| 7 const String TEST_ONE = r""" | 7 const String TEST_ONE = r""" |
| 8 foo(a) { | 8 foo(a) { |
| 9 // Make sure there is a bailout version. | 9 // Make sure there is a bailout version. |
| 10 foo(a); | 10 foo(a); |
| 11 // This will make a one shot interceptor that will be optimized in | 11 // This will make a one shot interceptor that will be optimized in |
| 12 // the non-bailout version because we know a is a number. | 12 // the non-bailout version because we know a is a number. |
| 13 return (a + 42).toString; | 13 return (a + 42).toString; |
| 14 } | 14 } |
| 15 """; | 15 """; |
| 16 | 16 |
| 17 const String TEST_TWO = r""" | 17 const String TEST_TWO = r""" |
| 18 foo(a) { | 18 foo(a) { |
| 19 var myVariableName = a + 42; | 19 var myVariableName = a + 42; |
| 20 print(myVariableName); | 20 print(myVariableName); |
| 21 print(myVariableName); | 21 print(myVariableName); |
| 22 } | 22 } |
| 23 """; | 23 """; |
| 24 | 24 |
| 25 const String TEST_THREE = r""" |
| 26 class A { |
| 27 var length; |
| 28 } |
| 29 foo(a) { |
| 30 print([]); // Make sure the array class is instantiated. |
| 31 return new A().length + a.length; |
| 32 } |
| 33 """; |
| 34 |
| 25 main() { | 35 main() { |
| 26 var generated = compile(TEST_ONE, entry: 'foo'); | 36 var generated = compile(TEST_ONE, entry: 'foo'); |
| 27 // Check that the one shot interceptor got converted to a direct | 37 // Check that the one shot interceptor got converted to a direct |
| 28 // call to the interceptor object. | 38 // call to the interceptor object. |
| 29 Expect.isTrue(generated.contains('CONSTANT.get\$toString(a + 42);')); | 39 Expect.isTrue(generated.contains('CONSTANT.get\$toString(a + 42);')); |
| 30 | 40 |
| 31 // Check that one-shot interceptors preserve variable names, see | 41 // Check that one-shot interceptors preserve variable names, see |
| 32 // https://code.google.com/p/dart/issues/detail?id=8106. | 42 // https://code.google.com/p/dart/issues/detail?id=8106. |
| 33 generated = compile(TEST_TWO, entry: 'foo'); | 43 generated = compile(TEST_TWO, entry: 'foo'); |
| 34 Expect.isTrue(generated.contains('\$.\$\$add(a, 42)')); | 44 Expect.isTrue(generated.contains('\$.\$\$add(a, 42)')); |
| 35 Expect.isTrue(generated.contains('myVariableName')); | 45 Expect.isTrue(generated.contains('myVariableName')); |
| 46 |
| 47 // Check that an intercepted getter that does not need to be |
| 48 // intercepted, is turned into a regular getter call or field |
| 49 // access. |
| 50 generated = compile(TEST_THREE, entry: 'foo'); |
| 51 Expect.isFalse(generated.contains(r'get$length')); |
| 52 Expect.isTrue(generated.contains(r'$.A$().length')); |
| 53 Expect.isTrue(generated.contains(r'length(a)')); |
| 36 } | 54 } |
| OLD | NEW |