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

Side by Side 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 more tests. 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 unified diff | Download patch
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | tests/language/library_env_test.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library leg_apiimpl; 5 library leg_apiimpl;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:package_config/packages.dart'; 10 import 'package:package_config/packages.dart';
(...skipping 21 matching lines...) Expand all
32 import 'diagnostics/spannable.dart' show 32 import 'diagnostics/spannable.dart' show
33 NO_LOCATION_SPANNABLE, 33 NO_LOCATION_SPANNABLE,
34 Spannable; 34 Spannable;
35 import 'elements/elements.dart' as elements; 35 import 'elements/elements.dart' as elements;
36 import 'io/source_file.dart'; 36 import 'io/source_file.dart';
37 import 'script.dart'; 37 import 'script.dart';
38 38
39 const bool forceIncrementalSupport = 39 const bool forceIncrementalSupport =
40 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT'); 40 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT');
41 41
42 /// For every 'dart:' library, a corresponding environment variable is set
43 /// to "true". The environment variable's name is the concatenation of
44 /// this prefix and the name (without the 'dart:'.
sigurdm 2015/10/19 07:26:26 DBC: missing ')'
45 ///
46 /// For example 'dart:html' has the environment variable 'dart.library.html' set
47 /// to "true".
48 const String dartLibraryEnvironmentPrefix = 'dart.library.';
49
42 class Compiler extends leg.Compiler { 50 class Compiler extends leg.Compiler {
43 api.CompilerInput provider; 51 api.CompilerInput provider;
44 api.CompilerDiagnostics handler; 52 api.CompilerDiagnostics handler;
45 final Uri libraryRoot; 53 final Uri libraryRoot;
46 final Uri packageConfig; 54 final Uri packageConfig;
47 final Uri packageRoot; 55 final Uri packageRoot;
48 final api.PackagesDiscoveryProvider packagesDiscoveryProvider; 56 final api.PackagesDiscoveryProvider packagesDiscoveryProvider;
49 Packages packages; 57 Packages packages;
50 List<String> options; 58 List<String> options;
51 Map<String, dynamic> environment; 59 Map<String, dynamic> environment;
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 Future<Packages> callUserPackagesDiscovery(Uri uri) { 545 Future<Packages> callUserPackagesDiscovery(Uri uri) {
538 try { 546 try {
539 return userPackagesDiscoveryTask.measure( 547 return userPackagesDiscoveryTask.measure(
540 () => packagesDiscoveryProvider(uri)); 548 () => packagesDiscoveryProvider(uri));
541 } catch (ex, s) { 549 } catch (ex, s) {
542 diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s); 550 diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s);
543 rethrow; 551 rethrow;
544 } 552 }
545 } 553 }
546 554
547 555 fromEnvironment(String name) {
548 fromEnvironment(String name) => environment[name]; 556 var result = environment[name];
557 if (result == null && !environment.containsKey(name) &&
558 name.startsWith(dartLibraryEnvironmentPrefix)) {
559 String libraryName = name.substring(dartLibraryEnvironmentPrefix.length);
560 LibraryInfo info = lookupLibraryInfo(libraryName);
561 if (info != null &&
562 allowedLibraryCategories.contains(info.category)) {
563 // Dart2js always "supports" importing 'dart:mirrors' but will abort
564 // the compilation at a later point if the backend doesn't support
565 // mirrors. In this case 'mirrors' should not be in the environment.
566 if (name == dartLibraryEnvironmentPrefix + 'mirrors') {
567 return backend.supportsReflection ? "true" : null;
568 }
569 return "true";
570 }
571 }
572 return result;
573 }
549 574
550 LibraryInfo lookupLibraryInfo(String libraryName) { 575 LibraryInfo lookupLibraryInfo(String libraryName) {
551 return library_info.LIBRARIES[libraryName]; 576 return library_info.LIBRARIES[libraryName];
552 } 577 }
553 } 578 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | tests/language/library_env_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698