Chromium Code Reviews| 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 28 matching lines...) Expand all Loading... | |
| 39 // to be generated or not. | 39 // to be generated or not. |
| 40 static const char* generate_pprof_symbols_filename = NULL; | 40 static const char* generate_pprof_symbols_filename = NULL; |
| 41 | 41 |
| 42 | 42 |
| 43 // Global state that indicates whether there is a debug breakpoint. | 43 // Global state that indicates whether there is a debug breakpoint. |
| 44 // This pointer points into an argv buffer and does not need to be | 44 // This pointer points into an argv buffer and does not need to be |
| 45 // free'd. | 45 // free'd. |
| 46 static const char* breakpoint_at = NULL; | 46 static const char* breakpoint_at = NULL; |
| 47 | 47 |
| 48 | 48 |
| 49 // Value of the --package_root flag. | |
| 50 // (This pointer points into an argv buffer and does not need to be | |
| 51 // free'd.) | |
| 52 static const char* package_root = NULL; | |
| 53 | |
| 54 | |
| 49 // Global flag that is used to indicate that we want to compile all the | 55 // Global flag that is used to indicate that we want to compile all the |
| 50 // dart functions and not run anything. | 56 // dart functions and not run anything. |
| 51 static bool has_compile_all = false; | 57 static bool has_compile_all = false; |
| 52 | 58 |
| 53 | 59 |
| 54 static bool IsValidFlag(const char* name, | 60 static bool IsValidFlag(const char* name, |
| 55 const char* prefix, | 61 const char* prefix, |
| 56 intptr_t prefix_length) { | 62 intptr_t prefix_length) { |
| 57 intptr_t name_length = strlen(name); | 63 intptr_t name_length = strlen(name); |
| 58 return ((name_length > prefix_length) && | 64 return ((name_length > prefix_length) && |
| 59 (strncmp(name, prefix, prefix_length) == 0)); | 65 (strncmp(name, prefix, prefix_length) == 0)); |
| 60 } | 66 } |
| 61 | 67 |
| 62 | 68 |
| 63 static void ProcessBreakpointOption(const char* funcname) { | 69 static void ProcessBreakpointOption(const char* funcname) { |
| 64 ASSERT(funcname != NULL); | 70 ASSERT(funcname != NULL); |
| 65 breakpoint_at = funcname; | 71 breakpoint_at = funcname; |
| 66 } | 72 } |
| 67 | 73 |
| 74 static void ProcessPackageRootOption(const char* arg) { | |
| 75 ASSERT(arg != NULL); | |
| 76 package_root = arg; | |
| 77 } | |
| 68 | 78 |
|
Ivan Posva
2012/04/25 16:25:19
Two lines, as in the rest of the file, please.
mattsh
2012/04/25 17:12:10
Done.
| |
| 69 static void ProcessCompileAllOption(const char* compile_all) { | 79 static void ProcessCompileAllOption(const char* compile_all) { |
| 70 ASSERT(compile_all != NULL); | 80 ASSERT(compile_all != NULL); |
| 71 has_compile_all = true; | 81 has_compile_all = true; |
| 72 } | 82 } |
| 73 | 83 |
| 74 | 84 |
| 75 static void ProcessPprofOption(const char* filename) { | 85 static void ProcessPprofOption(const char* filename) { |
| 76 ASSERT(filename != NULL); | 86 ASSERT(filename != NULL); |
| 77 generate_pprof_symbols_filename = filename; | 87 generate_pprof_symbols_filename = filename; |
| 78 } | 88 } |
| 79 | 89 |
| 80 | 90 |
| 81 static void ProcessImportMapOption(const char* map) { | 91 static void ProcessImportMapOption(const char* map) { |
| 82 ASSERT(map != NULL); | 92 ASSERT(map != NULL); |
| 83 import_map_options->AddArgument(map); | 93 import_map_options->AddArgument(map); |
| 84 } | 94 } |
| 85 | 95 |
|
Ivan Posva
2012/04/25 16:25:19
Why this removed line?
mattsh
2012/04/25 17:12:10
Done.
| |
| 86 | |
| 87 static struct { | 96 static struct { |
| 88 const char* option_name; | 97 const char* option_name; |
| 89 void (*process)(const char* option); | 98 void (*process)(const char* option); |
| 90 } main_options[] = { | 99 } main_options[] = { |
| 91 { "--break_at=", ProcessBreakpointOption }, | 100 { "--break_at=", ProcessBreakpointOption }, |
| 92 { "--compile_all", ProcessCompileAllOption }, | 101 { "--compile_all", ProcessCompileAllOption }, |
| 93 { "--generate_pprof_symbols=", ProcessPprofOption }, | 102 { "--generate_pprof_symbols=", ProcessPprofOption }, |
| 94 { "--import_map=", ProcessImportMapOption }, | 103 { "--import_map=", ProcessImportMapOption }, |
| 104 { "--package_root=", ProcessPackageRootOption }, | |
| 95 { NULL, NULL } | 105 { NULL, NULL } |
| 96 }; | 106 }; |
| 97 | 107 |
| 98 | 108 |
| 99 static bool ProcessMainOptions(const char* option) { | 109 static bool ProcessMainOptions(const char* option) { |
| 100 int i = 0; | 110 int i = 0; |
| 101 const char* name = main_options[0].option_name; | 111 const char* name = main_options[0].option_name; |
| 102 while (name != NULL) { | 112 while (name != NULL) { |
| 103 int length = strlen(name); | 113 int length = strlen(name); |
| 104 if (strncmp(option, name, length) == 0) { | 114 if (strncmp(option, name, length) == 0) { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); | 369 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); |
| 360 } else { | 370 } else { |
| 361 Dart_ListSetAt(import_map, index, Dart_NewString(name)); | 371 Dart_ListSetAt(import_map, index, Dart_NewString(name)); |
| 362 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); | 372 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); |
| 363 } | 373 } |
| 364 free(name); | 374 free(name); |
| 365 } | 375 } |
| 366 return Dart_LoadScript(script_url, source, LibraryTagHandler, import_map); | 376 return Dart_LoadScript(script_url, source, LibraryTagHandler, import_map); |
| 367 } | 377 } |
| 368 | 378 |
| 369 | 379 // returns true on success, false on failure |
|
Ivan Posva
2012/04/25 16:25:19
Comments end with . and start with a capital. Make
mattsh
2012/04/25 17:12:10
Done.
| |
| 370 static bool CreateIsolateAndSetup(const char* name_prefix, | 380 static bool CreateIsolateAndSetup(const char* name_prefix, |
| 371 void* data, char** error) { | 381 void* data, char** error) { |
| 372 Dart_Isolate isolate = | 382 Dart_Isolate isolate = |
| 373 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); | 383 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); |
| 374 if (isolate == NULL) { | 384 if (isolate == NULL) { |
| 375 return false; | 385 return false; |
| 376 } | 386 } |
| 377 | 387 |
| 378 Dart_EnterScope(); | 388 Dart_EnterScope(); |
| 379 | 389 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 393 if (Dart_IsError(builtin_lib)) { | 403 if (Dart_IsError(builtin_lib)) { |
| 394 *error = strdup(Dart_GetError(builtin_lib)); | 404 *error = strdup(Dart_GetError(builtin_lib)); |
| 395 return false; | 405 return false; |
| 396 } | 406 } |
| 397 Dart_Handle library = Dart_LibraryImportLibrary(builtin_lib, uri_lib); | 407 Dart_Handle library = Dart_LibraryImportLibrary(builtin_lib, uri_lib); |
| 398 if (Dart_IsError(library)) { | 408 if (Dart_IsError(library)) { |
| 399 *error = strdup(Dart_GetError(library)); | 409 *error = strdup(Dart_GetError(library)); |
| 400 return false; | 410 return false; |
| 401 } | 411 } |
| 402 | 412 |
| 413 if (package_root != NULL) { | |
| 414 Dart_Handle dart_args[1]; | |
| 415 | |
| 416 Dart_Handle handle = Dart_NewString(package_root); | |
| 417 if (Dart_IsError(handle)) { | |
| 418 return false; | |
| 419 } | |
| 420 dart_args[0] = handle; | |
| 421 | |
| 422 Dart_Handle result = Dart_Invoke(builtin_lib, | |
| 423 Dart_NewString("_setPackageRoot"), 1, dart_args); | |
| 424 if (Dart_IsError(result)) { | |
| 425 return false; | |
| 426 } | |
| 427 } | |
| 428 | |
| 403 // Load the specified application script into the newly created isolate. | 429 // Load the specified application script into the newly created isolate. |
| 404 library = LoadScript(builtin_lib, import_map_options); | 430 library = LoadScript(builtin_lib, import_map_options); |
| 405 if (Dart_IsError(library)) { | 431 if (Dart_IsError(library)) { |
| 406 *error = strdup(Dart_GetError(library)); | 432 *error = strdup(Dart_GetError(library)); |
| 407 Dart_ExitScope(); | 433 Dart_ExitScope(); |
| 408 Dart_ShutdownIsolate(); | 434 Dart_ShutdownIsolate(); |
| 409 return false; | 435 return false; |
| 410 } | 436 } |
| 411 if (!Dart_IsLibrary(library)) { | 437 if (!Dart_IsLibrary(library)) { |
| 412 char errbuf[256]; | 438 char errbuf[256]; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 Dart_ShutdownIsolate(); | 625 Dart_ShutdownIsolate(); |
| 600 // Terminate process exit-code handler. | 626 // Terminate process exit-code handler. |
| 601 Process::TerminateExitCodeHandler(); | 627 Process::TerminateExitCodeHandler(); |
| 602 | 628 |
| 603 free(const_cast<char*>(original_script_name)); | 629 free(const_cast<char*>(original_script_name)); |
| 604 free(const_cast<char*>(original_working_directory)); | 630 free(const_cast<char*>(original_working_directory)); |
| 605 free(const_cast<char*>(original_script_url)); | 631 free(const_cast<char*>(original_script_url)); |
| 606 | 632 |
| 607 return 0; | 633 return 0; |
| 608 } | 634 } |
| OLD | NEW |