OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, 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 |
| 5 import 'dart:io'; |
| 6 import 'package:expect/expect.dart'; |
| 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'package:compiler/src/dart2jslib.dart'; |
| 9 import 'package:compiler/src/elements/elements.dart'; |
| 10 import 'package:compiler/src/js_backend/js_backend.dart'; |
| 11 import 'memory_compiler.dart'; |
| 12 |
| 13 const Map MEMORY_SOURCE_FILES = const { |
| 14 'main.dart': r""" |
| 15 import 'package:expect/expect.dart'; |
| 16 |
| 17 int method(String arg) => arg.length; |
| 18 |
| 19 @AssumeDynamic() |
| 20 int methodAssumeDynamic(String arg) => arg.length; |
| 21 |
| 22 @TrustTypeAnnotations() |
| 23 int methodTrustTypeAnnotations(String arg) => arg.length; |
| 24 |
| 25 @NoInlining() |
| 26 int methodNoInlining(String arg) => arg.length; |
| 27 |
| 28 @NoInlining() @TrustTypeAnnotations() |
| 29 int methodNoInliningTrustTypeAnnotations(String arg) => arg.length; |
| 30 |
| 31 void main(List<String> args) { |
| 32 print(method(args[0])); |
| 33 print(methodAssumeDynamic('foo')); |
| 34 print(methodTrustTypeAnnotations(null)); |
| 35 print(methodNoInlining('bar')); |
| 36 print(methodNoInliningTrustTypeAnnotations(null)); |
| 37 } |
| 38 """ |
| 39 }; |
| 40 |
| 41 main() { |
| 42 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES); |
| 43 asyncTest(() => compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) { |
| 44 Expect.isFalse(compiler.compilationFailed, 'Unsuccessful compilation'); |
| 45 JavaScriptBackend backend = compiler.backend; |
| 46 Expect.isNotNull(backend.annotations.expectNoInliningClass, |
| 47 'NoInliningClass is unresolved.'); |
| 48 Expect.isNotNull(backend.annotations.expectTrustTypeAnnotationsClass, |
| 49 'TrustTypeAnnotations is unresolved.'); |
| 50 Expect.isNotNull(backend.annotations.expectAssumeDynamicClass, |
| 51 'AssumeDynamicClass is unresolved.'); |
| 52 |
| 53 void test(String name, |
| 54 {bool expectNoInlining: false, |
| 55 bool expectTrustTypeAnnotations: false, |
| 56 bool expectAssumeDynamic: false}) { |
| 57 Element method = compiler.mainApp.find(name); |
| 58 Expect.isNotNull(method); |
| 59 Expect.equals( |
| 60 expectNoInlining, |
| 61 backend.annotations.noInlining(method), |
| 62 "Unexpected annotation of @NoInlining on '$method'."); |
| 63 Expect.equals( |
| 64 expectTrustTypeAnnotations, |
| 65 backend.annotations.trustTypeAnnotations(method), |
| 66 "Unexpected annotation of @TrustTypeAnnotations on '$method'."); |
| 67 Expect.equals( |
| 68 expectAssumeDynamic, |
| 69 backend.annotations.assumeDynamic(method), |
| 70 "Unexpected annotation of @AssumeDynamic on '$method'."); |
| 71 } |
| 72 |
| 73 test('method'); |
| 74 test('methodAssumeDynamic', expectAssumeDynamic: true); |
| 75 test('methodTrustTypeAnnotations', expectTrustTypeAnnotations: true); |
| 76 test('methodNoInlining', expectNoInlining: true); |
| 77 test('methodNoInliningTrustTypeAnnotations', |
| 78 expectNoInlining: true, |
| 79 expectTrustTypeAnnotations: true); |
| 80 })); |
| 81 } |
OLD | NEW |