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

Unified Diff: pkg/compiler/lib/src/apiimpl.dart

Issue 1404183002: Add support for 'dart.library.X' environment variables in dart2js. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add test. Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/compiler/dart2js/library_env_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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];
« no previous file with comments | « no previous file | tests/compiler/dart2js/library_env_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698