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

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

Issue 1235563003: Add interfaces for a new compiler API. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Rebased Created 5 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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 // Test that the additional runtime type support is output to the right 5 // Test that the additional runtime type support is output to the right
6 // Files when using deferred loading. 6 // Files when using deferred loading.
7 7
8 import 'package:async_helper/async_helper.dart';
9 import 'package:compiler/src/dart2jslib.dart';
8 import 'package:expect/expect.dart'; 10 import 'package:expect/expect.dart';
9 import "package:async_helper/async_helper.dart"; 11 import 'memory_compiler.dart';
10 import 'memory_source_file_helper.dart'; 12 import 'output_collector.dart';
11 import "dart:async";
12
13 import 'package:compiler/src/dart2jslib.dart'
14 as dart2js;
15
16 class MemoryOutputSink extends EventSink<String> {
17 StringBuffer mem = new StringBuffer();
18 void add(String event) {
19 mem.write(event);
20 }
21 void addError(String event, [StackTrace stackTrace]) {
22 Expect.isTrue(false);
23 }
24 void close() {}
25 }
26 13
27 void main() { 14 void main() {
28 Uri script = currentDirectory.resolveUri(Platform.script); 15 OutputCollector collector = new OutputCollector();
29 Uri libraryRoot = script.resolve('../../../sdk/'); 16 Compiler compiler = compilerFor(
30 Uri packageRoot = script.resolve('./packages/'); 17 MEMORY_SOURCE_FILES,
31 18 outputProvider: collector);
32 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
33 var handler = new FormattingDiagnosticHandler(provider);
34
35 Map<String, MemoryOutputSink> outputs = new Map<String, MemoryOutputSink>();
36
37 MemoryOutputSink outputSaver(name, extension) {
38 if (name == '') {
39 name = 'main';
40 }
41 return outputs.putIfAbsent("$name.$extension", () {
42 return new MemoryOutputSink();
43 });
44 }
45
46 Compiler compiler = new Compiler(provider.readStringFromUri,
47 outputSaver,
48 handler.diagnosticHandler,
49 libraryRoot,
50 packageRoot,
51 [],
52 {});
53 asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) { 19 asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) {
54 lookupLibrary(name) { 20 lookupLibrary(name) {
55 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); 21 return compiler.libraryLoader.lookupLibrary(Uri.parse(name));
56 } 22 }
57 23
58 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); 24 var main = compiler.mainApp.find(Compiler.MAIN);
59 Expect.isNotNull(main, "Could not find 'main'"); 25 Expect.isNotNull(main, "Could not find 'main'");
60 compiler.deferredLoadTask.onResolutionComplete(main); 26 compiler.deferredLoadTask.onResolutionComplete(main);
61 27
62 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; 28 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement;
63 29
64 var lib1 = lookupLibrary("memory:lib1.dart"); 30 var lib1 = lookupLibrary("memory:lib1.dart");
65 var foo1 = lib1.find("finalVar"); 31 var foo1 = lib1.find("finalVar");
66 var ou_lib1 = outputUnitForElement(foo1); 32 var ou_lib1 = outputUnitForElement(foo1);
67 33
68 String mainOutput = outputs["main.js"].mem.toString(); 34 String mainOutput = collector.getOutput("", "js");
69 String lib1Output = outputs["out_${ou_lib1.name}.part.js"].mem.toString(); 35 String lib1Output = collector.getOutput("out_${ou_lib1.name}", "part.js");
70 // Test that the deferred globals are not inlined into the main file. 36 // Test that the deferred globals are not inlined into the main file.
71 RegExp re1 = new RegExp(r"= .string1"); 37 RegExp re1 = new RegExp(r"= .string1");
72 RegExp re2 = new RegExp(r"= .string2"); 38 RegExp re2 = new RegExp(r"= .string2");
73 Expect.isTrue(re1.hasMatch(lib1Output)); 39 Expect.isTrue(re1.hasMatch(lib1Output));
74 Expect.isTrue(re2.hasMatch(lib1Output)); 40 Expect.isTrue(re2.hasMatch(lib1Output));
75 Expect.isFalse(re1.hasMatch(mainOutput)); 41 Expect.isFalse(re1.hasMatch(mainOutput));
76 Expect.isFalse(re2.hasMatch(mainOutput)); 42 Expect.isFalse(re2.hasMatch(mainOutput));
77 })); 43 }));
78 } 44 }
79 45
80 // Make sure that deferred constants are not inlined into the main hunk. 46 // Make sure that deferred constants are not inlined into the main hunk.
81 const Map MEMORY_SOURCE_FILES = const {"main.dart": """ 47 const Map MEMORY_SOURCE_FILES = const {"main.dart": """
82 import "dart:async"; 48 import "dart:async";
83 49
84 import 'lib1.dart' deferred as lib1; 50 import 'lib1.dart' deferred as lib1;
85 51
86 void main() { 52 void main() {
87 lib1.loadLibrary().then((_) { 53 lib1.loadLibrary().then((_) {
88 print(lib1.finalVar); 54 print(lib1.finalVar);
89 print(lib1.globalVar); 55 print(lib1.globalVar);
90 lib1.globalVar = "foobar"; 56 lib1.globalVar = "foobar";
91 print(lib1.globalVar); 57 print(lib1.globalVar);
92 }); 58 });
93 } 59 }
94 """, "lib1.dart": """ 60 """, "lib1.dart": """
95 import "main.dart" as main; 61 import "main.dart" as main;
96 final finalVar = "string1"; 62 final finalVar = "string1";
97 var globalVar = "string2"; 63 var globalVar = "string2";
98 """}; 64 """};
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698