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 |
| 68 | 74 |
| 75 static void ProcessPackageRootOption(const char* arg) { | |
| 76 ASSERT(arg != NULL); | |
| 77 package_root = arg; | |
| 78 } | |
| 79 | |
| 80 | |
| 69 static void ProcessCompileAllOption(const char* compile_all) { | 81 static void ProcessCompileAllOption(const char* compile_all) { |
| 70 ASSERT(compile_all != NULL); | 82 ASSERT(compile_all != NULL); |
| 71 has_compile_all = true; | 83 has_compile_all = true; |
| 72 } | 84 } |
| 73 | 85 |
| 74 | 86 |
| 75 static void ProcessPprofOption(const char* filename) { | 87 static void ProcessPprofOption(const char* filename) { |
| 76 ASSERT(filename != NULL); | 88 ASSERT(filename != NULL); |
| 77 generate_pprof_symbols_filename = filename; | 89 generate_pprof_symbols_filename = filename; |
| 78 } | 90 } |
| 79 | 91 |
| 80 | 92 |
| 81 static void ProcessImportMapOption(const char* map) { | 93 static void ProcessImportMapOption(const char* map) { |
| 82 ASSERT(map != NULL); | 94 ASSERT(map != NULL); |
| 83 import_map_options->AddArgument(map); | 95 import_map_options->AddArgument(map); |
| 84 } | 96 } |
| 85 | 97 |
| 86 | 98 |
| 87 static struct { | 99 static struct { |
| 88 const char* option_name; | 100 const char* option_name; |
| 89 void (*process)(const char* option); | 101 void (*process)(const char* option); |
| 90 } main_options[] = { | 102 } main_options[] = { |
| 91 { "--break_at=", ProcessBreakpointOption }, | 103 { "--break_at=", ProcessBreakpointOption }, |
| 92 { "--compile_all", ProcessCompileAllOption }, | 104 { "--compile_all", ProcessCompileAllOption }, |
| 93 { "--generate_pprof_symbols=", ProcessPprofOption }, | 105 { "--generate_pprof_symbols=", ProcessPprofOption }, |
| 94 { "--import_map=", ProcessImportMapOption }, | 106 { "--import_map=", ProcessImportMapOption }, |
| 107 { "--package-root=", ProcessPackageRootOption }, | |
| 95 { NULL, NULL } | 108 { NULL, NULL } |
| 96 }; | 109 }; |
| 97 | 110 |
| 98 | 111 |
| 99 static bool ProcessMainOptions(const char* option) { | 112 static bool ProcessMainOptions(const char* option) { |
| 100 int i = 0; | 113 int i = 0; |
| 101 const char* name = main_options[0].option_name; | 114 const char* name = main_options[0].option_name; |
| 102 while (name != NULL) { | 115 while (name != NULL) { |
| 103 int length = strlen(name); | 116 int length = strlen(name); |
| 104 if (strncmp(option, name, length) == 0) { | 117 if (strncmp(option, name, length) == 0) { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 Dart_ListSetAt(import_map, index, Dart_NewString(name)); | 371 Dart_ListSetAt(import_map, index, Dart_NewString(name)); |
| 359 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); | 372 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); |
| 360 } else { | 373 } else { |
| 361 Dart_ListSetAt(import_map, index, Dart_NewString(name)); | 374 Dart_ListSetAt(import_map, index, Dart_NewString(name)); |
| 362 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); | 375 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); |
| 363 } | 376 } |
| 364 free(name); | 377 free(name); |
| 365 } | 378 } |
| 366 return Dart_LoadScript(script_url, source, LibraryTagHandler, import_map); | 379 return Dart_LoadScript(script_url, source, LibraryTagHandler, import_map); |
| 367 } | 380 } |
| 368 | 381 |
|
siva
2012/04/27 17:07:46
Missing blank line (2 blank lines between function
mattsh
2012/04/27 17:12:06
Done.
| |
| 369 | 382 // Returns true on success, false on failure. |
| 370 static bool CreateIsolateAndSetup(const char* name_prefix, | 383 static bool CreateIsolateAndSetup(const char* name_prefix, |
| 371 void* data, char** error) { | 384 void* data, char** error) { |
| 372 Dart_Isolate isolate = | 385 Dart_Isolate isolate = |
| 373 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); | 386 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); |
| 374 if (isolate == NULL) { | 387 if (isolate == NULL) { |
| 375 return false; | 388 return false; |
| 376 } | 389 } |
| 377 | 390 |
| 378 Dart_EnterScope(); | 391 Dart_EnterScope(); |
| 379 | 392 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 393 if (Dart_IsError(builtin_lib)) { | 406 if (Dart_IsError(builtin_lib)) { |
| 394 *error = strdup(Dart_GetError(builtin_lib)); | 407 *error = strdup(Dart_GetError(builtin_lib)); |
| 395 return false; | 408 return false; |
| 396 } | 409 } |
| 397 Dart_Handle library = Dart_LibraryImportLibrary(builtin_lib, uri_lib); | 410 Dart_Handle library = Dart_LibraryImportLibrary(builtin_lib, uri_lib); |
| 398 if (Dart_IsError(library)) { | 411 if (Dart_IsError(library)) { |
| 399 *error = strdup(Dart_GetError(library)); | 412 *error = strdup(Dart_GetError(library)); |
| 400 return false; | 413 return false; |
| 401 } | 414 } |
| 402 | 415 |
| 416 if (package_root != NULL) { | |
| 417 Dart_Handle dart_args[1]; | |
| 418 | |
| 419 Dart_Handle handle = Dart_NewString(package_root); | |
| 420 if (Dart_IsError(handle)) { | |
| 421 *error = strdup(Dart_GetError(handle)); | |
| 422 return false; | |
| 423 } | |
| 424 dart_args[0] = handle; | |
| 425 | |
| 426 Dart_Handle result = Dart_Invoke(builtin_lib, | |
| 427 Dart_NewString("_setPackageRoot"), 1, dart_args); | |
| 428 if (Dart_IsError(result)) { | |
| 429 *error = strdup(Dart_GetError(result)); | |
| 430 return false; | |
| 431 } | |
| 432 } | |
| 433 | |
| 403 // Load the specified application script into the newly created isolate. | 434 // Load the specified application script into the newly created isolate. |
| 404 library = LoadScript(builtin_lib, import_map_options); | 435 library = LoadScript(builtin_lib, import_map_options); |
| 405 if (Dart_IsError(library)) { | 436 if (Dart_IsError(library)) { |
| 406 *error = strdup(Dart_GetError(library)); | 437 *error = strdup(Dart_GetError(library)); |
| 407 Dart_ExitScope(); | 438 Dart_ExitScope(); |
| 408 Dart_ShutdownIsolate(); | 439 Dart_ShutdownIsolate(); |
| 409 return false; | 440 return false; |
| 410 } | 441 } |
| 411 if (!Dart_IsLibrary(library)) { | 442 if (!Dart_IsLibrary(library)) { |
| 412 char errbuf[256]; | 443 char errbuf[256]; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 Dart_ShutdownIsolate(); | 630 Dart_ShutdownIsolate(); |
| 600 // Terminate process exit-code handler. | 631 // Terminate process exit-code handler. |
| 601 Process::TerminateExitCodeHandler(); | 632 Process::TerminateExitCodeHandler(); |
| 602 | 633 |
| 603 free(const_cast<char*>(original_script_name)); | 634 free(const_cast<char*>(original_script_name)); |
| 604 free(const_cast<char*>(original_working_directory)); | 635 free(const_cast<char*>(original_working_directory)); |
| 605 free(const_cast<char*>(original_script_url)); | 636 free(const_cast<char*>(original_script_url)); |
| 606 | 637 |
| 607 return 0; | 638 return 0; |
| 608 } | 639 } |
| OLD | NEW |