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

Side by Side Diff: runtime/bin/main.cc

Issue 22565003: Make the values of Platform.executable and Platform.script available to all isolates (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from whesse@ Created 7 years, 4 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 | « runtime/bin/io_natives.cc ('k') | runtime/bin/platform.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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 ShellUtils::FreeUnicodeArgv(unicode_argv); 282 ShellUtils::FreeUnicodeArgv(unicode_argv);
283 return true; 283 return true;
284 } 284 }
285 285
286 286
287 // Parse out the command line arguments. Returns -1 if the arguments 287 // Parse out the command line arguments. Returns -1 if the arguments
288 // are incorrect, 0 otherwise. 288 // are incorrect, 0 otherwise.
289 static int ParseArguments(int argc, 289 static int ParseArguments(int argc,
290 char** argv, 290 char** argv,
291 CommandLineOptions* vm_options, 291 CommandLineOptions* vm_options,
292 char** executable_name,
293 char** script_name, 292 char** script_name,
294 CommandLineOptions* dart_options, 293 CommandLineOptions* dart_options,
295 bool* print_flags_seen, 294 bool* print_flags_seen,
296 bool* verbose_debug_seen) { 295 bool* verbose_debug_seen) {
297 const char* kPrefix = "--"; 296 const char* kPrefix = "--";
298 const intptr_t kPrefixLen = strlen(kPrefix); 297 const intptr_t kPrefixLen = strlen(kPrefix);
299 298
300 // Get the executable name. 299 // Store the executable name.
301 *executable_name = argv[0]; 300 Platform::SetExecutableName(argv[0]);
302 301
303 // Start the rest after the executable name. 302 // Start the rest after the executable name.
304 int i = 1; 303 int i = 1;
305 304
306 // Parse out the vm options. 305 // Parse out the vm options.
307 while (i < argc) { 306 while (i < argc) {
308 if (ProcessMainOptions(argv[i])) { 307 if (ProcessMainOptions(argv[i])) {
309 i++; 308 i++;
310 } else { 309 } else {
311 // Check if this flag is a potentially valid VM flag. 310 // Check if this flag is a potentially valid VM flag.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 while (i < argc) { 352 while (i < argc) {
354 dart_options->AddArgument(argv[i]); 353 dart_options->AddArgument(argv[i]);
355 i++; 354 i++;
356 } 355 }
357 356
358 return 0; 357 return 0;
359 } 358 }
360 359
361 360
362 static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options, 361 static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options,
363 const char* executable_name,
364 const char* script_name) { 362 const char* script_name) {
365 int options_count = options->count(); 363 int options_count = options->count();
366 Dart_Handle dart_executable = DartUtils::NewString(executable_name);
367 if (Dart_IsError(dart_executable)) {
368 return dart_executable;
369 }
370 Dart_Handle dart_script = DartUtils::NewString(script_name);
371 if (Dart_IsError(dart_script)) {
372 return dart_script;
373 }
374 Dart_Handle dart_arguments = Dart_NewList(options_count); 364 Dart_Handle dart_arguments = Dart_NewList(options_count);
375 if (Dart_IsError(dart_arguments)) { 365 if (Dart_IsError(dart_arguments)) {
376 return dart_arguments; 366 return dart_arguments;
377 } 367 }
378 for (int i = 0; i < options_count; i++) { 368 for (int i = 0; i < options_count; i++) {
379 Dart_Handle argument_value = 369 Dart_Handle argument_value =
380 DartUtils::NewString(options->GetArgument(i)); 370 DartUtils::NewString(options->GetArgument(i));
381 if (Dart_IsError(argument_value)) { 371 if (Dart_IsError(argument_value)) {
382 return argument_value; 372 return argument_value;
383 } 373 }
384 Dart_Handle result = Dart_ListSetAt(dart_arguments, i, argument_value); 374 Dart_Handle result = Dart_ListSetAt(dart_arguments, i, argument_value);
385 if (Dart_IsError(result)) { 375 if (Dart_IsError(result)) {
386 return result; 376 return result;
387 } 377 }
388 } 378 }
389 Dart_Handle io_lib_url = DartUtils::NewString("dart:io"); 379 Dart_Handle io_lib_url = DartUtils::NewString("dart:io");
390 if (Dart_IsError(io_lib_url)) { 380 if (Dart_IsError(io_lib_url)) {
391 return io_lib_url; 381 return io_lib_url;
392 } 382 }
393 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); 383 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url);
394 if (Dart_IsError(io_lib)) { 384 if (Dart_IsError(io_lib)) {
395 return io_lib; 385 return io_lib;
396 } 386 }
397 Dart_Handle platform_class_name = DartUtils::NewString("Platform");
398 if (Dart_IsError(platform_class_name)) {
399 return platform_class_name;
400 }
401 Dart_Handle platform_type =
402 Dart_GetType(io_lib, platform_class_name, 0, NULL);
403 if (Dart_IsError(platform_type)) {
404 return platform_type;
405 }
406 Dart_Handle executable_name_name = DartUtils::NewString("_nativeExecutable");
407 if (Dart_IsError(executable_name_name)) {
408 return executable_name_name;
409 }
410 Dart_Handle set_executable_name =
411 Dart_SetField(platform_type,
412 executable_name_name,
413 dart_executable);
414 if (Dart_IsError(set_executable_name)) {
415 return set_executable_name;
416 }
417 Dart_Handle script_name_name = DartUtils::NewString("_nativeScript");
418 if (Dart_IsError(script_name_name)) {
419 return script_name_name;
420 }
421 Dart_Handle set_script_name =
422 Dart_SetField(platform_type, script_name_name, dart_script);
423 if (Dart_IsError(set_script_name)) {
424 return set_script_name;
425 }
426 Dart_Handle runtime_options_class_name = DartUtils::NewString("_OptionsImpl"); 387 Dart_Handle runtime_options_class_name = DartUtils::NewString("_OptionsImpl");
427 if (Dart_IsError(runtime_options_class_name)) { 388 if (Dart_IsError(runtime_options_class_name)) {
428 return runtime_options_class_name; 389 return runtime_options_class_name;
429 } 390 }
430 Dart_Handle runtime_options_type = Dart_GetType( 391 Dart_Handle runtime_options_type = Dart_GetType(
431 io_lib, runtime_options_class_name, 0, NULL); 392 io_lib, runtime_options_class_name, 0, NULL);
432 if (Dart_IsError(runtime_options_type)) { 393 if (Dart_IsError(runtime_options_type)) {
433 return runtime_options_type; 394 return runtime_options_type;
434 } 395 }
435 Dart_Handle native_name = DartUtils::NewString("_nativeArguments"); 396 Dart_Handle native_name = DartUtils::NewString("_nativeArguments");
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 char errbuf[256]; 454 char errbuf[256];
494 snprintf(errbuf, sizeof(errbuf), 455 snprintf(errbuf, sizeof(errbuf),
495 "Expected a library when loading script: %s", 456 "Expected a library when loading script: %s",
496 script_uri); 457 script_uri);
497 *error = strdup(errbuf); 458 *error = strdup(errbuf);
498 Dart_ExitScope(); 459 Dart_ExitScope();
499 Dart_ShutdownIsolate(); 460 Dart_ShutdownIsolate();
500 return NULL; 461 return NULL;
501 } 462 }
502 463
464 Dart_Handle io_lib_url = DartUtils::NewString("dart:io");
465 CHECK_RESULT(io_lib_url);
466 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url);
467 CHECK_RESULT(io_lib);
468 Dart_Handle platform_class_name = DartUtils::NewString("Platform");
469 CHECK_RESULT(platform_class_name);
470 Dart_Handle platform_type =
471 Dart_GetType(io_lib, platform_class_name, 0, NULL);
472 CHECK_RESULT(platform_type);
473 Dart_Handle script_name_name = DartUtils::NewString("_nativeScript");
474 CHECK_RESULT(script_name_name);
475 Dart_Handle dart_script = DartUtils::NewString(script_uri);
476 CHECK_RESULT(dart_script);
477 Dart_Handle set_script_name =
478 Dart_SetField(platform_type, script_name_name, dart_script);
479 CHECK_RESULT(set_script_name);
480
503 VmService::SendIsolateStartupMessage(Dart_GetMainPortId()); 481 VmService::SendIsolateStartupMessage(Dart_GetMainPortId());
504 482
505 // Make the isolate runnable so that it is ready to handle messages. 483 // Make the isolate runnable so that it is ready to handle messages.
506 Dart_ExitScope(); 484 Dart_ExitScope();
507 Dart_ExitIsolate(); 485 Dart_ExitIsolate();
508 bool retval = Dart_IsolateMakeRunnable(isolate); 486 bool retval = Dart_IsolateMakeRunnable(isolate);
509 if (!retval) { 487 if (!retval) {
510 *error = strdup("Invalid isolate state - Unable to make it runnable"); 488 *error = strdup("Invalid isolate state - Unable to make it runnable");
511 Dart_EnterIsolate(isolate); 489 Dart_EnterIsolate(isolate);
512 Dart_ShutdownIsolate(); 490 Dart_ShutdownIsolate();
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 if (Dart_IsError(result)) { 667 if (Dart_IsError(result)) {
690 return result; 668 return result;
691 } 669 }
692 Log::Print("%s\n", script_source); 670 Log::Print("%s\n", script_source);
693 } 671 }
694 return Dart_True(); 672 return Dart_True();
695 } 673 }
696 674
697 675
698 int main(int argc, char** argv) { 676 int main(int argc, char** argv) {
699 char* executable_name;
700 char* script_name; 677 char* script_name;
701 CommandLineOptions vm_options(argc); 678 CommandLineOptions vm_options(argc);
702 CommandLineOptions dart_options(argc); 679 CommandLineOptions dart_options(argc);
703 bool print_flags_seen = false; 680 bool print_flags_seen = false;
704 bool verbose_debug_seen = false; 681 bool verbose_debug_seen = false;
705 682
706 // Perform platform specific initialization. 683 // Perform platform specific initialization.
707 if (!Platform::Initialize()) { 684 if (!Platform::Initialize()) {
708 Log::PrintErr("Initialization failed\n"); 685 Log::PrintErr("Initialization failed\n");
709 } 686 }
710 687
711 // On Windows, the argv strings are code page encoded and not 688 // On Windows, the argv strings are code page encoded and not
712 // utf8. We need to convert them to utf8. 689 // utf8. We need to convert them to utf8.
713 bool argv_converted = Utf8ConvertArgv(argc, argv); 690 bool argv_converted = Utf8ConvertArgv(argc, argv);
714 691
715 // Parse command line arguments. 692 // Parse command line arguments.
716 if (ParseArguments(argc, 693 if (ParseArguments(argc,
717 argv, 694 argv,
718 &vm_options, 695 &vm_options,
719 &executable_name,
720 &script_name, 696 &script_name,
721 &dart_options, 697 &dart_options,
722 &print_flags_seen, 698 &print_flags_seen,
723 &verbose_debug_seen) < 0) { 699 &verbose_debug_seen) < 0) {
724 if (has_help_option) { 700 if (has_help_option) {
725 PrintUsage(); 701 PrintUsage();
726 return 0; 702 return 0;
727 } else if (has_version_option) { 703 } else if (has_version_option) {
728 PrintVersion(); 704 PrintVersion();
729 return 0; 705 return 0;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 802
827 if (has_check_function_fingerprints) { 803 if (has_check_function_fingerprints) {
828 result = Dart_CheckFunctionFingerprints(); 804 result = Dart_CheckFunctionFingerprints();
829 if (Dart_IsError(result)) { 805 if (Dart_IsError(result)) {
830 return DartErrorExit(result); 806 return DartErrorExit(result);
831 } 807 }
832 } 808 }
833 809
834 // Create a dart options object that can be accessed from dart code. 810 // Create a dart options object that can be accessed from dart code.
835 Dart_Handle options_result = 811 Dart_Handle options_result =
836 SetupRuntimeOptions(&dart_options, executable_name, script_name); 812 SetupRuntimeOptions(&dart_options, script_name);
837 if (Dart_IsError(options_result)) { 813 if (Dart_IsError(options_result)) {
838 return DartErrorExit(options_result); 814 return DartErrorExit(options_result);
839 } 815 }
840 // Lookup the library of the root script. 816 // Lookup the library of the root script.
841 Dart_Handle library = Dart_RootLibrary(); 817 Dart_Handle library = Dart_RootLibrary();
842 if (Dart_IsNull(library)) { 818 if (Dart_IsNull(library)) {
843 return ErrorExit(kErrorExitCode, 819 return ErrorExit(kErrorExitCode,
844 "Unable to find root library for '%s'\n", 820 "Unable to find root library for '%s'\n",
845 script_name); 821 script_name);
846 } 822 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 864
889 return Process::GlobalExitCode(); 865 return Process::GlobalExitCode();
890 } 866 }
891 867
892 } // namespace bin 868 } // namespace bin
893 } // namespace dart 869 } // namespace dart
894 870
895 int main(int argc, char** argv) { 871 int main(int argc, char** argv) {
896 return dart::bin::main(argc, argv); 872 return dart::bin::main(argc, argv);
897 } 873 }
OLDNEW
« no previous file with comments | « runtime/bin/io_natives.cc ('k') | runtime/bin/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698