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

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

Issue 13452007: Add new Dart API call Dart_MakeIsolateRunnable(). This would allow an (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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/include/dart_api.h » ('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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 415
416 return Dart_SetField(runtime_options_class, native_name, dart_arguments); 416 return Dart_SetField(runtime_options_class, native_name, dart_arguments);
417 } 417 }
418 418
419 419
420 #define CHECK_RESULT(result) \ 420 #define CHECK_RESULT(result) \
421 if (Dart_IsError(result)) { \ 421 if (Dart_IsError(result)) { \
422 *error = strdup(Dart_GetError(result)); \ 422 *error = strdup(Dart_GetError(result)); \
423 Dart_ExitScope(); \ 423 Dart_ExitScope(); \
424 Dart_ShutdownIsolate(); \ 424 Dart_ShutdownIsolate(); \
425 return false; \ 425 return NULL; \
426 } \ 426 } \
427 427
428 428
429 // Returns true on success, false on failure. 429 // Returns true on success, false on failure.
430 static bool CreateIsolateAndSetupHelper(const char* script_uri, 430 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
431 const char* main, 431 const char* main,
432 void* data, 432 void* data,
433 char** error) { 433 char** error) {
434 Dart_Isolate isolate = 434 Dart_Isolate isolate =
435 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); 435 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error);
436 if (isolate == NULL) { 436 if (isolate == NULL) {
437 return false; 437 return NULL;
438 } 438 }
439 439
440 Dart_EnterScope(); 440 Dart_EnterScope();
441 441
442 if (snapshot_buffer != NULL) { 442 if (snapshot_buffer != NULL) {
443 // Setup the native resolver as the snapshot does not carry it. 443 // Setup the native resolver as the snapshot does not carry it.
444 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 444 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
445 Builtin::SetNativeResolver(Builtin::kIOLibrary); 445 Builtin::SetNativeResolver(Builtin::kIOLibrary);
446 } 446 }
447 447
(...skipping 21 matching lines...) Expand all
469 Dart_Handle library = DartUtils::LoadScript(script_uri, builtin_lib); 469 Dart_Handle library = DartUtils::LoadScript(script_uri, builtin_lib);
470 CHECK_RESULT(library); 470 CHECK_RESULT(library);
471 if (!Dart_IsLibrary(library)) { 471 if (!Dart_IsLibrary(library)) {
472 char errbuf[256]; 472 char errbuf[256];
473 snprintf(errbuf, sizeof(errbuf), 473 snprintf(errbuf, sizeof(errbuf),
474 "Expected a library when loading script: %s", 474 "Expected a library when loading script: %s",
475 script_uri); 475 script_uri);
476 *error = strdup(errbuf); 476 *error = strdup(errbuf);
477 Dart_ExitScope(); 477 Dart_ExitScope();
478 Dart_ShutdownIsolate(); 478 Dart_ShutdownIsolate();
479 return false; 479 return NULL;
480 } 480 }
481
482 // Make the isolate runnable so that it is ready to handle messages.
481 Dart_ExitScope(); 483 Dart_ExitScope();
484 Dart_ExitIsolate();
485 bool retval = Dart_IsolateMakeRunnable(isolate);
486 if (!retval) {
487 *error = strdup("Invalid isolate state - Unable to make it runnable");
488 Dart_EnterIsolate(isolate);
489 Dart_ShutdownIsolate();
490 return NULL;
491 }
492
482 VmStats::AddIsolate(reinterpret_cast<IsolateData*>(data), isolate); 493 VmStats::AddIsolate(reinterpret_cast<IsolateData*>(data), isolate);
483 return true; 494 return isolate;
484 } 495 }
485 496
486 497
487 static bool CreateIsolateAndSetup(const char* script_uri, 498 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
488 const char* main, 499 const char* main,
489 void* data, char** error) { 500 void* data, char** error) {
490 return CreateIsolateAndSetupHelper(script_uri, 501 return CreateIsolateAndSetupHelper(script_uri,
491 main, 502 main,
492 new IsolateData(), 503 new IsolateData(),
493 error); 504 error);
494 } 505 }
495 506
496 507
497 static void PrintVersion() { 508 static void PrintVersion() {
498 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); 509 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString());
499 } 510 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 // Start the debugger wire protocol handler if necessary. 738 // Start the debugger wire protocol handler if necessary.
728 if (start_debugger) { 739 if (start_debugger) {
729 ASSERT(debug_port != 0); 740 ASSERT(debug_port != 0);
730 DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); 741 DebuggerConnectionHandler::StartHandler(debug_ip, debug_port);
731 } 742 }
732 743
733 // Call CreateIsolateAndSetup which creates an isolate and loads up 744 // Call CreateIsolateAndSetup which creates an isolate and loads up
734 // the specified application script. 745 // the specified application script.
735 char* error = NULL; 746 char* error = NULL;
736 char* isolate_name = BuildIsolateName(script_name, "main"); 747 char* isolate_name = BuildIsolateName(script_name, "main");
737 if (!CreateIsolateAndSetupHelper(script_name, 748 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name,
738 "main", 749 "main",
739 new IsolateData(), 750 new IsolateData(),
740 &error)) { 751 &error);
752 if (isolate == NULL) {
741 Log::PrintErr("%s\n", error); 753 Log::PrintErr("%s\n", error);
742 free(error); 754 free(error);
743 delete [] isolate_name; 755 delete [] isolate_name;
744 return kErrorExitCode; // Indicates we encountered an error. 756 return kErrorExitCode; // Indicates we encountered an error.
745 } 757 }
746 delete [] isolate_name; 758 delete [] isolate_name;
747 759
748 Dart_Isolate isolate = Dart_CurrentIsolate(); 760 Dart_EnterIsolate(isolate);
761 ASSERT(isolate == Dart_CurrentIsolate());
749 ASSERT(isolate != NULL); 762 ASSERT(isolate != NULL);
750 Dart_Handle result; 763 Dart_Handle result;
751 764
752 Dart_EnterScope(); 765 Dart_EnterScope();
753 766
754 if (vmstats_port >= 0) { 767 if (vmstats_port >= 0) {
755 VmStats::Start(vmstats_port, vmstats_root); 768 VmStats::Start(vmstats_port, vmstats_root);
756 } 769 }
757 770
758 if (generate_script_snapshot) { 771 if (generate_script_snapshot) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 Dart_ShutdownIsolate(); 844 Dart_ShutdownIsolate();
832 // Terminate process exit-code handler. 845 // Terminate process exit-code handler.
833 Process::TerminateExitCodeHandler(); 846 Process::TerminateExitCodeHandler();
834 // Free copied argument strings if converted. 847 // Free copied argument strings if converted.
835 if (argv_converted) { 848 if (argv_converted) {
836 for (int i = 0; i < argc; i++) free(argv[i]); 849 for (int i = 0; i < argc; i++) free(argv[i]);
837 } 850 }
838 851
839 return Process::GlobalExitCode(); 852 return Process::GlobalExitCode();
840 } 853 }
OLDNEW
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | runtime/include/dart_api.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698