Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: tests/compiler/dart2js/dart_backend_test.dart

Issue 383413003: Add @Native(...) annotation for native class names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'dart:async'; 6 import 'dart:async';
7 import "package:async_helper/async_helper.dart"; 7 import "package:async_helper/async_helper.dart";
8 import 'mock_compiler.dart'; 8 import 'mock_compiler.dart';
9 import 'mock_libraries.dart';
9 import 'package:compiler/compiler.dart'; 10 import 'package:compiler/compiler.dart';
10 import 'package:compiler/implementation/dart2jslib.dart' as leg; 11 import 'package:compiler/implementation/dart2jslib.dart' as leg;
11 import 'package:compiler/implementation/dart_backend/dart_backend.dart'; 12 import 'package:compiler/implementation/dart_backend/dart_backend.dart';
12 import 'package:compiler/implementation/elements/elements.dart'; 13 import 'package:compiler/implementation/elements/elements.dart';
13 import 'package:compiler/implementation/tree/tree.dart'; 14 import 'package:compiler/implementation/tree/tree.dart';
14 15
15 const coreLib = r''' 16 const coreLib = const {
16 library corelib; 17 'Math': '''class Math {
floitsch 2014/07/14 19:32:59 this should be double.parse. We don't have a clas
Johnni Winther 2014/07/18 08:59:32 Changed.
17 class Object { 18 static double parseDouble(String s) => 1.0;
18 Object(); 19 }''',
19 } 20 };
20 class bool {}
21 class num {}
22 class int extends num {}
23 class double extends num {}
24 abstract class String {}
25 class Function {}
26 class List<T> {}
27 class Map<K,V> {}
28 class BoundClosure {}
29 class Closure {}
30 class Dynamic_ {}
31 class Null {}
32 class TypeError {}
33 class Type {}
34 class StackTrace {}
35 class LinkedHashMap {
36 factory LinkedHashMap._empty() => null;
37 factory LinkedHashMap._literal(elements) => null;
38 }
39 class Math {
40 static double parseDouble(String s) => 1.0;
41 }
42 print(x) {}
43 identical(a, b) => true;
44 const proxy = 0;
45 ''';
46
47 const corePatch = r'''
48 import 'dart:_js_helper';
49 import 'dart:_interceptors';
50 import 'dart:_isolate_helper';
51 import 'dart:_foreign_helper';
52 ''';
53 21
54 const ioLib = r''' 22 const ioLib = r'''
55 library io; 23 library io;
56 class Platform { 24 class Platform {
57 static int operatingSystem; 25 static int operatingSystem;
58 } 26 }
59 '''; 27 ''';
60 28
61 const htmlLib = r''' 29 const htmlLib = r'''
62 library html; 30 library html;
63 Window __window; 31 Window __window;
64 Window get window => __window; 32 Window get window => __window;
65 abstract class Window { 33 abstract class Window {
66 Navigator get navigator; 34 Navigator get navigator;
67 } 35 }
68 abstract class Navigator { 36 abstract class Navigator {
69 String get userAgent; 37 String get userAgent;
70 } 38 }
71 '''; 39 ''';
72 40
73 const helperLib = r'''
74 library js_helper;
75 class JSInvocationMirror {}
76 assertHelper(a) {}
77 class Closure {}
78 class BoundClosure {}
79 const patch = 0;
80 ''';
81
82 const foreignLib = r'''
83 var JS;
84 ''';
85
86 const isolateHelperLib = r'''
87 class _WorkerStub {
88 }
89 ''';
90
91 testDart2Dart(String src, {void continuation(String s), bool minify: false, 41 testDart2Dart(String src, {void continuation(String s), bool minify: false,
92 bool stripTypes: false}) { 42 bool stripTypes: false}) {
93 // If continuation is not provided, check that source string remains the same. 43 // If continuation is not provided, check that source string remains the same.
94 if (continuation == null) { 44 if (continuation == null) {
95 continuation = (s) { Expect.equals(src, s); }; 45 continuation = (s) { Expect.equals(src, s); };
96 } 46 }
97 testDart2DartWithLibrary(src, '', continuation: continuation, minify: minify, 47 testDart2DartWithLibrary(src, '', continuation: continuation, minify: minify,
98 stripTypes: stripTypes); 48 stripTypes: stripTypes);
99 } 49 }
100 50
101 /** 51 /**
102 * Library name is assumed to be 'mylib' in 'mylib.dart' file. 52 * Library name is assumed to be 'mylib' in 'mylib.dart' file.
103 */ 53 */
104 testDart2DartWithLibrary( 54 testDart2DartWithLibrary(
105 String srcMain, String srcLibrary, 55 String srcMain, String srcLibrary,
106 {void continuation(String s), bool minify: false, 56 {void continuation(String s), bool minify: false,
107 bool stripTypes: false}) { 57 bool stripTypes: false}) {
108 fileUri(path) => new Uri(scheme: 'file', path: path); 58 fileUri(path) => new Uri(scheme: 'file', path: path);
109 59
110 final scriptUri = fileUri('script.dart'); 60 final scriptUri = fileUri('script.dart');
111 final libUri = fileUri('mylib.dart'); 61 final libUri = fileUri('mylib.dart');
112 62
113 provider(uri) { 63 provider(uri) {
114 if (uri == scriptUri) return new Future.value(srcMain); 64 if (uri == scriptUri) return new Future.value(srcMain);
115 if (uri.toString() == libUri.toString()) { 65 if (uri.toString() == libUri.toString()) {
116 return new Future.value(srcLibrary); 66 return new Future.value(srcLibrary);
117 } 67 }
118 if (uri.path.endsWith('/core.dart')) { 68 if (uri.path.endsWith('/core.dart')) {
119 return new Future.value(coreLib); 69 return new Future.value(
70 buildLibrarySource(DEFAULT_CORE_LIBRARY, coreLib));
120 } else if (uri.path.endsWith('/core_patch.dart')) { 71 } else if (uri.path.endsWith('/core_patch.dart')) {
121 return new Future.value(corePatch); 72 return new Future.value(DEFAULT_PATCH_CORE_SOURCE);
122 } else if (uri.path.endsWith('/io.dart')) { 73 } else if (uri.path.endsWith('/io.dart')) {
123 return new Future.value(ioLib); 74 return new Future.value(ioLib);
124 } else if (uri.path.endsWith('/js_helper.dart')) { 75 } else if (uri.path.endsWith('/js_helper.dart')) {
125 return new Future.value(helperLib); 76 return new Future.value(buildLibrarySource(DEFAULT_JS_HELPER_LIBRARY));
126 } else if (uri.path.endsWith('/html_dart2js.dart')) { 77 } else if (uri.path.endsWith('/html_dart2js.dart')) {
127 // TODO(smok): The file should change to html_dartium at some point. 78 // TODO(smok): The file should change to html_dartium at some point.
128 return new Future.value(htmlLib); 79 return new Future.value(htmlLib);
129 } else if (uri.path.endsWith('/foreign_helper.dart')) { 80 } else if (uri.path.endsWith('/foreign_helper.dart')) {
130 return new Future.value(foreignLib); 81 return new Future.value(
82 buildLibrarySource(DEFAULT_FOREIGN_HELPER_LIBRARY));
131 } else if (uri.path.endsWith('/isolate_helper.dart')) { 83 } else if (uri.path.endsWith('/isolate_helper.dart')) {
132 return new Future.value(isolateHelperLib); 84 return new Future.value(
85 buildLibrarySource(DEFAULT_ISOLATE_HELPER_LIBRARY));
133 } 86 }
134 return new Future.value(''); 87 return new Future.value('');
135 } 88 }
136 89
137 handler(uri, begin, end, message, kind) { 90 handler(uri, begin, end, message, kind) {
138 if (identical(kind, Diagnostic.ERROR) || identical(kind, Diagnostic.CRASH)) { 91 if (identical(kind, Diagnostic.ERROR) || identical(kind, Diagnostic.CRASH)) {
139 Expect.fail('$uri: $begin-$end: $message [$kind]'); 92 Expect.fail('$uri: $begin-$end: $message [$kind]');
140 } 93 }
141 } 94 }
142 95
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 new B<Object>(); 536 new B<Object>();
584 } 537 }
585 class A<T extends Object> {} 538 class A<T extends Object> {}
586 class B<T extends Object> extends A<T> {} 539 class B<T extends Object> extends A<T> {}
587 '''); 540 ''');
588 } 541 }
589 542
590 testStaticInvocation() { 543 testStaticInvocation() {
591 testDart2Dart(''' 544 testDart2Dart('''
592 main() { 545 main() {
593 var x = Math.parseDouble("1"); 546 var x = Math.parseDouble("1");
floitsch 2014/07/14 19:32:59 change to double.parse("1"); ?
Johnni Winther 2014/07/18 08:59:32 Done.
594 } 547 }
595 '''); 548 ''');
596 } 549 }
597 550
598 testLibraryGetSet() { 551 testLibraryGetSet() {
599 var librarySrc = ''' 552 var librarySrc = '''
600 library mylib; 553 library mylib;
601 554
602 get topgetset => 5; 555 get topgetset => 5;
603 set topgetset(arg) {} 556 set topgetset(arg) {}
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 testStaticAccessIoLib(); 941 testStaticAccessIoLib();
989 testLocalFunctionPlaceholder(); 942 testLocalFunctionPlaceholder();
990 testMinification(); 943 testMinification();
991 testClosureLocalsMinified(); 944 testClosureLocalsMinified();
992 testParametersMinified(); 945 testParametersMinified();
993 testDeclarationTypePlaceholders(); 946 testDeclarationTypePlaceholders();
994 testPlatformLibraryMemberNamesAreFixed(); 947 testPlatformLibraryMemberNamesAreFixed();
995 testConflictsWithCoreLib(); 948 testConflictsWithCoreLib();
996 testUnresolvedNamedConstructor(); 949 testUnresolvedNamedConstructor();
997 } 950 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698