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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 1640853004: Support 'dart.library.X' env variables in the VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Rebase and fix typo. Created 4 years, 10 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 | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index a085ee4af86300bd20eb9ced1bcc709fdb853c2e..4aa7c2f4d758a4c733fd245ec2a6dee72cd389aa 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -4964,6 +4964,44 @@ DART_EXPORT void Dart_SetWeakHandleReturnValue(Dart_NativeArguments args,
// --- Environment ---
+RawString* Api::GetEnvironmentValue(Thread* thread, const String& name) {
+ String& result = String::Handle(CallEnvironmentCallback(thread, name));
+ if (result.IsNull()) {
+ // Every 'dart:X' library introduces an environment variable
+ // 'dart.library.X' that is set to 'true'.
+ // We just need to make sure to hide private libraries (starting with
+ // "_", and the mirrors library, if it is not supported.
+
+ if (!FLAG_enable_mirrors && name.Equals(Symbols::DartLibraryMirrors())) {
+ return Symbols::False().raw();
+ }
+
+ const String& prefix = Symbols::DartLibrary();
+ if (name.StartsWith(prefix)) {
+ const String& library_name =
+ String::Handle(String::SubString(name, prefix.Length()));
+
+ // Private libraries (starting with "_") are not exposed to the user.
+ if (!library_name.IsNull() && library_name.CharAt(0) != '_') {
+ const String& dart_library_name =
+ String::Handle(String::Concat(Symbols::DartScheme(), library_name));
+ const Library& library =
+ Library::Handle(Library::LookupLibrary(dart_library_name));
+ if (!library.IsNull()) {
+ return Symbols::True().raw();
+ }
+ }
+ }
+ // Check for default VM provided values. If it was not overriden on the
+ // command line.
+ if (Symbols::DartIsVM().Equals(name)) {
+ return Symbols::True().raw();
+ }
+ }
+ return result.raw();
+}
+
+
RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) {
Isolate* isolate = thread->isolate();
Dart_EnvironmentCallback callback = isolate->environment_callback();
@@ -4985,15 +5023,6 @@ RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) {
String::Handle(String::New("Illegal environment value")));
}
}
- if (result.IsNull()) {
- // TODO(iposva): Determine whether builtin values can be overriden by the
- // embedder.
- // Check for default VM provided values. If it was not overriden on the
- // command line.
- if (Symbols::DartIsVM().Equals(name)) {
- return Symbols::True().raw();
- }
- }
return result.raw();
}
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698