Chromium Code Reviews| Index: pkg/compiler/lib/src/apiimpl.dart |
| diff --git a/pkg/compiler/lib/src/apiimpl.dart b/pkg/compiler/lib/src/apiimpl.dart |
| index e515631bdb9163d8f06ebf1a796f860c2402b6ad..de068f1b5826d03d265166d2c2804d873fdd5182 100644 |
| --- a/pkg/compiler/lib/src/apiimpl.dart |
| +++ b/pkg/compiler/lib/src/apiimpl.dart |
| @@ -39,6 +39,14 @@ import 'script.dart'; |
| const bool forceIncrementalSupport = |
| const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT'); |
| +/// For every 'dart:' library, a corresponding environment variable is set |
| +/// to "true". The environment variable's name is the concatenation of |
| +/// this prefix and the name (without the 'dart:'. |
| +/// |
| +/// For example 'dart:html' has the environment variable 'dart.library.html' set |
| +/// to "true". |
| +const String dartLibraryEnvironmentPrefix = 'dart.library.'; |
| + |
| class Compiler extends leg.Compiler { |
| api.CompilerInput provider; |
| api.CompilerDiagnostics handler; |
| @@ -544,8 +552,25 @@ class Compiler extends leg.Compiler { |
| } |
| } |
| - |
| - fromEnvironment(String name) => environment[name]; |
| + fromEnvironment(String name) { |
| + var result = environment[name]; |
| + if (result == null && !environment.containsKey(name) && |
| + name.startsWith(dartLibraryEnvironmentPrefix)) { |
| + String libraryName = name.substring(dartLibraryEnvironmentPrefix.length); |
| + LibraryInfo info = lookupLibraryInfo(libraryName); |
| + if (info != null && |
| + allowedLibraryCategories.contains(info.category)) { |
| + // Dart2js always "supports" importing 'dart:mirrors' but will abort |
| + // the compilation at a later point if the backend doesn't support |
| + // mirrors. In this case 'mirrors' should not be in the environment. |
| + if (name == dartLibraryEnvironmentPrefix + 'mirrors') { |
| + return backend.supportsReflection ? "true" : null; |
| + } |
| + return "true"; |
| + } |
| + } |
| + return result; |
| + } |
|
Lasse Reichstein Nielsen
2015/10/18 11:45:54
How do environment lookups at runtime ("new String
Johnni Winther
2015/10/19 08:07:56
It's a throwing constructor so only const String.f
|
| LibraryInfo lookupLibraryInfo(String libraryName) { |
| return library_info.LIBRARIES[libraryName]; |