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

Unified Diff: runtime/lib/bool.cc

Issue 50983002: Implement fromEnvironment on bool, int and String (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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/lib/bool.cc
diff --git a/runtime/lib/bool.cc b/runtime/lib/bool.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2d7119c79a8c86211aa95ebfd6ee7b3188411929
--- /dev/null
+++ b/runtime/lib/bool.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "vm/bootstrap_natives.h"
+
+#include "include/dart_api.h"
+#include "vm/bigint_operations.h"
+#include "vm/dart_entry.h"
+#include "vm/dart_api_impl.h"
+#include "vm/exceptions.h"
+#include "vm/isolate.h"
+#include "vm/native_entry.h"
+#include "vm/object.h"
+#include "vm/object_store.h"
+#include "vm/symbols.h"
+
+namespace dart {
+
+DEFINE_NATIVE_ENTRY(Bool_fromEnvironment, 3) {
+ 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.
+ Dart_ConfigCallback callback = isolate->config_callback();
+ if (callback != NULL) {
+ Dart_Handle result = callback(kBoolConfig,
+ Api::NewHandle(isolate, name.raw()));
+ if (Dart_IsString(result)) {
+ const char *chars;
+ Dart_StringToCString(result, &chars);
+ return (strcmp("false", chars) != 0)
Ivan Posva 2013/10/29 21:42:59 Only "true" is the true value in Dart, you should
Søren Gjesse 2013/10/29 22:44:39 One question here. I was a bit puzzeled about the
Ivan Posva 2013/10/30 05:08:21 I guess it would make the native API simpler and l
Søren Gjesse 2013/10/30 11:44:02 Changed so that only "true" is true. Changed the
+ ? Bool::True().raw() : Bool::False().raw();
+ }
+ }
+ if (default_value.IsNull()) {
+ Exceptions::ThrowArgumentError(
+ String::Handle(String::New("Environment value does not have a value")));
+ }
+ return default_value.raw();
+}
+
+} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698