| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 final String TEST_ONE = @""" | 7 final String TEST_ONE = @""" |
| 8 sum(param0, param1) { | 8 sum(param0, param1) { |
| 9 var sum = 0; | 9 var sum = 0; |
| 10 for (var i = param0; i < param1; i += 1) sum = sum + i; | 10 for (var i = param0; i < param1; i += 1) sum = sum + i; |
| 11 return sum; | 11 return sum; |
| 12 } | 12 } |
| 13 """; | 13 """; |
| 14 | 14 |
| 15 final String TEST_TWO = @""" | 15 final String TEST_TWO = @""" |
| 16 foo(int param0) { | 16 foo(int param0) { |
| 17 return -param0; | 17 return -param0; |
| 18 } | 18 } |
| 19 """; | 19 """; |
| 20 | 20 |
| 21 final String TEST_TWO_WITH_BAILOUT = @""" | |
| 22 foo(int param0) { | |
| 23 var t; | |
| 24 for (int i = 0; i < 1; i++) { | |
| 25 t = -param0; | |
| 26 } | |
| 27 return t; | |
| 28 } | |
| 29 """; | |
| 30 | |
| 31 final String TEST_THREE = @""" | 21 final String TEST_THREE = @""" |
| 32 foo(c) { | 22 foo(c) { |
| 33 for (int i = 0; i < 10; i++) print(c[i]); | 23 for (int i = 0; i < 10; i++) print(c[i]); |
| 34 } | 24 } |
| 35 """; | 25 """; |
| 36 | 26 |
| 37 final String TEST_FOUR = @""" | 27 final String TEST_FOUR = @""" |
| 38 foo(String c) { | 28 foo(String c) { |
| 39 print(c[0]); // Force a type guard. | 29 print(c[0]); // Force a type guard. |
| 40 while (true) print(c.length); | 30 while (true) print(c.length); |
| 41 } | 31 } |
| 42 """; | 32 """; |
| 43 | 33 |
| 44 final String TEST_FIVE = @""" | 34 final String TEST_FIVE = @""" |
| 45 foo(a) { | 35 foo(a) { |
| 46 a[0] = 1; | 36 a[0] = 1; |
| 47 print(a[1]); | 37 print(a[1]); |
| 48 } | 38 } |
| 49 """; | 39 """; |
| 50 | 40 |
| 51 final String TEST_FIVE_WITH_BAILOUT = @""" | |
| 52 foo(a) { | |
| 53 for (int i = 0; i < 1; i++) { | |
| 54 a[0] = 1; | |
| 55 print(a[1]); | |
| 56 } | |
| 57 } | |
| 58 """; | |
| 59 | |
| 60 final String TEST_SIX = @""" | 41 final String TEST_SIX = @""" |
| 61 foo(a) { | 42 main(a) { |
| 62 print(a[0]); | 43 print(a[0]); |
| 63 while (true) { | 44 while (true) { |
| 64 a[0] = a[1]; | 45 a[0] = a[1]; |
| 65 } | 46 } |
| 66 } | 47 } |
| 67 """; | 48 """; |
| 68 | 49 |
| 69 main() { | 50 main() { |
| 70 String generated = compile(TEST_ONE, 'sum'); | 51 String generated = compile(TEST_ONE, 'sum'); |
| 71 | 52 |
| 72 RegExp regexp = new RegExp("sum = \\(?$anyIdentifier \\+ $anyIdentifier\\)?"); | 53 RegExp regexp = new RegExp("sum = \\(?$anyIdentifier \\+ $anyIdentifier\\)?"); |
| 73 Expect.isTrue(regexp.hasMatch(generated)); | 54 Expect.isTrue(regexp.hasMatch(generated)); |
| 74 | 55 |
| 75 regexp = const RegExp("typeof param1 !== 'number'"); | 56 regexp = const RegExp("typeof param1 !== 'number'"); |
| 76 Expect.isTrue(regexp.hasMatch(generated)); | 57 Expect.isTrue(regexp.hasMatch(generated)); |
| 77 | 58 |
| 78 generated = compile(TEST_TWO, 'foo'); | 59 generated = compile(TEST_TWO, 'foo'); |
| 79 regexp = new RegExp(getNumberTypeCheck('param0')); | 60 regexp = new RegExp(getNumberTypeCheck('param0')); |
| 80 Expect.isTrue(!regexp.hasMatch(generated)); | |
| 81 | |
| 82 regexp = const RegExp('-param0'); | |
| 83 Expect.isTrue(!regexp.hasMatch(generated)); | |
| 84 | |
| 85 generated = compile(TEST_TWO_WITH_BAILOUT, 'foo'); | |
| 86 regexp = new RegExp(getNumberTypeCheck('param0')); | |
| 87 Expect.isTrue(regexp.hasMatch(generated)); | 61 Expect.isTrue(regexp.hasMatch(generated)); |
| 88 | 62 |
| 89 regexp = const RegExp('-param0'); | 63 regexp = const RegExp('-param0'); |
| 90 Expect.isTrue(regexp.hasMatch(generated)); | 64 Expect.isTrue(regexp.hasMatch(generated)); |
| 91 | 65 |
| 92 generated = compile(TEST_THREE, 'foo'); | 66 generated = compile(TEST_THREE, 'foo'); |
| 93 regexp = new RegExp("c[$anyIdentifier]"); | 67 regexp = new RegExp("c[$anyIdentifier]"); |
| 94 Expect.isTrue(regexp.hasMatch(generated)); | 68 Expect.isTrue(regexp.hasMatch(generated)); |
| 95 | 69 |
| 96 generated = compile(TEST_FOUR, 'foo'); | 70 generated = compile(TEST_FOUR, 'foo'); |
| 97 regexp = new RegExp("c.length"); | 71 regexp = new RegExp("c.length"); |
| 98 Expect.isTrue(regexp.hasMatch(generated)); | 72 Expect.isTrue(regexp.hasMatch(generated)); |
| 99 | 73 |
| 100 generated = compile(TEST_FIVE, 'foo'); | 74 generated = compile(TEST_FIVE, 'foo'); |
| 101 regexp = const RegExp('a.constructor !== Array'); | 75 regexp = const RegExp('a.constructor !== Array'); |
| 102 Expect.isTrue(!regexp.hasMatch(generated)); | |
| 103 Expect.isTrue(generated.contains('index')); | |
| 104 Expect.isTrue(generated.contains('indexSet')); | |
| 105 | |
| 106 generated = compile(TEST_FIVE_WITH_BAILOUT, 'foo'); | |
| 107 regexp = const RegExp('a.constructor !== Array'); | |
| 108 Expect.isTrue(regexp.hasMatch(generated)); | 76 Expect.isTrue(regexp.hasMatch(generated)); |
| 109 Expect.isTrue(!generated.contains('index')); | 77 Expect.isTrue(!generated.contains('index')); |
| 110 Expect.isTrue(!generated.contains('indexSet')); | 78 Expect.isTrue(!generated.contains('indexSet')); |
| 111 | 79 |
| 112 generated = compile(TEST_SIX, 'foo'); | 80 generated = compile(TEST_FIVE, 'foo'); |
| 113 regexp = const RegExp('a.constructor !== Array'); | 81 regexp = const RegExp('a.constructor !== Array'); |
| 114 Expect.isTrue(regexp.hasMatch(generated)); | 82 Expect.isTrue(regexp.hasMatch(generated)); |
| 115 Expect.isTrue(!generated.contains('index')); | 83 Expect.isTrue(!generated.contains('index')); |
| 116 Expect.isTrue(!generated.contains('indexSet')); | 84 Expect.isTrue(!generated.contains('indexSet')); |
| 117 } | 85 } |
| OLD | NEW |