OLD | NEW |
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 Loading... |
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) || (type == kIntegerConfig)) { |
| 432 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value), |
| 433 strlen(value)); |
| 434 } else if (type == kBoolConfig) { |
| 435 UNIMPLEMENTED(); |
| 436 } |
| 437 } |
| 438 } |
| 439 return result; |
| 440 } |
| 441 |
| 442 |
417 // Returns true on success, false on failure. | 443 // Returns true on success, false on failure. |
418 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, | 444 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, |
419 const char* main, | 445 const char* main, |
420 void* data, | 446 void* data, |
421 char** error, | 447 char** error, |
422 bool* is_compile_error) { | 448 bool* is_compile_error) { |
423 Dart_Isolate isolate = | 449 Dart_Isolate isolate = |
424 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); | 450 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); |
425 if (isolate == NULL) { | 451 if (isolate == NULL) { |
426 return NULL; | 452 return NULL; |
427 } | 453 } |
428 | 454 |
429 Dart_EnterScope(); | 455 Dart_EnterScope(); |
430 | 456 |
431 if (snapshot_buffer != NULL) { | 457 if (snapshot_buffer != NULL) { |
432 // Setup the native resolver as the snapshot does not carry it. | 458 // Setup the native resolver as the snapshot does not carry it. |
433 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 459 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
434 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 460 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
435 } | 461 } |
436 | 462 |
437 // Set up the library tag handler for this isolate. | 463 // Set up the library tag handler for this isolate. |
438 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); | 464 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); |
439 CHECK_RESULT(result); | 465 CHECK_RESULT(result); |
440 | 466 |
| 467 result = Dart_SetConfigCallback(ConfigCallback); |
| 468 CHECK_RESULT(result); |
| 469 |
441 // Load the specified application script into the newly created isolate. | 470 // Load the specified application script into the newly created isolate. |
442 | 471 |
443 // Prepare builtin and its dependent libraries for use to resolve URIs. | 472 // 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 | 473 // The builtin library is part of the core snapshot and would already be |
445 // available here in the case of script snapshot loading. | 474 // available here in the case of script snapshot loading. |
446 Dart_Handle builtin_lib = | 475 Dart_Handle builtin_lib = |
447 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 476 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
448 CHECK_RESULT(builtin_lib); | 477 CHECK_RESULT(builtin_lib); |
449 | 478 |
450 // Prepare for script loading by setting up the 'print' and 'timer' | 479 // Prepare for script loading by setting up the 'print' and 'timer' |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 | 913 |
885 return Process::GlobalExitCode(); | 914 return Process::GlobalExitCode(); |
886 } | 915 } |
887 | 916 |
888 } // namespace bin | 917 } // namespace bin |
889 } // namespace dart | 918 } // namespace dart |
890 | 919 |
891 int main(int argc, char** argv) { | 920 int main(int argc, char** argv) { |
892 return dart::bin::main(argc, argv); | 921 return dart::bin::main(argc, argv); |
893 } | 922 } |
OLD | NEW |