Index: runtime/lib/string.cc |
diff --git a/runtime/lib/string.cc b/runtime/lib/string.cc |
index 6b451350ac50871083eeaaf3117ae2314b374557..91e844883e21679cc4a95ebc7cf78e5d28cf12b2 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(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()))); |
+ } |
+ if (Dart_IsString(result)) { |
+ const Object& value = |
+ Object::Handle(isolate, Api::UnwrapHandle(result)); |
+ return Symbols::New(String::Cast(value)); |
+ } |
Ivan Posva
2013/10/30 20:44:43
if (Dart_IsString(result)) {
...
} else if (!Dar
Søren Gjesse
2013/10/30 21:24:34
Done. Included the IsNull case, and changed for al
|
+ 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()) { |