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

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: Addressed comments 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 a6103c06268b031dd02784fe29c35e9e6e18e528..ba42a57339a1643ec14246dc00d04558ce2193f1 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,32 @@
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_EnvironmentCallback callback = isolate->environment_callback();
+ if (callback != NULL) {
+ Dart_Handle result = callback(Api::NewHandle(isolate, name.raw()));
+ 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_IsString(result)) {
+ const Object& value =
+ Object::Handle(isolate, Api::UnwrapHandle(result));
+ return Symbols::New(String::Cast(value));
+ } else if (!Dart_IsNull(result)) {
+ Exceptions::ThrowArgumentError(
+ String::Handle(String::New("Illegal environment 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