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

Unified Diff: runtime/lib/string.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/string.cc
diff --git a/runtime/lib/string.cc b/runtime/lib/string.cc
index bab0abadef2e12c39c5119ee892892cf80aa09f6..06e050b077287735f32eef30928888117cea86b1 100644
--- a/runtime/lib/string.cc
+++ b/runtime/lib/string.cc
@@ -4,7 +4,10 @@
#include "vm/bootstrap_natives.h"
+#include "include/dart_api.h"
#include "vm/exceptions.h"
+#include "vm/dart_api_impl.h"
+#include "vm/isolate.h"
#include "vm/native_entry.h"
#include "vm/object.h"
#include "vm/symbols.h"
@@ -12,6 +15,34 @@
namespace dart {
+DEFINE_NATIVE_ENTRY(String_fromEnvironment, 3) {
+ GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1));
+ GET_NATIVE_ARGUMENT(String, 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(kStringConfig,
Ivan Posva 2013/10/29 21:42:59 Here and the other callbacks: You are ignoring all
Søren Gjesse 2013/10/30 11:44:02 Done. If the embedder returns an error object I n
+ Api::NewHandle(isolate, name.raw()));
+ if (Dart_IsString(result)) {
+ int len;
+ Dart_StringLength(result, &len);
+ if (len > 0) {
Ivan Posva 2013/10/29 21:42:59 The empty string should be a valid value from the
Søren Gjesse 2013/10/30 11:44:02 Absolutely. Removed the check.
+ const Object& value =
+ Object::Handle(isolate, Api::UnwrapHandle(result));
+ if (value.IsString()) {
+ return Symbols::New(String::Cast(value));
+ }
+ }
+ }
+ }
+ if (default_value.IsNull()) {
+ Exceptions::ThrowArgumentError(
+ String::Handle(String::New("Environment value does not have a value")));
+ }
+ return default_value.raw();
+}
+
+
DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) {
GET_NON_NULL_NATIVE_ARGUMENT(Instance, list, arguments->NativeArgAt(0));
if (!list.IsGrowableObjectArray() && !list.IsArray()) {

Powered by Google App Engine
This is Rietveld 408576698