Index: runtime/bin/main.cc |
=================================================================== |
--- runtime/bin/main.cc (revision 28841) |
+++ runtime/bin/main.cc (working copy) |
@@ -422,6 +422,37 @@ |
} \ |
+static Dart_Handle EnvironmentCallback(Dart_EnvironmentType type, |
+ Dart_Handle name) { |
+ uint8_t* utf8_array; |
+ intptr_t utf8_len; |
+ Dart_Handle result = Dart_Null(); |
+ Dart_Handle handle = Dart_StringToUTF8(name, &utf8_array, &utf8_len); |
+ if (Dart_IsError(handle)) { |
+ handle = Dart_ThrowException( |
+ DartUtils::NewDartArgumentError(Dart_GetError(handle))); |
+ } else { |
+ char* name_chars = reinterpret_cast<char*>(malloc(utf8_len + 1)); |
+ memmove(name_chars, utf8_array, utf8_len); |
+ name_chars[utf8_len] = '\0'; |
+ const char* value = getenv(name_chars); |
+ if (value != NULL) { |
+ if ((type == kStringEnvironment) || (type == kIntegerEnvironment)) { |
+ result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value), |
+ strlen(value)); |
+ } else if (type == kBoolEnvironment) { |
+ if (strcmp(value, "true") == 0) { |
+ result = Dart_True(); |
+ } else { |
+ result = Dart_False(); |
+ } |
+ } |
+ } |
+ } |
+ return result; |
+} |
+ |
+ |
// Returns true on success, false on failure. |
static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, |
const char* main, |
@@ -446,6 +477,9 @@ |
Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); |
CHECK_RESULT(result); |
+ result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
+ CHECK_RESULT(result); |
+ |
// Load the specified application script into the newly created isolate. |
// Prepare builtin and its dependent libraries for use to resolve URIs. |