Chromium Code Reviews| 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 61% |
| copy from tests/compiler/dart2js/deferred_dont_inline_deferred_globals_test.dart |
| copy to tests/compiler/dart2js/deferred_inline_restrictions_test.dart |
| index 2868661fe1ed70914a108876f567b1144993ee92..36bceb44339868289e1f895fcf68a573722b8fc5 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. |
|
floitsch
2015/05/05 17:58:15
Thanks. I was going to ask for a test like this :)
herhut
2015/05/06 08:37:09
Acknowledged.
|
| import 'package:expect/expect.dart'; |
| import "package:async_helper/async_helper.dart"; |
| @@ -55,44 +55,71 @@ 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); |
| 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"inlineMeAway"); |
|
floitsch
2015/05/05 17:58:15
I would go for the strings instead. The method nam
herhut
2015/05/06 08:37:09
Done.
|
| + RegExp re2 = new RegExp(r"inlineFromMain"); |
| + RegExp re3 = new RegExp(r"inlineFromLib1"); |
| + |
| + Expect.isFalse(re1.hasMatch(lib1Output)); |
| + Expect.isFalse(re2.hasMatch(lib1Output)); |
| + Expect.isTrue(re3.hasMatch(lib1Output)); |
| + |
| Expect.isFalse(re1.hasMatch(mainOutput)); |
| Expect.isFalse(re2.hasMatch(mainOutput)); |
| + Expect.isTrue(re3.hasMatch(mainOutput)); |
| + |
| + Expect.isTrue(re3.hasMatch(lib3Output)); |
| })); |
| } |
| -// 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) => x; |
| void main() { |
| lib1.loadLibrary().then((_) { |
| - print(lib1.finalVar); |
| - print(lib1.globalVar); |
| - lib1.globalVar = "foobar"; |
| - print(lib1.globalVar); |
| + lib1.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) => 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) => x; |
| """}; |