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

Side by Side Diff: bin/main.cc

Issue 9614006: - Proper URI resolution when loading scripts from the standalone binary. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 9 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 | « bin/gen_snapshot.cc ('k') | vm/dart_api_impl.cc » ('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"
11 11
12 #include "bin/builtin.h" 12 #include "bin/builtin.h"
13 #include "bin/dartutils.h" 13 #include "bin/dartutils.h"
14 #include "bin/eventhandler.h" 14 #include "bin/eventhandler.h"
15 #include "bin/extensions.h" 15 #include "bin/extensions.h"
16 #include "bin/file.h" 16 #include "bin/file.h"
17 #include "bin/platform.h" 17 #include "bin/platform.h"
18 #include "bin/process.h" 18 #include "bin/process.h"
19 #include "platform/globals.h" 19 #include "platform/globals.h"
20 20
21 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise 21 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise
22 // it is initialized to NULL. 22 // it is initialized to NULL.
23 extern const uint8_t* snapshot_buffer; 23 extern const uint8_t* snapshot_buffer;
24 24
25 25
26 // Global state that stores a pointer to the application script file. 26 // Global state that stores a pointer to the application script file.
27 static char* canonical_script_name = NULL; 27 static const char* original_script_name = NULL;
28 static const char* original_working_directory = NULL;
29 static const char* original_script_url = NULL;
28 30
29 31
30 // Global state that stores the import URL map specified on the 32 // Global state that stores the import URL map specified on the
31 // command line. 33 // command line.
32 static CommandLineOptions* import_map_options = NULL; 34 static CommandLineOptions* import_map_options = NULL;
33 35
34 36
35 // Global state that stores a pointer to the application script snapshot.
36 static bool use_script_snapshot = false;
37 static uint8_t* script_snapshot_buffer = NULL;
38
39
40 // Global state that indicates whether pprof symbol information is 37 // Global state that indicates whether pprof symbol information is
41 // to be generated or not. 38 // to be generated or not.
42 static const char* generate_pprof_symbols_filename = NULL; 39 static const char* generate_pprof_symbols_filename = NULL;
43 40
44 41
45 // Global state that indicates whether there is a debug breakpoint. 42 // Global state that indicates whether there is a debug breakpoint.
46 // This pointer points into an argv buffer and does not need to be 43 // This pointer points into an argv buffer and does not need to be
47 // free'd. 44 // free'd.
48 static const char* breakpoint_at = NULL; 45 static const char* breakpoint_at = NULL;
49 46
(...skipping 23 matching lines...) Expand all
73 has_compile_all = true; 70 has_compile_all = true;
74 } 71 }
75 72
76 73
77 static void ProcessPprofOption(const char* filename) { 74 static void ProcessPprofOption(const char* filename) {
78 ASSERT(filename != NULL); 75 ASSERT(filename != NULL);
79 generate_pprof_symbols_filename = filename; 76 generate_pprof_symbols_filename = filename;
80 } 77 }
81 78
82 79
83 static void ProcessSnapshotOption(const char* snapshot) {
84 ASSERT(snapshot != NULL);
85 use_script_snapshot = true;
86 }
87
88
89 static void ProcessImportMapOption(const char* map) { 80 static void ProcessImportMapOption(const char* map) {
90 ASSERT(map != NULL); 81 ASSERT(map != NULL);
91 import_map_options->AddArgument(map); 82 import_map_options->AddArgument(map);
92 } 83 }
93 84
94 85
95 static struct { 86 static struct {
96 const char* option_name; 87 const char* option_name;
97 void (*process)(const char* option); 88 void (*process)(const char* option);
98 } main_options[] = { 89 } main_options[] = {
99 { "--break_at=", ProcessBreakpointOption }, 90 { "--break_at=", ProcessBreakpointOption },
100 { "--compile_all", ProcessCompileAllOption }, 91 { "--compile_all", ProcessCompileAllOption },
101 { "--generate_pprof_symbols=", ProcessPprofOption }, 92 { "--generate_pprof_symbols=", ProcessPprofOption },
102 { "--use_script_snapshot", ProcessSnapshotOption },
103 { "--import_map=", ProcessImportMapOption }, 93 { "--import_map=", ProcessImportMapOption },
104 { NULL, NULL } 94 { NULL, NULL }
105 }; 95 };
106 96
107 97
108 static bool ProcessMainOptions(const char* option) { 98 static bool ProcessMainOptions(const char* option) {
109 int i = 0; 99 int i = 0;
110 const char* name = main_options[0].option_name; 100 const char* name = main_options[0].option_name;
111 while (name != NULL) { 101 while (name != NULL) {
112 int length = strlen(name); 102 int length = strlen(name);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 while (i < argc) { 149 while (i < argc) {
160 dart_options->AddArgument(argv[i]); 150 dart_options->AddArgument(argv[i]);
161 i += 1; 151 i += 1;
162 } 152 }
163 153
164 return 0; 154 return 0;
165 } 155 }
166 156
167 157
168 static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options, 158 static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options,
169 char* script_name) { 159 const char* script_name) {
170 int options_count = options->count(); 160 int options_count = options->count();
171 Dart_Handle dart_script = Dart_NewString(script_name); 161 Dart_Handle dart_script = Dart_NewString(script_name);
172 if (Dart_IsError(dart_script)) { 162 if (Dart_IsError(dart_script)) {
173 return dart_script; 163 return dart_script;
174 } 164 }
175 Dart_Handle dart_arguments = Dart_NewList(options_count); 165 Dart_Handle dart_arguments = Dart_NewList(options_count);
176 if (Dart_IsError(dart_arguments)) { 166 if (Dart_IsError(dart_arguments)) {
177 return dart_arguments; 167 return dart_arguments;
178 } 168 }
179 for (int i = 0; i < options_count; i++) { 169 for (int i = 0; i < options_count; i++) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 return Dart_Error("accessing url characters failed"); 248 return Dart_Error("accessing url characters failed");
259 } 249 }
260 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); 250 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string);
261 bool is_dart_extension_url = DartUtils::IsDartExtensionSchemeURL(url_string); 251 bool is_dart_extension_url = DartUtils::IsDartExtensionSchemeURL(url_string);
262 if (tag == kCanonicalizeUrl) { 252 if (tag == kCanonicalizeUrl) {
263 // If this is a Dart Scheme URL then it is not modified as it will be 253 // If this is a Dart Scheme URL then it is not modified as it will be
264 // handled by the VM internally. 254 // handled by the VM internally.
265 if (is_dart_scheme_url || is_dart_extension_url) { 255 if (is_dart_scheme_url || is_dart_extension_url) {
266 return url; 256 return url;
267 } 257 }
268 // Create a canonical path based on the including library and current url. 258 // Resolve the url within the context of the library's URL.
269 return DartUtils::CanonicalizeURL(NULL, library, url_string); 259 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary);
260 Dart_Handle library_url = Dart_LibraryUrl(library);
261 if (Dart_IsError(library_url)) {
262 return Dart_Error("accessing library url failed");
263 }
264 Dart_Handle dart_args[2];
265 dart_args[0] = library_url;
266 dart_args[1] = url;
267 return Dart_InvokeStatic(builtin_lib,
268 Dart_NewString(""), Dart_NewString("resolveUri"),
269 2, dart_args);
270 } 270 }
271 if (is_dart_scheme_url) { 271 if (is_dart_scheme_url) {
272 ASSERT(tag == kImportTag); 272 ASSERT(tag == kImportTag);
273 // Handle imports of other built-in libraries present in the SDK. 273 // Handle imports of other built-in libraries present in the SDK.
274 if (DartUtils::IsDartIOLibURL(url_string)) { 274 if (DartUtils::IsDartIOLibURL(url_string)) {
275 return Builtin::LoadLibrary(Builtin::kIOLibrary); 275 return Builtin::LoadLibrary(Builtin::kIOLibrary);
276 } else if (DartUtils::IsDartJsonLibURL(url_string)) { 276 } else if (DartUtils::IsDartJsonLibURL(url_string)) {
277 return Builtin::LoadLibrary(Builtin::kJsonLibrary); 277 return Builtin::LoadLibrary(Builtin::kJsonLibrary);
278 } else if (DartUtils::IsDartUriLibURL(url_string)) { 278 } else if (DartUtils::IsDartUriLibURL(url_string)) {
279 return Builtin::LoadLibrary(Builtin::kUriLibrary); 279 return Builtin::LoadLibrary(Builtin::kUriLibrary);
280 } else if (DartUtils::IsDartUtf8LibURL(url_string)) { 280 } else if (DartUtils::IsDartUtf8LibURL(url_string)) {
281 return Builtin::LoadLibrary(Builtin::kUtf8Library); 281 return Builtin::LoadLibrary(Builtin::kUtf8Library);
282 } else { 282 } else {
283 return Dart_Error("Do not know how to load '%s'", url_string); 283 return Dart_Error("Do not know how to load '%s'", url_string);
284 } 284 }
285 } else if (is_dart_extension_url) { 285 } else if (is_dart_extension_url) {
286 if (tag != kImportTag) { 286 if (tag != kImportTag) {
287 return Dart_Error("Dart extensions must use import: '%s'", url_string); 287 return Dart_Error("Dart extensions must use import: '%s'", url_string);
288 } 288 }
289 return Extensions::LoadExtension(url_string, library); 289 return Extensions::LoadExtension(url_string, library);
290 } else {
291 // Get the file path out of the url.
292 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary);
293 Dart_Handle dart_args[1];
294 dart_args[0] = url;
295 Dart_Handle file_path = Dart_InvokeStatic(builtin_lib,
296 Dart_NewString(""),
297 Dart_NewString("filePathFromUri"),
298 1, dart_args);
299 if (Dart_IsError(file_path)) {
300 return file_path;
301 }
302 Dart_StringToCString(file_path, &url_string);
290 } 303 }
291 result = DartUtils::LoadSource(NULL, 304 result = DartUtils::LoadSource(NULL,
292 library, 305 library,
293 url, 306 url,
294 tag, 307 tag,
295 url_string, 308 url_string,
296 import_map); 309 import_map);
297 if (!Dart_IsError(result) && (tag == kImportTag)) { 310 if (!Dart_IsError(result) && (tag == kImportTag)) {
298 Builtin::ImportLibrary(result, Builtin::kBuiltinLibrary); 311 Builtin::ImportLibrary(result, Builtin::kBuiltinLibrary);
299 } 312 }
300 return result; 313 return result;
301 } 314 }
302 315
303 316
304 static Dart_Handle LoadScript(const char* script_name, 317 static Dart_Handle LoadScript(Dart_Handle builtin_lib,
305 CommandLineOptions* map) { 318 CommandLineOptions* map) {
306 Dart_Handle source = DartUtils::ReadStringFromFile(script_name); 319 Dart_Handle dart_args[2];
320 dart_args[0] = Dart_NewString(original_working_directory);
321 dart_args[1] = Dart_NewString(original_script_name);
322 Dart_Handle script_url = Dart_InvokeStatic(builtin_lib,
323 Dart_NewString(""),
324 Dart_NewString("resolveScriptUri"),
325 2, dart_args);
326 if (Dart_IsError(script_url)) {
327 fprintf(stderr, "%s", Dart_GetError(script_url));
328 return false;
329 }
330 if (original_script_url == NULL) {
331 const char* script_url_cstr;
332 Dart_StringToCString(script_url, &script_url_cstr);
333 original_script_url = strdup(script_url_cstr);
334 }
335 dart_args[0] = script_url;
336 Dart_Handle script_path = Dart_InvokeStatic(builtin_lib,
337 Dart_NewString(""),
338 Dart_NewString("filePathFromUri"),
339 1, dart_args);
340 if (Dart_IsError(script_path)) {
341 return script_path;
342 }
343 const char* script_path_cstr;
344 Dart_StringToCString(script_path, &script_path_cstr);
345 Dart_Handle source = DartUtils::ReadStringFromFile(script_path_cstr);
307 if (Dart_IsError(source)) { 346 if (Dart_IsError(source)) {
308 return source; 347 return source;
309 } 348 }
310 Dart_Handle url = Dart_NewString(script_name);
311 intptr_t length = (map == NULL) ? 0 : map->count(); 349 intptr_t length = (map == NULL) ? 0 : map->count();
312 Dart_Handle import_map = Dart_NewList(length * 2); 350 Dart_Handle import_map = Dart_NewList(length * 2);
313 for (intptr_t i = 0; i < length; i++) { 351 for (intptr_t i = 0; i < length; i++) {
314 ASSERT(map->GetArgument(i) != NULL); 352 ASSERT(map->GetArgument(i) != NULL);
315 char* name = strdup(map->GetArgument(i)); 353 char* name = strdup(map->GetArgument(i));
316 ASSERT(name != NULL); 354 ASSERT(name != NULL);
317 char* map_name = strchr(name, ','); 355 char* map_name = strchr(name, ',');
318 intptr_t index = i * 2; 356 intptr_t index = i * 2;
319 if (map_name != NULL) { 357 if (map_name != NULL) {
320 *map_name = '\0'; 358 *map_name = '\0';
321 map_name += 1; 359 map_name += 1;
322 Dart_ListSetAt(import_map, index, Dart_NewString(name)); 360 Dart_ListSetAt(import_map, index, Dart_NewString(name));
323 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); 361 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name));
324 } else { 362 } else {
325 Dart_ListSetAt(import_map, index, Dart_NewString(name)); 363 Dart_ListSetAt(import_map, index, Dart_NewString(name));
326 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); 364 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(""));
327 } 365 }
328 free(name); 366 free(name);
329 } 367 }
330 return Dart_LoadScript(url, source, LibraryTagHandler, import_map); 368 return Dart_LoadScript(script_url, source, LibraryTagHandler, import_map);
331 } 369 }
332 370
333 371
334 static bool CreateIsolateAndSetup(const char* name_prefix, 372 static bool CreateIsolateAndSetup(const char* name_prefix,
335 void* data, char** error) { 373 void* data, char** error) {
336 Dart_Isolate isolate = 374 Dart_Isolate isolate =
337 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); 375 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error);
338 if (isolate == NULL) { 376 if (isolate == NULL) {
339 return false; 377 return false;
340 } 378 }
341 379
342 Dart_Handle library;
343 Dart_EnterScope(); 380 Dart_EnterScope();
344 381
382 if (snapshot_buffer != NULL) {
383 // Setup the native resolver as the snapshot does not carry it.
384 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
385 Builtin::SetNativeResolver(Builtin::kIOLibrary);
386 }
387
388 // Prepare builtin for use to resolve URIs.
389 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary);
390 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary);
391 Builtin::ImportLibrary(builtin_lib, Builtin::kUriLibrary);
392
345 // Load the specified application script into the newly created isolate. 393 // Load the specified application script into the newly created isolate.
346 if (script_snapshot_buffer != NULL) { 394 Dart_Handle library = LoadScript(builtin_lib, import_map_options);
347 library = Dart_LoadScriptFromSnapshot(script_snapshot_buffer);
348 } else {
349 library = LoadScript(canonical_script_name, import_map_options);
350 }
351 if (Dart_IsError(library)) { 395 if (Dart_IsError(library)) {
352 *error = strdup(Dart_GetError(library)); 396 *error = strdup(Dart_GetError(library));
353 Dart_ExitScope(); 397 Dart_ExitScope();
354 Dart_ShutdownIsolate(); 398 Dart_ShutdownIsolate();
355 return false; 399 return false;
356 } 400 }
357 if (!Dart_IsLibrary(library)) { 401 if (!Dart_IsLibrary(library)) {
358 char errbuf[256]; 402 char errbuf[256];
359 snprintf(errbuf, sizeof(errbuf), 403 snprintf(errbuf, sizeof(errbuf),
360 "Expected a library when loading script: %s", 404 "Expected a library when loading script: %s",
361 canonical_script_name); 405 original_script_name);
362 *error = strdup(errbuf); 406 *error = strdup(errbuf);
363 Dart_ExitScope(); 407 Dart_ExitScope();
364 Dart_ShutdownIsolate(); 408 Dart_ShutdownIsolate();
365 return false; 409 return false;
366 } 410 }
367 if (script_snapshot_buffer == NULL) { 411 // Implicitly import builtin into app.
368 // Implicitly import builtin into app. 412 Builtin::ImportLibrary(library, Builtin::kBuiltinLibrary);
369 Builtin::ImportLibrary(library, Builtin::kBuiltinLibrary);
370 }
371 if (snapshot_buffer != NULL) {
372 // Setup the native resolver as the snapshot does not carry it.
373 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
374 Builtin::SetNativeResolver(Builtin::kIOLibrary);
375 }
376 Dart_ExitScope(); 413 Dart_ExitScope();
377 return true; 414 return true;
siva 2012/03/07 18:32:17 This was a good way of testing the script snapshot
Ivan Posva 2012/03/07 22:45:17 I am trying to avoid testing code in the main bina
378 } 415 }
379 416
380 417
381 static bool CaptureScriptSnapshot() {
382 char* error = NULL;
383 Dart_Handle result;
384
385 // First create an isolate and load up the specified script in it.
386 if (!CreateIsolateAndSetup(NULL, NULL, &error)) {
387 fprintf(stderr, "%s\n", error);
388 free(canonical_script_name);
389 free(error);
390 return false; // Indicates we encountered an error.
391 }
392
393 Dart_EnterScope();
394
395 #if 0
396 // Lookup the library of the main script.
397 Dart_Handle script_url = Dart_NewString(canonical_script_name);
398 Dart_Handle library = Dart_LookupLibrary(script_url);
399 if (Dart_IsError(library)) {
400 fprintf(stderr, "%s\n", Dart_GetError(library));
401 Dart_ExitScope();
402 Dart_ShutdownIsolate();
403 free(canonical_script_name);
404 return false; // Indicates we encountered an error.
405 }
406 #endif
407
408 // Now create the script snapshot and save into a buffer.
409 uint8_t* buffer;
410 intptr_t size;
411 result = Dart_CreateScriptSnapshot(&buffer, &size);
412 if (Dart_IsError(result)) {
413 fprintf(stderr, "%s\n", Dart_GetError(result));
414 Dart_ExitScope();
415 Dart_ShutdownIsolate();
416 return false; // Indicates we encountered an error.
417 }
418
419 // Save the script snapshot as we are about to shutdown the isolate.
420 script_snapshot_buffer = reinterpret_cast<uint8_t*>(malloc(size));
421 ASSERT(script_snapshot_buffer != NULL);
422 memmove(script_snapshot_buffer, buffer, size);
423
424 // Shutdown this isolate.
425 Dart_ExitScope();
426 Dart_ShutdownIsolate();
427 return true;
428 }
429
430
431 static void PrintUsage() { 418 static void PrintUsage() {
432 fprintf(stderr, 419 fprintf(stderr,
433 "dart [<vm-flags>] <dart-script-file> [<dart-options>]\n"); 420 "dart [<vm-flags>] <dart-script-file> [<dart-options>]\n");
434 } 421 }
435 422
436 423
437 static Dart_Handle SetBreakpoint(const char* breakpoint_at, 424 static Dart_Handle SetBreakpoint(const char* breakpoint_at,
438 Dart_Handle library) { 425 Dart_Handle library) {
439 Dart_Handle result; 426 Dart_Handle result;
440 if (strchr(breakpoint_at, ':')) { 427 if (strchr(breakpoint_at, ':')) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 496 }
510 497
511 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 498 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
512 499
513 // Initialize event handler. 500 // Initialize event handler.
514 EventHandler::Initialize(); 501 EventHandler::Initialize();
515 502
516 // Initialize the Dart VM. 503 // Initialize the Dart VM.
517 Dart_Initialize(CreateIsolateAndSetup, NULL); 504 Dart_Initialize(CreateIsolateAndSetup, NULL);
518 505
519 canonical_script_name = File::GetCanonicalPath(script_name); 506 original_script_name = strdup(script_name);
520 if (canonical_script_name == NULL) { 507 original_working_directory = File::GetWorkingDirectory();
521 fprintf(stderr, "Unable to find '%s'\n", script_name);
522 return 255; // Indicates we encountered an error.
523 }
524
525 // If application snapshot option is specified, first create the
526 // application snapshot and then load the script using the snapshot
527 // created.
528 if (use_script_snapshot) {
529 if (!CaptureScriptSnapshot()) {
530 return 255; // Error capturing script snapshot, error already reported.
531 }
532 }
533 508
534 // Call CreateIsolateAndSetup which creates an isolate and loads up 509 // Call CreateIsolateAndSetup which creates an isolate and loads up
535 // the specified application script. 510 // the specified application script.
536 char* error = NULL; 511 char* error = NULL;
537 char* isolate_name = BuildIsolateName(canonical_script_name, "main"); 512 char* isolate_name = BuildIsolateName(original_script_name, "main");
538 if (!CreateIsolateAndSetup(isolate_name, NULL, &error)) { 513 if (!CreateIsolateAndSetup(isolate_name, NULL, &error)) {
539 fprintf(stderr, "%s\n", error); 514 fprintf(stderr, "%s\n", error);
540 free(canonical_script_name); 515 free(const_cast<char*>(original_script_name));
siva 2012/03/07 18:32:17 A free of original_working_directory and original_
Ivan Posva 2012/03/07 22:45:17 Done.
541 free(error); 516 free(error);
542 free(script_snapshot_buffer);
543 delete [] isolate_name; 517 delete [] isolate_name;
544 return 255; // Indicates we encountered an error. 518 return 255; // Indicates we encountered an error.
545 } 519 }
546 free(script_snapshot_buffer); // Don't need it anymore.
547 delete [] isolate_name; 520 delete [] isolate_name;
548 521
549 Dart_Isolate isolate = Dart_CurrentIsolate(); 522 Dart_Isolate isolate = Dart_CurrentIsolate();
550 ASSERT(isolate != NULL); 523 ASSERT(isolate != NULL);
551 Dart_Handle result; 524 Dart_Handle result;
552 525
553 Dart_EnterScope(); 526 Dart_EnterScope();
554 527
555 if (has_compile_all) { 528 if (has_compile_all) {
556 result = Dart_CompileAll(); 529 result = Dart_CompileAll();
557 if (Dart_IsError(result)) { 530 if (Dart_IsError(result)) {
558 fprintf(stderr, "%s\n", Dart_GetError(result)); 531 fprintf(stderr, "%s\n", Dart_GetError(result));
559 Dart_ExitScope(); 532 Dart_ExitScope();
560 Dart_ShutdownIsolate(); 533 Dart_ShutdownIsolate();
561 free(canonical_script_name); 534 free(const_cast<char*>(original_script_name));
562 return 255; // Indicates we encountered an error. 535 return 255; // Indicates we encountered an error.
563 } 536 }
564 } 537 }
565 538
566 // Create a dart options object that can be accessed from dart code. 539 // Create a dart options object that can be accessed from dart code.
567 Dart_Handle options_result = 540 Dart_Handle options_result =
568 SetupRuntimeOptions(&dart_options, canonical_script_name); 541 SetupRuntimeOptions(&dart_options, original_script_name);
569 if (Dart_IsError(options_result)) { 542 if (Dart_IsError(options_result)) {
570 fprintf(stderr, "%s\n", Dart_GetError(options_result)); 543 fprintf(stderr, "%s\n", Dart_GetError(options_result));
571 Dart_ExitScope(); 544 Dart_ExitScope();
572 Dart_ShutdownIsolate(); 545 Dart_ShutdownIsolate();
573 free(canonical_script_name); 546 free(const_cast<char*>(original_script_name));
574 return 255; // Indicates we encountered an error. 547 return 255; // Indicates we encountered an error.
575 } 548 }
576 // Lookup the library of the main script. 549 // Lookup the library of the main script.
577 Dart_Handle script_url = Dart_NewString(canonical_script_name); 550 Dart_Handle script_url = Dart_NewString(original_script_url);
578 Dart_Handle library = Dart_LookupLibrary(script_url); 551 Dart_Handle library = Dart_LookupLibrary(script_url);
579 if (Dart_IsError(library)) { 552 if (Dart_IsError(library)) {
580 fprintf(stderr, "%s\n", Dart_GetError(library)); 553 fprintf(stderr, "%s\n", Dart_GetError(library));
581 Dart_ExitScope(); 554 Dart_ExitScope();
582 Dart_ShutdownIsolate(); 555 Dart_ShutdownIsolate();
583 free(canonical_script_name); 556 free(const_cast<char*>(original_script_name));
584 return 255; // Indicates we encountered an error. 557 return 255; // Indicates we encountered an error.
585 } 558 }
586 // Set debug breakpoint if specified on the command line. 559 // Set debug breakpoint if specified on the command line.
587 if (breakpoint_at != NULL) { 560 if (breakpoint_at != NULL) {
588 result = SetBreakpoint(breakpoint_at, library); 561 result = SetBreakpoint(breakpoint_at, library);
589 if (Dart_IsError(result)) { 562 if (Dart_IsError(result)) {
590 fprintf(stderr, "Error setting breakpoint at '%s': %s\n", 563 fprintf(stderr, "Error setting breakpoint at '%s': %s\n",
591 breakpoint_at, 564 breakpoint_at,
592 Dart_GetError(result)); 565 Dart_GetError(result));
593 Dart_ExitScope(); 566 Dart_ExitScope();
594 Dart_ShutdownIsolate(); 567 Dart_ShutdownIsolate();
595 free(canonical_script_name); 568 free(const_cast<char*>(original_script_name));
596 return 255; // Indicates we encountered an error. 569 return 255; // Indicates we encountered an error.
597 } 570 }
598 } 571 }
599 // Lookup and invoke the top level main function. 572 // Lookup and invoke the top level main function.
600 result = Dart_InvokeStatic(library, 573 result = Dart_InvokeStatic(library,
601 Dart_NewString(""), 574 Dart_NewString(""),
602 Dart_NewString("main"), 575 Dart_NewString("main"),
603 0, 576 0,
604 NULL); 577 NULL);
605 if (Dart_IsError(result)) { 578 if (Dart_IsError(result)) {
606 fprintf(stderr, "%s\n", Dart_GetError(result)); 579 fprintf(stderr, "%s\n", Dart_GetError(result));
607 Dart_ExitScope(); 580 Dart_ExitScope();
608 Dart_ShutdownIsolate(); 581 Dart_ShutdownIsolate();
609 free(canonical_script_name); 582 free(const_cast<char*>(original_script_name));
610 return 255; // Indicates we encountered an error. 583 return 255; // Indicates we encountered an error.
611 } 584 }
612 // Keep handling messages until the last active receive port is closed. 585 // Keep handling messages until the last active receive port is closed.
613 result = Dart_RunLoop(); 586 result = Dart_RunLoop();
614 if (Dart_IsError(result)) { 587 if (Dart_IsError(result)) {
615 fprintf(stderr, "%s\n", Dart_GetError(result)); 588 fprintf(stderr, "%s\n", Dart_GetError(result));
616 Dart_ExitScope(); 589 Dart_ExitScope();
617 Dart_ShutdownIsolate(); 590 Dart_ShutdownIsolate();
618 free(canonical_script_name); 591 free(const_cast<char*>(original_script_name));
619 return 255; // Indicates we encountered an error. 592 return 255; // Indicates we encountered an error.
620 } 593 }
621 free(canonical_script_name); 594 free(const_cast<char*>(original_script_name));
622 Dart_ExitScope(); 595 Dart_ExitScope();
623 // Dump symbol information for the profiler. 596 // Dump symbol information for the profiler.
624 DumpPprofSymbolInfo(); 597 DumpPprofSymbolInfo();
625 // Shutdown the isolate. 598 // Shutdown the isolate.
626 Dart_ShutdownIsolate(); 599 Dart_ShutdownIsolate();
627 // Terminate event handler. 600 // Terminate event handler.
628 EventHandler::Terminate(); 601 EventHandler::Terminate();
629 // Terminate process exit-code handler. 602 // Terminate process exit-code handler.
630 Process::TerminateExitCodeHandler(); 603 Process::TerminateExitCodeHandler();
631 604
632 return 0; 605 return 0;
633 } 606 }
OLDNEW
« no previous file with comments | « bin/gen_snapshot.cc ('k') | vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698