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

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

Issue 10386107: Implement spawnUri from dart:isolate. This function allows us to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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
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/dbg_connection.h" 14 #include "bin/dbg_connection.h"
15 #include "bin/directory.h" 15 #include "bin/directory.h"
16 #include "bin/eventhandler.h" 16 #include "bin/eventhandler.h"
17 #include "bin/extensions.h" 17 #include "bin/extensions.h"
18 #include "bin/file.h" 18 #include "bin/file.h"
19 #include "bin/platform.h" 19 #include "bin/platform.h"
20 #include "bin/process.h" 20 #include "bin/process.h"
21 #include "platform/globals.h" 21 #include "platform/globals.h"
22 22
23 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise 23 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise
24 // it is initialized to NULL. 24 // it is initialized to NULL.
25 extern const uint8_t* snapshot_buffer; 25 extern const uint8_t* snapshot_buffer;
26 26
27 27
28 // Global state that stores a pointer to the application script file. 28 // Global state that stores the original working directory..
29 static const char* original_script_name = NULL;
30 static const char* original_working_directory = NULL; 29 static const char* original_working_directory = NULL;
31 static const char* original_script_url = NULL;
32 30
33 31
34 // Global state that stores the import URL map specified on the 32 // Global state that stores the import URL map specified on the
35 // command line. 33 // command line.
36 static CommandLineOptions* import_map_options = NULL; 34 static CommandLineOptions* import_map_options = NULL;
37 35
38 36
39 // Global state that indicates whether pprof symbol information is 37 // Global state that indicates whether pprof symbol information is
40 // to be generated or not. 38 // to be generated or not.
41 static const char* generate_pprof_symbols_filename = NULL; 39 static const char* generate_pprof_symbols_filename = NULL;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 if (buffer_size > 0) { 288 if (buffer_size > 0) {
291 ASSERT(buffer != NULL); 289 ASSERT(buffer != NULL);
292 pprof_file->WriteFully(buffer, buffer_size); 290 pprof_file->WriteFully(buffer, buffer_size);
293 } 291 }
294 delete pprof_file; // Closes the file. 292 delete pprof_file; // Closes the file.
295 Dart_ExitScope(); 293 Dart_ExitScope();
296 } 294 }
297 } 295 }
298 296
299 297
298
299 static Dart_Handle ResolveScriptUri(Dart_Handle script_uri,
300 Dart_Handle builtin_lib) {
301 Dart_Handle dart_args[3];
302 dart_args[0] = Dart_NewString(original_working_directory);
303 dart_args[1] = script_uri;
304 #if !defined(TARGET_OS_WINDOWS)
305 dart_args[2] = Dart_False();
306 #else // !defined(TARGET_OS_WINDOWS)
307 dart_args[2] = Dart_True();
308 #endif // !defined(TARGET_OS_WINDOWS)
309 return Dart_Invoke(
310 builtin_lib, Dart_NewString("_resolveScriptUri"), 3, dart_args);
311 }
312
313
314 static Dart_Handle FilePathFromUri(Dart_Handle script_uri,
315 Dart_Handle builtin_lib) {
316 Dart_Handle dart_args[2];
317 dart_args[0] = script_uri;
318 #if !defined(TARGET_OS_WINDOWS)
319 dart_args[1] = Dart_False();
320 #else // !defined(TARGET_OS_WINDOWS)
321 dart_args[1] = Dart_True();
322 #endif // !defined(TARGET_OS_WINDOWS)
323 Dart_Handle script_path = Dart_Invoke(
324 builtin_lib, Dart_NewString("_filePathFromUri"), 2, dart_args);
325 return script_path;
326 }
327
328
300 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, 329 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
301 Dart_Handle library, 330 Dart_Handle library,
302 Dart_Handle url, 331 Dart_Handle url) {
303 Dart_Handle import_map) {
304 if (!Dart_IsLibrary(library)) { 332 if (!Dart_IsLibrary(library)) {
305 return Dart_Error("not a library"); 333 return Dart_Error("not a library");
306 } 334 }
307 if (!Dart_IsString8(url)) { 335 if (!Dart_IsString8(url)) {
308 return Dart_Error("url is not a string"); 336 return Dart_Error("url is not a string");
309 } 337 }
310 const char* url_string = NULL; 338 const char* url_string = NULL;
311 Dart_Handle result = Dart_StringToCString(url, &url_string); 339 Dart_Handle result = Dart_StringToCString(url, &url_string);
312 if (Dart_IsError(result)) { 340 if (Dart_IsError(result)) {
313 return result; 341 return result;
(...skipping 28 matching lines...) Expand all
342 } else if (DartUtils::IsDartUriLibURL(url_string)) { 370 } else if (DartUtils::IsDartUriLibURL(url_string)) {
343 return Builtin::LoadLibrary(Builtin::kUriLibrary); 371 return Builtin::LoadLibrary(Builtin::kUriLibrary);
344 } else if (DartUtils::IsDartUtfLibURL(url_string)) { 372 } else if (DartUtils::IsDartUtfLibURL(url_string)) {
345 return Builtin::LoadLibrary(Builtin::kUtfLibrary); 373 return Builtin::LoadLibrary(Builtin::kUtfLibrary);
346 } else { 374 } else {
347 return Dart_Error("Do not know how to load '%s'", url_string); 375 return Dart_Error("Do not know how to load '%s'", url_string);
348 } 376 }
349 } else { 377 } else {
350 // Get the file path out of the url. 378 // Get the file path out of the url.
351 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); 379 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary);
352 Dart_Handle dart_args[1]; 380 Dart_Handle file_path = FilePathFromUri(url, builtin_lib);
353 dart_args[0] = url;
354 Dart_Handle file_path = Dart_Invoke(
355 builtin_lib, Dart_NewString("_filePathFromUri"), 1, dart_args);
356 if (Dart_IsError(file_path)) { 381 if (Dart_IsError(file_path)) {
357 return file_path; 382 return file_path;
358 } 383 }
359 Dart_StringToCString(file_path, &url_string); 384 Dart_StringToCString(file_path, &url_string);
360 } 385 }
361 if (is_dart_extension_url) { 386 if (is_dart_extension_url) {
362 if (tag != kImportTag) { 387 if (tag != kImportTag) {
363 return Dart_Error("Dart extensions must use import: '%s'", url_string); 388 return Dart_Error("Dart extensions must use import: '%s'", url_string);
364 } 389 }
365 return Extensions::LoadExtension(url_string, library); 390 return Extensions::LoadExtension(url_string, library);
366 } 391 }
367 result = DartUtils::LoadSource(NULL, 392 result = DartUtils::LoadSource(NULL,
368 library, 393 library,
369 url, 394 url,
370 tag, 395 tag,
371 url_string, 396 url_string);
372 import_map);
373 if (!Dart_IsError(result) && (tag == kImportTag)) { 397 if (!Dart_IsError(result) && (tag == kImportTag)) {
374 Builtin::ImportLibrary(result, Builtin::kBuiltinLibrary); 398 Builtin::ImportLibrary(result, Builtin::kBuiltinLibrary);
375 } 399 }
376 return result; 400 return result;
377 } 401 }
378 402
379 403
380 static Dart_Handle LoadScript(Dart_Handle builtin_lib, 404 static Dart_Handle ReadSource(Dart_Handle script_uri,
381 CommandLineOptions* map) { 405 Dart_Handle builtin_lib) {
382 Dart_Handle dart_args[3]; 406 Dart_Handle script_path = FilePathFromUri(script_uri, builtin_lib);
383 dart_args[0] = Dart_NewString(original_working_directory);
384 dart_args[1] = Dart_NewString(original_script_name);
385 #if !defined(TARGET_OS_WINDOWS)
386 dart_args[2] = Dart_False();
387 #else // !defined(TARGET_OS_WINDOWS)
388 dart_args[2] = Dart_True();
389 #endif // !defined(TARGET_OS_WINDOWS)
390 Dart_Handle script_url = Dart_Invoke(
391 builtin_lib, Dart_NewString("_resolveScriptUri"), 3, dart_args);
392 if (Dart_IsError(script_url)) {
393 fprintf(stderr, "%s", Dart_GetError(script_url));
394 return script_url;
395 }
396 if (original_script_url == NULL) {
397 const char* script_url_cstr;
398 Dart_StringToCString(script_url, &script_url_cstr);
399 original_script_url = strdup(script_url_cstr);
400 }
401 dart_args[0] = script_url;
402 Dart_Handle script_path = Dart_Invoke(
403 builtin_lib, Dart_NewString("_filePathFromUri"), 1, dart_args);
404 if (Dart_IsError(script_path)) { 407 if (Dart_IsError(script_path)) {
405 return script_path; 408 return script_path;
406 } 409 }
407 const char* script_path_cstr; 410 const char* script_path_cstr;
408 Dart_StringToCString(script_path, &script_path_cstr); 411 Dart_StringToCString(script_path, &script_path_cstr);
409 Dart_Handle source = DartUtils::ReadStringFromFile(script_path_cstr); 412 Dart_Handle source = DartUtils::ReadStringFromFile(script_path_cstr);
413 return source;
414 }
415
416
417 static Dart_Handle LoadScript(const char* script_uri,
418 bool resolve_script,
419 Dart_Handle builtin_lib) {
420 Dart_Handle resolved_script_uri;
421 if (resolve_script) {
422 resolved_script_uri = ResolveScriptUri(Dart_NewString(script_uri),
423 builtin_lib);
424 if (Dart_IsError(resolved_script_uri)) {
425 return resolved_script_uri;
426 }
427 } else {
428 resolved_script_uri = Dart_NewString(script_uri);
429 }
430 Dart_Handle source = ReadSource(resolved_script_uri, builtin_lib);
410 if (Dart_IsError(source)) { 431 if (Dart_IsError(source)) {
411 return source; 432 return source;
412 } 433 }
434 return Dart_LoadScript(resolved_script_uri, source);
435 }
436
437
438 static Dart_Handle CreateImportMap(CommandLineOptions* map) {
413 intptr_t length = (map == NULL) ? 0 : map->count(); 439 intptr_t length = (map == NULL) ? 0 : map->count();
414 Dart_Handle import_map = Dart_NewList(length * 2); 440 Dart_Handle import_map = Dart_NewList(length * 2);
415 for (intptr_t i = 0; i < length; i++) { 441 for (intptr_t i = 0; i < length; i++) {
416 ASSERT(map->GetArgument(i) != NULL); 442 ASSERT(map->GetArgument(i) != NULL);
417 char* name = strdup(map->GetArgument(i)); 443 char* name = strdup(map->GetArgument(i));
418 ASSERT(name != NULL); 444 ASSERT(name != NULL);
419 char* map_name = strchr(name, ','); 445 char* map_name = strchr(name, ',');
420 intptr_t index = i * 2; 446 intptr_t index = i * 2;
421 if (map_name != NULL) { 447 if (map_name != NULL) {
422 *map_name = '\0'; 448 *map_name = '\0';
423 map_name += 1; 449 map_name += 1;
424 Dart_ListSetAt(import_map, index, Dart_NewString(name)); 450 Dart_ListSetAt(import_map, index, Dart_NewString(name));
425 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); 451 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name));
426 } else { 452 } else {
427 Dart_ListSetAt(import_map, index, Dart_NewString(name)); 453 Dart_ListSetAt(import_map, index, Dart_NewString(name));
428 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); 454 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(""));
429 } 455 }
430 free(name); 456 free(name);
431 } 457 }
432 return Dart_LoadScript(script_url, source, import_map); 458 return import_map;
433 } 459 }
434 460
435 461
436 // Returns true on success, false on failure. 462 // Returns true on success, false on failure.
437 static bool CreateIsolateAndSetup(const char* name_prefix, 463 static bool CreateIsolateAndSetupHelper(const char* script_uri,
438 void* data, char** error) { 464 const char* main,
465 bool resolve_script,
466 void* data,
467 char** error) {
439 Dart_Isolate isolate = 468 Dart_Isolate isolate =
440 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); 469 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error);
441 if (isolate == NULL) { 470 if (isolate == NULL) {
442 return false; 471 return false;
443 } 472 }
444 473
445 Dart_EnterScope(); 474 Dart_EnterScope();
446 475
447 if (snapshot_buffer != NULL) { 476 if (snapshot_buffer != NULL) {
448 // Setup the native resolver as the snapshot does not carry it. 477 // Setup the native resolver as the snapshot does not carry it.
449 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 478 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
450 Builtin::SetNativeResolver(Builtin::kIOLibrary); 479 Builtin::SetNativeResolver(Builtin::kIOLibrary);
451 } 480 }
452 481
453 // Set up the library tag handler for this isolate. 482 // Set up the library tag handler for this isolate.
454 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); 483 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler);
455 if (Dart_IsError(result)) { 484 if (Dart_IsError(result)) {
456 *error = strdup(Dart_GetError(result)); 485 *error = strdup(Dart_GetError(result));
486 Dart_ExitScope();
487 Dart_ShutdownIsolate();
488 return false;
489 }
490
491 // Set up the import map for this isolate.
492 result = Dart_SetImportMap(CreateImportMap(import_map_options));
493 if (Dart_IsError(result)) {
494 *error = strdup(Dart_GetError(result));
495 Dart_ExitScope();
496 Dart_ShutdownIsolate();
457 return false; 497 return false;
458 } 498 }
459 499
460 // Prepare builtin and its dependent libraries for use to resolve URIs. 500 // Prepare builtin and its dependent libraries for use to resolve URIs.
461 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary); 501 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary);
462 if (Dart_IsError(uri_lib)) { 502 if (Dart_IsError(uri_lib)) {
463 *error = strdup(Dart_GetError(uri_lib)); 503 *error = strdup(Dart_GetError(uri_lib));
504 Dart_ExitScope();
505 Dart_ShutdownIsolate();
464 return false; 506 return false;
465 } 507 }
466 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); 508 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary);
467 if (Dart_IsError(builtin_lib)) { 509 if (Dart_IsError(builtin_lib)) {
468 *error = strdup(Dart_GetError(builtin_lib)); 510 *error = strdup(Dart_GetError(builtin_lib));
511 Dart_ExitScope();
512 Dart_ShutdownIsolate();
469 return false; 513 return false;
470 } 514 }
471 515
472 if (package_root != NULL) { 516 if (package_root != NULL) {
473 Dart_Handle dart_args[1]; 517 Dart_Handle dart_args[1];
474 518
475 Dart_Handle handle = Dart_NewString(package_root); 519 Dart_Handle handle = Dart_NewString(package_root);
476 if (Dart_IsError(handle)) { 520 if (Dart_IsError(handle)) {
477 *error = strdup(Dart_GetError(handle)); 521 *error = strdup(Dart_GetError(handle));
522 Dart_ExitScope();
523 Dart_ShutdownIsolate();
478 return false; 524 return false;
479 } 525 }
480 dart_args[0] = handle; 526 dart_args[0] = handle;
481 527
482 Dart_Handle result = Dart_Invoke(builtin_lib, 528 Dart_Handle result = Dart_Invoke(builtin_lib,
483 Dart_NewString("_setPackageRoot"), 1, dart_args); 529 Dart_NewString("_setPackageRoot"), 1, dart_args);
484 if (Dart_IsError(result)) { 530 if (Dart_IsError(result)) {
485 *error = strdup(Dart_GetError(result)); 531 *error = strdup(Dart_GetError(result));
532 Dart_ExitScope();
533 Dart_ShutdownIsolate();
486 return false; 534 return false;
487 } 535 }
488 } 536 }
489 537
490 // Load the specified application script into the newly created isolate. 538 // Load the specified application script into the newly created isolate.
491 Dart_Handle library = LoadScript(builtin_lib, import_map_options); 539 Dart_Handle library = LoadScript(script_uri, resolve_script, builtin_lib);
492 if (Dart_IsError(library)) { 540 if (Dart_IsError(library)) {
493 *error = strdup(Dart_GetError(library)); 541 *error = strdup(Dart_GetError(library));
494 Dart_ExitScope(); 542 Dart_ExitScope();
495 Dart_ShutdownIsolate(); 543 Dart_ShutdownIsolate();
496 return false; 544 return false;
497 } 545 }
498 if (!Dart_IsLibrary(library)) { 546 if (!Dart_IsLibrary(library)) {
499 char errbuf[256]; 547 char errbuf[256];
500 snprintf(errbuf, sizeof(errbuf), 548 snprintf(errbuf, sizeof(errbuf),
501 "Expected a library when loading script: %s", 549 "Expected a library when loading script: %s",
502 original_script_name); 550 script_uri);
503 *error = strdup(errbuf); 551 *error = strdup(errbuf);
504 Dart_ExitScope(); 552 Dart_ExitScope();
505 Dart_ShutdownIsolate(); 553 Dart_ShutdownIsolate();
506 return false; 554 return false;
507 } 555 }
508 // Implicitly import builtin into app. 556 // Implicitly import builtin into app.
509 Builtin::ImportLibrary(library, Builtin::kBuiltinLibrary); 557 Builtin::ImportLibrary(library, Builtin::kBuiltinLibrary);
510 Dart_ExitScope(); 558 Dart_ExitScope();
511 return true; 559 return true;
512 } 560 }
513 561
514 562
563 static bool CreateIsolateAndSetup(const char* script_uri,
564 const char* main,
565 void* data, char** error) {
566 return CreateIsolateAndSetupHelper(script_uri,
567 main,
568 false, // script_uri already canonical.
569 data,
570 error);
571 }
572
573
515 static void PrintUsage() { 574 static void PrintUsage() {
516 fprintf(stderr, 575 fprintf(stderr,
517 "dart [<vm-flags>] <dart-script-file> [<dart-options>]\n"); 576 "dart [<vm-flags>] <dart-script-file> [<dart-options>]\n");
518 } 577 }
519 578
520 579
521 static Dart_Handle SetBreakpoint(const char* breakpoint_at, 580 static Dart_Handle SetBreakpoint(const char* breakpoint_at,
522 Dart_Handle library) { 581 Dart_Handle library) {
523 Dart_Handle result; 582 Dart_Handle result;
524 if (strchr(breakpoint_at, ':')) { 583 if (strchr(breakpoint_at, ':')) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 633
575 634
576 static int ErrorExit(const char* format, ...) { 635 static int ErrorExit(const char* format, ...) {
577 va_list arguments; 636 va_list arguments;
578 va_start(arguments, format); 637 va_start(arguments, format);
579 vfprintf(stderr, format, arguments); 638 vfprintf(stderr, format, arguments);
580 va_end(arguments); 639 va_end(arguments);
581 640
582 Dart_ExitScope(); 641 Dart_ExitScope();
583 Dart_ShutdownIsolate(); 642 Dart_ShutdownIsolate();
584
585 free(const_cast<char*>(original_script_name));
586 free(const_cast<char*>(original_working_directory)); 643 free(const_cast<char*>(original_working_directory));
587 free(const_cast<char*>(original_script_url));
588 644
589 return kErrorExitCode; 645 return kErrorExitCode;
590 } 646 }
591 647
592 648
593 int main(int argc, char** argv) { 649 int main(int argc, char** argv) {
594 char* executable_name; 650 char* executable_name;
595 char* script_name; 651 char* script_name;
596 CommandLineOptions vm_options(argc); 652 CommandLineOptions vm_options(argc);
597 CommandLineOptions dart_options(argc); 653 CommandLineOptions dart_options(argc);
(...skipping 14 matching lines...) Expand all
612 &dart_options) < 0) { 668 &dart_options) < 0) {
613 PrintUsage(); 669 PrintUsage();
614 return kErrorExitCode; 670 return kErrorExitCode;
615 } 671 }
616 672
617 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 673 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
618 674
619 // Initialize the Dart VM. 675 // Initialize the Dart VM.
620 Dart_Initialize(CreateIsolateAndSetup, NULL); 676 Dart_Initialize(CreateIsolateAndSetup, NULL);
621 677
622 original_script_name = strdup(script_name);
623 original_working_directory = Directory::Current(); 678 original_working_directory = Directory::Current();
624 679
625 // Call CreateIsolateAndSetup which creates an isolate and loads up 680 // Call CreateIsolateAndSetup which creates an isolate and loads up
626 // the specified application script. 681 // the specified application script.
627 char* error = NULL; 682 char* error = NULL;
628 char* isolate_name = BuildIsolateName(original_script_name, "main"); 683 char* isolate_name = BuildIsolateName(script_name, "main");
629 if (!CreateIsolateAndSetup(isolate_name, NULL, &error)) { 684 if (!CreateIsolateAndSetupHelper(script_name,
685 "main",
686 true, // Canonicalize the script name.
687 NULL,
688 &error)) {
630 fprintf(stderr, "%s\n", error); 689 fprintf(stderr, "%s\n", error);
631 free(const_cast<char*>(original_script_name));
632 free(const_cast<char*>(original_working_directory)); 690 free(const_cast<char*>(original_working_directory));
633 free(error); 691 free(error);
634 delete [] isolate_name; 692 delete [] isolate_name;
635 return 255; // Indicates we encountered an error. 693 return 255; // Indicates we encountered an error.
636 } 694 }
637 delete [] isolate_name; 695 delete [] isolate_name;
638 696
639 Dart_Isolate isolate = Dart_CurrentIsolate(); 697 Dart_Isolate isolate = Dart_CurrentIsolate();
640 ASSERT(isolate != NULL); 698 ASSERT(isolate != NULL);
641 Dart_Handle result; 699 Dart_Handle result;
642 700
643 Dart_EnterScope(); 701 Dart_EnterScope();
644 702
645 if (has_compile_all) { 703 if (has_compile_all) {
646 result = Dart_CompileAll(); 704 result = Dart_CompileAll();
647 if (Dart_IsError(result)) { 705 if (Dart_IsError(result)) {
648 return ErrorExit("%s\n", Dart_GetError(result)); 706 return ErrorExit("%s\n", Dart_GetError(result));
649 } 707 }
650 } 708 }
651 709
652 // Create a dart options object that can be accessed from dart code. 710 // Create a dart options object that can be accessed from dart code.
653 Dart_Handle options_result = 711 Dart_Handle options_result =
654 SetupRuntimeOptions(&dart_options, executable_name, original_script_name); 712 SetupRuntimeOptions(&dart_options, executable_name, script_name);
655 if (Dart_IsError(options_result)) { 713 if (Dart_IsError(options_result)) {
656 return ErrorExit("%s\n", Dart_GetError(options_result)); 714 return ErrorExit("%s\n", Dart_GetError(options_result));
657 } 715 }
658 // Lookup the library of the main script. 716 // Lookup the library of the root script.
659 Dart_Handle script_url = Dart_NewString(original_script_url); 717 Dart_Handle library = Dart_RootLibrary();
660 Dart_Handle library = Dart_LookupLibrary(script_url); 718 if (Dart_IsNull(library)) {
661 if (Dart_IsError(library)) { 719 return ErrorExit("Unable to find root library for '%s'\n",
662 return ErrorExit("%s\n", Dart_GetError(library)); 720 script_name);
663 } 721 }
664 // Set debug breakpoint if specified on the command line. 722 // Set debug breakpoint if specified on the command line.
665 if (breakpoint_at != NULL) { 723 if (breakpoint_at != NULL) {
666 result = SetBreakpoint(breakpoint_at, library); 724 result = SetBreakpoint(breakpoint_at, library);
667 if (Dart_IsError(result)) { 725 if (Dart_IsError(result)) {
668 return ErrorExit("Error setting breakpoint at '%s': %s\n", 726 return ErrorExit("Error setting breakpoint at '%s': %s\n",
669 breakpoint_at, 727 breakpoint_at,
670 Dart_GetError(result)); 728 Dart_GetError(result));
671 } 729 }
672 } 730 }
(...skipping 16 matching lines...) Expand all
689 } 747 }
690 748
691 Dart_ExitScope(); 749 Dart_ExitScope();
692 // Dump symbol information for the profiler. 750 // Dump symbol information for the profiler.
693 DumpPprofSymbolInfo(); 751 DumpPprofSymbolInfo();
694 // Shutdown the isolate. 752 // Shutdown the isolate.
695 Dart_ShutdownIsolate(); 753 Dart_ShutdownIsolate();
696 // Terminate process exit-code handler. 754 // Terminate process exit-code handler.
697 Process::TerminateExitCodeHandler(); 755 Process::TerminateExitCodeHandler();
698 756
699 free(const_cast<char*>(original_script_name));
700 free(const_cast<char*>(original_working_directory)); 757 free(const_cast<char*>(original_working_directory));
701 free(const_cast<char*>(original_script_url));
702 758
703 return 0; 759 return 0;
704 } 760 }
OLDNEW
« no previous file with comments | « runtime/bin/gen_snapshot.cc ('k') | runtime/include/dart_api.h » ('j') | runtime/lib/isolate.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698