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

Unified Diff: runtime/lib/bool.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
« no previous file with comments | « no previous file | runtime/lib/integers.cc » ('j') | runtime/vm/dart_api_impl.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/bool.cc
===================================================================
--- runtime/lib/bool.cc (revision 39888)
+++ runtime/lib/bool.cc (working copy)
@@ -21,25 +21,15 @@
GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1));
GET_NATIVE_ARGUMENT(Bool, default_value, arguments->NativeArgAt(2));
// Call the embedder to supply us with the environment.
- Api::Scope api_scope(isolate);
- Dart_EnvironmentCallback callback = isolate->environment_callback();
- if (callback != NULL) {
- Dart_Handle result = callback(Api::NewHandle(isolate, name.raw()));
- if (Dart_IsString(result)) {
- const char *chars;
- Dart_StringToCString(result, &chars);
- if (strcmp("true", chars) == 0) return Bool::True().raw();
- if (strcmp("false", chars) == 0) return Bool::False().raw();
- } else if (Dart_IsError(result)) {
- const Object& error =
- Object::Handle(isolate, Api::UnwrapHandle(result));
- Exceptions::ThrowArgumentError(
- String::Handle(
- String::New(Error::Cast(error).ToErrorCString())));
- } else if (!Dart_IsNull(result)) {
- Exceptions::ThrowArgumentError(
- String::Handle(String::New("Illegal environment value")));
+ const String& env_value =
+ String::Handle(Api::CallEnvironmentCallback(isolate, name));
+ if (!env_value.IsNull()) {
+ if (Symbols::True().Equals(env_value)) {
+ return Bool::True().raw();
}
+ if (Symbols::False().Equals(env_value)) {
+ return Bool::False().raw();
+ }
}
return default_value.raw();
}
« no previous file with comments | « no previous file | runtime/lib/integers.cc » ('j') | runtime/vm/dart_api_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698