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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 546053002: - Refactor the way X.fromEnvironment is implemented. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 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
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 39888)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -4721,6 +4721,38 @@
// --- Environment ---
+RawString* Api::CallEnvironmentCallback(Isolate* isolate, const String& name) {
+ Scope api_scope(isolate);
+ Dart_EnvironmentCallback callback = isolate->environment_callback();
+ String& result = String::Handle(isolate);
+ if (callback != NULL) {
+ Dart_Handle response = callback(Api::NewHandle(isolate, name.raw()));
+ if (::Dart_IsString(response)) {
+ result ^= Api::UnwrapHandle(response);
+ } else if (::Dart_IsError(response)) {
+ const Object& error =
+ Object::Handle(isolate, Api::UnwrapHandle(response));
+ Exceptions::ThrowArgumentError(
+ String::Handle(String::New(Error::Cast(error).ToErrorCString())));
+ } else if (!::Dart_IsNull(response)) {
+ // At this point everything except null are invalid environment values.
+ Exceptions::ThrowArgumentError(
+ 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();
+}
+
+
DART_EXPORT Dart_Handle Dart_SetEnvironmentCallback(
Dart_EnvironmentCallback callback) {
Isolate* isolate = Isolate::Current();

Powered by Google App Engine
This is Rietveld 408576698