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()) { |