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

Side by Side 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, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_debugger_api.h" 10 #include "include/dart_debugger_api.h"
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 #define CHECK_RESULT(result) \ 415 #define CHECK_RESULT(result) \
416 if (Dart_IsError(result)) { \ 416 if (Dart_IsError(result)) { \
417 *error = strdup(Dart_GetError(result)); \ 417 *error = strdup(Dart_GetError(result)); \
418 *is_compile_error = Dart_IsCompilationError(result); \ 418 *is_compile_error = Dart_IsCompilationError(result); \
419 Dart_ExitScope(); \ 419 Dart_ExitScope(); \
420 Dart_ShutdownIsolate(); \ 420 Dart_ShutdownIsolate(); \
421 return NULL; \ 421 return NULL; \
422 } \ 422 } \
423 423
424 424
425 static Dart_Handle EnvironmentCallback(Dart_EnvironmentType type,
426 Dart_Handle name) {
427 uint8_t* utf8_array;
428 intptr_t utf8_len;
429 Dart_Handle result = Dart_Null();
430 Dart_Handle handle = Dart_StringToUTF8(name, &utf8_array, &utf8_len);
431 if (Dart_IsError(handle)) {
432 handle = Dart_ThrowException(
433 DartUtils::NewDartArgumentError(Dart_GetError(handle)));
434 } else {
435 char* name_chars = reinterpret_cast<char*>(malloc(utf8_len + 1));
436 memmove(name_chars, utf8_array, utf8_len);
437 name_chars[utf8_len] = '\0';
438 const char* value = getenv(name_chars);
439 if (value != NULL) {
440 if ((type == kStringEnvironment) || (type == kIntegerEnvironment)) {
441 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value),
442 strlen(value));
443 } else if (type == kBoolEnvironment) {
444 if (strcmp(value, "true") == 0) {
445 result = Dart_True();
446 } else {
447 result = Dart_False();
448 }
449 }
450 }
451 }
452 return result;
453 }
454
455
425 // Returns true on success, false on failure. 456 // Returns true on success, false on failure.
426 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, 457 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
427 const char* main, 458 const char* main,
428 void* data, 459 void* data,
429 char** error, 460 char** error,
430 bool* is_compile_error) { 461 bool* is_compile_error) {
431 Dart_Isolate isolate = 462 Dart_Isolate isolate =
432 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); 463 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error);
433 if (isolate == NULL) { 464 if (isolate == NULL) {
434 return NULL; 465 return NULL;
435 } 466 }
436 467
437 Dart_EnterScope(); 468 Dart_EnterScope();
438 469
439 if (snapshot_buffer != NULL) { 470 if (snapshot_buffer != NULL) {
440 // Setup the native resolver as the snapshot does not carry it. 471 // Setup the native resolver as the snapshot does not carry it.
441 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 472 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
442 Builtin::SetNativeResolver(Builtin::kIOLibrary); 473 Builtin::SetNativeResolver(Builtin::kIOLibrary);
443 } 474 }
444 475
445 // Set up the library tag handler for this isolate. 476 // Set up the library tag handler for this isolate.
446 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); 477 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler);
447 CHECK_RESULT(result); 478 CHECK_RESULT(result);
448 479
480 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
481 CHECK_RESULT(result);
482
449 // Load the specified application script into the newly created isolate. 483 // Load the specified application script into the newly created isolate.
450 484
451 // Prepare builtin and its dependent libraries for use to resolve URIs. 485 // Prepare builtin and its dependent libraries for use to resolve URIs.
452 // The builtin library is part of the core snapshot and would already be 486 // The builtin library is part of the core snapshot and would already be
453 // available here in the case of script snapshot loading. 487 // available here in the case of script snapshot loading.
454 Dart_Handle builtin_lib = 488 Dart_Handle builtin_lib =
455 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 489 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
456 CHECK_RESULT(builtin_lib); 490 CHECK_RESULT(builtin_lib);
457 491
458 // Prepare for script loading by setting up the 'print' and 'timer' 492 // Prepare for script loading by setting up the 'print' and 'timer'
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 935
902 return Process::GlobalExitCode(); 936 return Process::GlobalExitCode();
903 } 937 }
904 938
905 } // namespace bin 939 } // namespace bin
906 } // namespace dart 940 } // namespace dart
907 941
908 int main(int argc, char** argv) { 942 int main(int argc, char** argv) {
909 return dart::bin::main(argc, argv); 943 return dart::bin::main(argc, argv);
910 } 944 }
OLDNEW
« 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