Skip to content

Commit

Permalink
Support 'dart.library.X' env variables in the VM.
Browse files Browse the repository at this point in the history
BUG= http://dartbug.com/24587
R=iposva@google.com, johnmccutchan@google.com

Committed: c2a06e2
Reverted: 5eb5b42

Review URL: https://codereview.chromium.org/1640853004 .
  • Loading branch information
floitschG committed Feb 29, 2016
1 parent 1176782 commit 55630a5
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 18 deletions.
2 changes: 1 addition & 1 deletion runtime/lib/bool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DEFINE_NATIVE_ENTRY(Bool_fromEnvironment, 3) {
GET_NATIVE_ARGUMENT(Bool, default_value, arguments->NativeArgAt(2));
// Call the embedder to supply us with the environment.
const String& env_value =
String::Handle(Api::CallEnvironmentCallback(thread, name));
String::Handle(Api::GetEnvironmentValue(thread, name));
if (!env_value.IsNull()) {
if (Symbols::True().Equals(env_value)) {
return Bool::True().raw();
Expand Down
2 changes: 1 addition & 1 deletion runtime/lib/integers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ DEFINE_NATIVE_ENTRY(Integer_fromEnvironment, 3) {
GET_NATIVE_ARGUMENT(Integer, default_value, arguments->NativeArgAt(2));
// Call the embedder to supply us with the environment.
const String& env_value =
String::Handle(Api::CallEnvironmentCallback(thread, name));
String::Handle(Api::GetEnvironmentValue(thread, name));
if (!env_value.IsNull()) {
const Integer& result = Integer::Handle(ParseInteger(env_value));
if (!result.IsNull()) {
Expand Down
2 changes: 1 addition & 1 deletion runtime/lib/string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ DEFINE_NATIVE_ENTRY(String_fromEnvironment, 3) {
GET_NATIVE_ARGUMENT(String, default_value, arguments->NativeArgAt(2));
// Call the embedder to supply us with the environment.
const String& env_value =
String::Handle(Api::CallEnvironmentCallback(thread, name));
String::Handle(Api::GetEnvironmentValue(thread, name));
if (!env_value.IsNull()) {
return Symbols::New(env_value);
}
Expand Down
47 changes: 38 additions & 9 deletions runtime/vm/dart_api_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}

Expand Down
5 changes: 3 additions & 2 deletions runtime/vm/dart_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,13 @@ class Api : AllStatic {
static void SetWeakHandleReturnValue(NativeArguments* args,
Dart_WeakPersistentHandle retval);

static RawString* CallEnvironmentCallback(Thread* thread,
const String& name);
static RawString* GetEnvironmentValue(Thread* thread, const String& name);

private:
static Dart_Handle InitNewHandle(Thread* thread, RawObject* raw);

static RawString* CallEnvironmentCallback(Thread* thread, const String& name);

// Thread local key used by the API. Currently holds the current
// ApiNativeScope if any.
static ThreadLocalKey api_native_key_;
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5796,7 +5796,7 @@ void Parser::ParseLibraryImportExport(const Object& tl_owner,
: String::Cast(valueNode->AsLiteralNode()->literal());
// Call the embedder to supply us with the environment.
const String& env_value =
String::Handle(Api::CallEnvironmentCallback(T, key));
String::Handle(Api::GetEnvironmentValue(T, key));
if (!env_value.IsNull() && env_value.Equals(value)) {
condition_triggered = true;
url_literal = conditional_url_literal;
Expand Down
2 changes: 2 additions & 0 deletions runtime/vm/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ class ObjectPointerVisitor;
V(ConstructorClosurePrefix, "new#") \
V(_runExtension, "_runExtension") \
V(_runPendingImmediateCallback, "_runPendingImmediateCallback") \
V(DartLibrary, "dart.library.") \
V(DartLibraryMirrors, "dart.library.mirrors") \


// Contains a list of frequently used strings in a canonicalized form. This
Expand Down
14 changes: 12 additions & 2 deletions tests/language/language.status
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ async_star_regression_2238_test: CompileTimeError, RuntimeError # drt only runti
async_star_cancel_while_paused_test: RuntimeError
async_star_await_pauses_test: Skip # Times out. Issue 23996

library_env_test: RuntimeError

accessor_conflict_export2_test: RuntimeError # Issue 25625
accessor_conflict_import2_test: RuntimeError # Issue 25625
accessor_conflict_import_prefixed2_test: RuntimeError # Issue 25625
Expand Down Expand Up @@ -197,3 +195,15 @@ regress_22443_test: Skip

[ $runtime == vm && $mode == product ]
vm/type_vm_test: Fail,OK # Expects exact type name.

[ $compiler == none && $browser ]
# The following tests are supposed to fail.
library_env_test/has_io_support: RuntimeError, OK
library_env_test/has_no_html_support: RuntimeError, OK
library_env_test/has_no_mirror_support: RuntimeError, OK

[ $compiler == none && $browser != true ]
# The following tests are supposed to fail.
library_env_test/has_html_support: RuntimeError, OK
library_env_test/has_no_io_support: RuntimeError, OK
library_env_test/has_no_mirror_support: RuntimeError, OK
2 changes: 1 addition & 1 deletion tests/language/language_dart2js.status
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mixin_supertype_subclass4_test: CompileTimeError # Issue 23773
mixin_of_mixin_test: CompileTimeError # Issue 23773

# The following tests are supposed to fail.
# When run for testing dart2js supports all dart:X libraries (because it
# In testing-mode, dart2js supports all dart:X libraries (because it
# uses '--categories=all').
library_env_test/has_no_html_support: RuntimeError, OK
library_env_test/has_no_io_support: RuntimeError, OK
Expand Down

0 comments on commit 55630a5

Please sign in to comment.