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

Unified Diff: runtime/bin/main.cc

Issue 24975002: - Implement a first cut for const String.env in the VM to allow (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698