Chromium Code Reviews| Index: bin/main.cc |
| =================================================================== |
| --- bin/main.cc (revision 1771) |
| +++ bin/main.cc (working copy) |
| @@ -18,6 +18,10 @@ |
| extern const uint8_t* snapshot_buffer; |
| +// Global state that stores a pointer to the application script file. |
| +static char* canonical_script_name = NULL; |
| + |
| + |
| // Global state that indicates whether pprof symbol information is |
| // to be generated or not. |
| static const char* generate_pprof_symbols_filename = NULL; |
| @@ -186,7 +190,7 @@ |
| } |
| result = DartUtils::LoadSource(NULL, library, url, tag, url_string); |
| if (!Dart_IsError(result) && (tag == kImportTag)) { |
| - Builtin_ImportLibrary(result); |
| + Builtin::ImportLibrary(result); |
| } |
| return result; |
| } |
| @@ -203,30 +207,41 @@ |
| } |
| -static void* MainIsolateInitCallback(void* data) { |
| - const char* script_name = reinterpret_cast<const char*>(data); |
| +static bool CreateIsolateAndSetup(Dart_IsolateError error) { |
| + Dart_Isolate isolate = Dart_CreateIsolate(snapshot_buffer); |
| + if (isolate == NULL) { |
| + snprintf(const_cast<char*>(error.buffer), error.length, |
| + "Creation/Bootstrap of Isolate failed"); |
|
turnidge
2011/11/23 18:05:12
If Dart_CreateIsolate took a Dart_IsolateError par
siva
2011/11/23 22:37:27
Done.
|
| + return false; |
| + } |
| + |
| Dart_Handle library; |
| Dart_EnterScope(); |
| - // Load the specified script. |
| - library = LoadScript(script_name); |
| + // Load the specified application script into the newly created isolate. |
| + library = LoadScript(canonical_script_name); |
| if (Dart_IsError(library)) { |
| - const char* err_msg = Dart_GetError(library); |
| - fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg); |
| + snprintf(const_cast<char*>(error.buffer), error.length, |
| + "%s", Dart_GetError(library)); |
|
turnidge
2011/11/23 18:05:12
Should we use OS::SNPrint instead of snprintf? Sa
siva
2011/11/23 22:37:27
OS class is not avaialble here as it is the embedd
turnidge
2011/11/28 18:39:58
Ok.
On 2011/11/23 22:37:27, asiva wrote:
|
| Dart_ExitScope(); |
| - exit(255); |
| + Dart_ShutdownIsolate(); |
| + return false; |
| } |
| if (!Dart_IsLibrary(library)) { |
| - fprintf(stderr, |
| - "Expected a library when loading script: %s", |
| - script_name); |
| + snprintf(const_cast<char*>(error.buffer), error.length, |
| + "Expected a library when loading script: %s", |
| + canonical_script_name); |
| Dart_ExitScope(); |
| - exit(255); |
| + Dart_ShutdownIsolate(); |
| + return false; |
| } |
| - Builtin_ImportLibrary(library); // Import builtin library. |
| - |
| + Builtin::ImportLibrary(library); // Implicitly import builtin into app. |
| + if (snapshot_buffer != NULL) { |
| + // Setup the native resolver as the snapshot does not carry it. |
| + Builtin::SetNativeResolver(); |
| + } |
|
turnidge
2011/11/23 18:05:12
Do we want to provide embedders with access to our
siva
2011/11/23 22:37:27
The Builtin stuff is in our dart embedder, this co
turnidge
2011/11/28 18:39:58
Ok.
On 2011/11/23 22:37:27, asiva wrote:
|
| Dart_ExitScope(); |
| - return data; |
| + return true; |
| } |
| @@ -265,31 +280,36 @@ |
| // dart API is fixed to take a const char** in Dart_Initialize). |
| Dart_Initialize(vm_options.count(), |
| vm_options.arguments(), |
| - MainIsolateInitCallback); |
| + CreateIsolateAndSetup); |
| - // Create an isolate. As a side effect, MainIsolateInitCallback |
| - // gets called, which loads the scripts and libraries. |
| - char* canonical_script_name = File::GetCanonicalPath(script_name); |
| + canonical_script_name = File::GetCanonicalPath(script_name); |
| if (canonical_script_name == NULL) { |
| fprintf(stderr, "Unable to find '%s'\n", script_name); |
| return 255; // Indicates we encountered an error. |
| } |
| - Dart_Isolate isolate = Dart_CreateIsolate(snapshot_buffer, |
| - canonical_script_name); |
| - if (isolate == NULL) { |
| + |
| + // Call CreateIsolateAndSetup which creates an isolate and loads up |
| + // the specified application script. |
| + Dart_IsolateError error; |
| + static const int kErrorMsgLength = 256; |
| + error.buffer = reinterpret_cast<char*>(malloc(kErrorMsgLength)); |
| + error.length = kErrorMsgLength; |
| + if (!CreateIsolateAndSetup(error)) { |
| + fprintf(stderr, "%s\n", error.buffer); |
| free(canonical_script_name); |
| - return 255; |
| + free(error.buffer); |
| + return 255; // Indicates we encountered an error. |
| } |
| + free(error.buffer); |
| + Dart_Isolate isolate = Dart_CurrentIsolate(); |
| + ASSERT(isolate != NULL); |
| + Dart_Handle result; |
| + |
| Dart_EnterScope(); |
| - if (snapshot_buffer != NULL) { |
| - // Setup the native resolver as the snapshot does not carry it. |
| - Builtin_SetNativeResolver(); |
| - } |
| - |
| if (HasCompileAll(vm_options)) { |
| - Dart_Handle result = Dart_CompileAll(); |
| + result = Dart_CompileAll(); |
| if (Dart_IsError(result)) { |
| fprintf(stderr, "%s\n", Dart_GetError(result)); |
| Dart_ExitScope(); |
| @@ -319,11 +339,11 @@ |
| free(canonical_script_name); |
| return 255; // Indicates we encountered an error. |
| } |
| - Dart_Handle result = Dart_InvokeStatic(library, |
| - Dart_NewString(""), |
| - Dart_NewString("main"), |
| - 0, |
| - NULL); |
| + result = Dart_InvokeStatic(library, |
| + Dart_NewString(""), |
| + Dart_NewString("main"), |
| + 0, |
| + NULL); |
| if (Dart_IsError(result)) { |
| fprintf(stderr, "%s\n", Dart_GetError(result)); |
| Dart_ExitScope(); |