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

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, 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | runtime/lib/integers_patch.dart » ('J')
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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 #define CHECK_RESULT(result) \ 407 #define CHECK_RESULT(result) \
408 if (Dart_IsError(result)) { \ 408 if (Dart_IsError(result)) { \
409 *error = strdup(Dart_GetError(result)); \ 409 *error = strdup(Dart_GetError(result)); \
410 *is_compile_error = Dart_IsCompilationError(result); \ 410 *is_compile_error = Dart_IsCompilationError(result); \
411 Dart_ExitScope(); \ 411 Dart_ExitScope(); \
412 Dart_ShutdownIsolate(); \ 412 Dart_ShutdownIsolate(); \
413 return NULL; \ 413 return NULL; \
414 } \ 414 } \
415 415
416 416
417 static Dart_Handle ConfigCallback(Dart_ConfigType type, Dart_Handle name) {
418 uint8_t* utf8_array;
419 intptr_t utf8_len;
420 Dart_Handle result = Dart_Null();
421 Dart_Handle handle = Dart_StringToUTF8(name, &utf8_array, &utf8_len);
422 if (Dart_IsError(handle)) {
423 handle = Dart_ThrowException(
424 DartUtils::NewDartArgumentError(Dart_GetError(handle)));
425 } else {
426 char* name_chars = reinterpret_cast<char*>(malloc(utf8_len + 1));
427 memmove(name_chars, utf8_array, utf8_len);
428 name_chars[utf8_len] = '\0';
429 const char* value = getenv(name_chars);
430 if (value != NULL) {
431 if (type == kStringConfig) {
432 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value),
433 strlen(value));
434 } else if (type == kIntegerConfig) {
435 UNIMPLEMENTED();
436 } else if (type == kBoolConfig) {
437 UNIMPLEMENTED();
bakster 2013/09/27 07:44:39 Why not implement int and bool when you are at it?
Ivan Posva 2013/09/27 21:05:06 Because I wanted to get feedback on the initial ap
438 }
439 }
440 }
441 return result;
442 }
443
444
417 // Returns true on success, false on failure. 445 // Returns true on success, false on failure.
418 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, 446 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
419 const char* main, 447 const char* main,
420 void* data, 448 void* data,
421 char** error, 449 char** error,
422 bool* is_compile_error) { 450 bool* is_compile_error) {
423 Dart_Isolate isolate = 451 Dart_Isolate isolate =
424 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); 452 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error);
425 if (isolate == NULL) { 453 if (isolate == NULL) {
426 return NULL; 454 return NULL;
427 } 455 }
428 456
429 Dart_EnterScope(); 457 Dart_EnterScope();
430 458
431 if (snapshot_buffer != NULL) { 459 if (snapshot_buffer != NULL) {
432 // Setup the native resolver as the snapshot does not carry it. 460 // Setup the native resolver as the snapshot does not carry it.
433 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 461 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
434 Builtin::SetNativeResolver(Builtin::kIOLibrary); 462 Builtin::SetNativeResolver(Builtin::kIOLibrary);
435 } 463 }
436 464
437 // Set up the library tag handler for this isolate. 465 // Set up the library tag handler for this isolate.
438 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); 466 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler);
439 CHECK_RESULT(result); 467 CHECK_RESULT(result);
440 468
469 result = Dart_SetConfigCallback(ConfigCallback);
470 CHECK_RESULT(result);
471
441 // Load the specified application script into the newly created isolate. 472 // Load the specified application script into the newly created isolate.
442 473
443 // Prepare builtin and its dependent libraries for use to resolve URIs. 474 // Prepare builtin and its dependent libraries for use to resolve URIs.
444 // The builtin library is part of the core snapshot and would already be 475 // The builtin library is part of the core snapshot and would already be
445 // available here in the case of script snapshot loading. 476 // available here in the case of script snapshot loading.
446 Dart_Handle builtin_lib = 477 Dart_Handle builtin_lib =
447 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 478 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
448 CHECK_RESULT(builtin_lib); 479 CHECK_RESULT(builtin_lib);
449 480
450 // Prepare for script loading by setting up the 'print' and 'timer' 481 // Prepare for script loading by setting up the 'print' and 'timer'
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 913
883 return Process::GlobalExitCode(); 914 return Process::GlobalExitCode();
884 } 915 }
885 916
886 } // namespace bin 917 } // namespace bin
887 } // namespace dart 918 } // namespace dart
888 919
889 int main(int argc, char** argv) { 920 int main(int argc, char** argv) {
890 return dart::bin::main(argc, argv); 921 return dart::bin::main(argc, argv);
891 } 922 }
OLDNEW
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | runtime/lib/integers_patch.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698