| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 // Testing optimized 'is' tests. |
| 5 // VMOptions=--optimization-counter-threshold=5 --no-use-osr |
| 6 |
| 7 import "package:expect/expect.dart"; |
| 8 |
| 9 |
| 10 bool isInt(x) => x is int; |
| 11 |
| 12 |
| 13 bool isIntRes(x) { |
| 14 if (x is int) { |
| 15 return 1; |
| 16 } else { |
| 17 return 0; |
| 18 } |
| 19 } |
| 20 |
| 21 |
| 22 bool isNotIntRes(x) { |
| 23 if (x is! int) { |
| 24 return 1; |
| 25 } else { |
| 26 return 0; |
| 27 } |
| 28 } |
| 29 |
| 30 |
| 31 bool isIfThenElseIntRes(x) { |
| 32 return x is int ? 1 : 0; |
| 33 } |
| 34 |
| 35 |
| 36 |
| 37 bool isString(x) => x is String; |
| 38 |
| 39 |
| 40 bool isStringRes(x) { |
| 41 if (x is String) { |
| 42 return 1; |
| 43 } else { |
| 44 return 0; |
| 45 } |
| 46 } |
| 47 |
| 48 |
| 49 bool isNotStringRes(x) { |
| 50 if (x is! String) { |
| 51 return 1; |
| 52 } else { |
| 53 return 0; |
| 54 } |
| 55 } |
| 56 |
| 57 |
| 58 main() { |
| 59 for (int i = 0; i < 20; i++) { |
| 60 Expect.isFalse(isInt(3.2)); |
| 61 Expect.isTrue(isInt(3)); |
| 62 Expect.isTrue(isInt(17179869184)); // Mint on ia32. |
| 63 Expect.isFalse(isString(2.0)); |
| 64 Expect.isTrue(isString("Morgan")); |
| 65 } |
| 66 // No deoptimization of isInt possible since all types are known by the compil
er |
| 67 |
| 68 Expect.isFalse(isString(true)); |
| 69 for (int i = 0; i < 20; i++) { |
| 70 Expect.isFalse(isInt(3.2)); |
| 71 Expect.isTrue(isInt(3)); |
| 72 Expect.isTrue(isInt(17179869184)); // Mint on ia32. |
| 73 Expect.isFalse(isInt("hu")); |
| 74 Expect.isFalse(isString(2.0)); |
| 75 Expect.isTrue(isString("Morgan")); |
| 76 Expect.isFalse(isString(true)); |
| 77 } |
| 78 |
| 79 for (int i = 0; i < 20; i++) { |
| 80 Expect.equals(0, isIntRes(3.2)); |
| 81 Expect.equals(1, isIntRes(3)); |
| 82 Expect.equals(0, isIntRes("hi")); |
| 83 Expect.equals(1, isNotIntRes(3.2)); |
| 84 Expect.equals(0, isNotIntRes(3)); |
| 85 Expect.equals(1, isNotIntRes("hi")); |
| 86 Expect.equals(0, isIfThenElseIntRes(3.2)); |
| 87 Expect.equals(1, isIfThenElseIntRes(3)); |
| 88 Expect.equals(0, isIfThenElseIntRes("hi")); |
| 89 } |
| 90 |
| 91 for (int i = 0; i < 20; i++) { |
| 92 Expect.equals(0, isStringRes(3.2)); |
| 93 Expect.equals(1, isStringRes("Lotus")); |
| 94 Expect.equals(1, isNotStringRes(3.2)); |
| 95 Expect.equals(0, isNotStringRes("Lotus")); |
| 96 } |
| 97 |
| 98 // Deoptimize 'isStringRes', 'isNotIntRes'. |
| 99 Expect.equals(0, isStringRes(null)); |
| 100 Expect.equals(1, isNotIntRes(null)); |
| 101 for (int i = 0; i < 20; i++) { |
| 102 Expect.equals(0, isStringRes(3.2)); |
| 103 Expect.equals(1, isStringRes("Lotus")); |
| 104 Expect.equals(0, isStringRes(null)); |
| 105 |
| 106 Expect.equals(1, isNotStringRes(3.2)); |
| 107 Expect.equals(0, isNotStringRes("Lotus")); |
| 108 Expect.equals(1, isNotStringRes(null)); |
| 109 } |
| 110 } |
| OLD | NEW |