OLD | NEW |
---|---|
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 Loading... | |
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:'. | |
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 Loading... | |
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 } | |
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
| |
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 } |
OLD | NEW |