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

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: Refactor code. Created 4 years, 11 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 8f81d151dcce9e238914c8b690bb1013e1e5b3d2..60754fe913511da6b9bf9615737ffa593d151a22 100644
--- a/pkg/compiler/lib/src/apiimpl.dart
+++ b/pkg/compiler/lib/src/apiimpl.dart
@@ -33,6 +33,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.';
+
/// Locations of the platform descriptor files relative to the library root.
const String _clientPlatform = "lib/dart_client.platform";
const String _serverPlatform = "lib/dart_server.platform";
@@ -580,7 +588,25 @@ class CompilerImpl extends Compiler {
}
}
- fromEnvironment(String name) => environment[name];
+ fromEnvironment(String name) {
+ assert(invariant(NO_LOCATION_SPANNABLE,
+ sdkLibraries != null, message: "setupSdk() has not been run"));
+
+ if (environment.containsKey(name)) return environment[name];
Lasse Reichstein Nielsen 2016/01/11 13:58:35 Could this be: String result = environment[name];
floitsch 2016/01/11 14:18:29 Tbh I don't think it's that costly to look into th
+ if (!name.startsWith(dartLibraryEnvironmentPrefix)) return null;
+
+ String libraryName = name.substring(dartLibraryEnvironmentPrefix.length);
+ if (sdkLibraries.containsKey(libraryName)) {
+ // 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 null;
+ }
Uri lookupLibraryUri(String libraryName) {
assert(invariant(NO_LOCATION_SPANNABLE,
« 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