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