| Index: tests/compiler/dart2js/deferred_inline_restrictions_test.dart
|
| diff --git a/tests/compiler/dart2js/deferred_dont_inline_deferred_globals_test.dart b/tests/compiler/dart2js/deferred_inline_restrictions_test.dart
|
| similarity index 54%
|
| copy from tests/compiler/dart2js/deferred_dont_inline_deferred_globals_test.dart
|
| copy to tests/compiler/dart2js/deferred_inline_restrictions_test.dart
|
| index 2868661fe1ed70914a108876f567b1144993ee92..2bedda3f9cb3778c02a475cfb96e13c874757418 100644
|
| --- a/tests/compiler/dart2js/deferred_dont_inline_deferred_globals_test.dart
|
| +++ b/tests/compiler/dart2js/deferred_inline_restrictions_test.dart
|
| @@ -2,8 +2,8 @@
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| -// Test that the additional runtime type support is output to the right
|
| -// Files when using deferred loading.
|
| +// Test that we do not accidentially leak code from deferred libraries but do
|
| +// allow inlining of empty functions and from main.
|
|
|
| import 'package:expect/expect.dart';
|
| import "package:async_helper/async_helper.dart";
|
| @@ -55,44 +55,83 @@ void main() {
|
| return compiler.libraryLoader.lookupLibrary(Uri.parse(name));
|
| }
|
|
|
| - var main = compiler.mainApp.find(dart2js.Compiler.MAIN);
|
| - Expect.isNotNull(main, "Could not find 'main'");
|
| - compiler.deferredLoadTask.onResolutionComplete(main);
|
| -
|
| var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement;
|
|
|
| var lib1 = lookupLibrary("memory:lib1.dart");
|
| - var foo1 = lib1.find("finalVar");
|
| - var ou_lib1 = outputUnitForElement(foo1);
|
| + var inlineMeAway = lib1.find("inlineMeAway");
|
| + var ou_lib1 = outputUnitForElement(inlineMeAway);
|
| +
|
| + var lib3 = lookupLibrary("memory:lib3.dart");
|
| + var sameContextInline = lib3.find("sameContextInline");
|
| + var ou_lib3 = outputUnitForElement(sameContextInline);
|
| +
|
| + // Test that we actually got differnt output units.
|
| + Expect.notEquals(ou_lib1.name, ou_lib3.name);
|
|
|
| String mainOutput = outputs["main.js"].mem.toString();
|
| String lib1Output = outputs["out_${ou_lib1.name}.part.js"].mem.toString();
|
| - // Test that the deferred globals are not inlined into the main file.
|
| - RegExp re1 = new RegExp(r"= .string1");
|
| - RegExp re2 = new RegExp(r"= .string2");
|
| - Expect.isTrue(re1.hasMatch(lib1Output));
|
| - Expect.isTrue(re2.hasMatch(lib1Output));
|
| + String lib3Output = outputs["out_${ou_lib3.name}.part.js"].mem.toString();
|
| +
|
| + RegExp re1 = new RegExp(r"inlined as empty");
|
| + RegExp re2 = new RegExp(r"inlined from main");
|
| + RegExp re3 = new RegExp(r"inlined from lib1");
|
| + RegExp re4 = new RegExp(r"inline same context");
|
| +
|
| + // Test that inlineMeAway was inlined and its argument thus dropped.
|
| Expect.isFalse(re1.hasMatch(mainOutput));
|
| +
|
| + // Test that inlineFromMain was inlined and thus the string moved to lib1.
|
| Expect.isFalse(re2.hasMatch(mainOutput));
|
| + Expect.isTrue(re2.hasMatch(lib1Output));
|
| +
|
| + // Test that inlineFromLib1 was not inlined into main.
|
| + Expect.isFalse(re3.hasMatch(mainOutput));
|
| + Expect.isTrue(re3.hasMatch(lib1Output));
|
| +
|
| + // Test that inlineSameContext was inlined into lib1.
|
| + Expect.isFalse(re4.hasMatch(lib3Output));
|
| + Expect.isTrue(re4.hasMatch(lib1Output));
|
| }));
|
| }
|
|
|
| -// Make sure that deferred constants are not inlined into the main hunk.
|
| +// Make sure that empty functions are inlined and that functions from
|
| +// main also are inlined (assuming normal heuristics).
|
| const Map MEMORY_SOURCE_FILES = const {"main.dart": """
|
| import "dart:async";
|
|
|
| import 'lib1.dart' deferred as lib1;
|
| +import 'lib2.dart' deferred as lib2;
|
| +
|
| +inlineFromMain(x) => "inlined from main" + x;
|
|
|
| void main() {
|
| lib1.loadLibrary().then((_) {
|
| - print(lib1.finalVar);
|
| - print(lib1.globalVar);
|
| - lib1.globalVar = "foobar";
|
| - print(lib1.globalVar);
|
| + lib2.loadLibrary().then((_) {
|
| + lib1.test();
|
| + lib2.test();
|
| + print(lib1.inlineMeAway("inlined as empty"));
|
| + print(lib1.inlineFromLib1("should stay"));
|
| + });
|
| });
|
| }
|
| """, "lib1.dart": """
|
| import "main.dart" as main;
|
| -final finalVar = "string1";
|
| -var globalVar = "string2";
|
| +import "lib3.dart" as lib3;
|
| +
|
| +inlineMeAway(x) {}
|
| +
|
| +inlineFromLib1(x) => "inlined from lib1" + x;
|
| +
|
| +test() {
|
| + print(main.inlineFromMain("should be inlined"));
|
| + print(lib3.sameContextInline("should be inlined"));
|
| +}
|
| +""", "lib2.dart": """
|
| +import "lib3.dart" as lib3;
|
| +
|
| +test() {
|
| + print(lib3.sameContextInline("should be inlined"));
|
| +}
|
| +""", "lib3.dart": """
|
| +sameContextInline(x) => "inline same context" + x;
|
| """};
|
|
|