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

Side by Side Diff: bin/main.cc

Issue 10387061: Resubmit change 7506. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
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
« no previous file with comments | « bin/gen_snapshot.cc ('k') | include/dart_api.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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 *map_name = '\0'; 422 *map_name = '\0';
423 map_name += 1; 423 map_name += 1;
424 Dart_ListSetAt(import_map, index, Dart_NewString(name)); 424 Dart_ListSetAt(import_map, index, Dart_NewString(name));
425 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); 425 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name));
426 } else { 426 } else {
427 Dart_ListSetAt(import_map, index, Dart_NewString(name)); 427 Dart_ListSetAt(import_map, index, Dart_NewString(name));
428 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); 428 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(""));
429 } 429 }
430 free(name); 430 free(name);
431 } 431 }
432 return Dart_LoadScript(script_url, source, LibraryTagHandler, import_map); 432 return Dart_LoadScript(script_url, source, import_map);
433 } 433 }
434 434
435 435
436 // Returns true on success, false on failure. 436 // Returns true on success, false on failure.
437 static bool CreateIsolateAndSetup(const char* name_prefix, 437 static bool CreateIsolateAndSetup(const char* name_prefix,
438 void* data, char** error) { 438 void* data, char** error) {
439 Dart_Isolate isolate = 439 Dart_Isolate isolate =
440 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); 440 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error);
441 if (isolate == NULL) { 441 if (isolate == NULL) {
442 return false; 442 return false;
443 } 443 }
444 444
445 Dart_EnterScope(); 445 Dart_EnterScope();
446 446
447 if (snapshot_buffer != NULL) { 447 if (snapshot_buffer != NULL) {
448 // Setup the native resolver as the snapshot does not carry it. 448 // Setup the native resolver as the snapshot does not carry it.
449 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 449 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
450 Builtin::SetNativeResolver(Builtin::kIOLibrary); 450 Builtin::SetNativeResolver(Builtin::kIOLibrary);
451 } 451 }
452 452
453 // Set up the library tag handler for this isolate.
454 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler);
455 if (Dart_IsError(result)) {
456 *error = strdup(Dart_GetError(result));
457 return false;
458 }
459
453 // Prepare builtin and its dependent libraries for use to resolve URIs. 460 // Prepare builtin and its dependent libraries for use to resolve URIs.
454 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary); 461 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary);
455 if (Dart_IsError(uri_lib)) { 462 if (Dart_IsError(uri_lib)) {
456 *error = strdup(Dart_GetError(uri_lib)); 463 *error = strdup(Dart_GetError(uri_lib));
457 return false; 464 return false;
458 } 465 }
459 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); 466 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary);
460 if (Dart_IsError(builtin_lib)) { 467 if (Dart_IsError(builtin_lib)) {
461 *error = strdup(Dart_GetError(builtin_lib)); 468 *error = strdup(Dart_GetError(builtin_lib));
462 return false; 469 return false;
463 } 470 }
464 Dart_Handle library = Dart_LibraryImportLibrary(builtin_lib, uri_lib);
465 if (Dart_IsError(library)) {
466 *error = strdup(Dart_GetError(library));
467 return false;
468 }
469 471
470 if (package_root != NULL) { 472 if (package_root != NULL) {
471 Dart_Handle dart_args[1]; 473 Dart_Handle dart_args[1];
472 474
473 Dart_Handle handle = Dart_NewString(package_root); 475 Dart_Handle handle = Dart_NewString(package_root);
474 if (Dart_IsError(handle)) { 476 if (Dart_IsError(handle)) {
475 *error = strdup(Dart_GetError(handle)); 477 *error = strdup(Dart_GetError(handle));
476 return false; 478 return false;
477 } 479 }
478 dart_args[0] = handle; 480 dart_args[0] = handle;
479 481
480 Dart_Handle result = Dart_Invoke(builtin_lib, 482 Dart_Handle result = Dart_Invoke(builtin_lib,
481 Dart_NewString("_setPackageRoot"), 1, dart_args); 483 Dart_NewString("_setPackageRoot"), 1, dart_args);
482 if (Dart_IsError(result)) { 484 if (Dart_IsError(result)) {
483 *error = strdup(Dart_GetError(result)); 485 *error = strdup(Dart_GetError(result));
484 return false; 486 return false;
485 } 487 }
486 } 488 }
487 489
488 // Load the specified application script into the newly created isolate. 490 // Load the specified application script into the newly created isolate.
489 library = LoadScript(builtin_lib, import_map_options); 491 Dart_Handle library = LoadScript(builtin_lib, import_map_options);
490 if (Dart_IsError(library)) { 492 if (Dart_IsError(library)) {
491 *error = strdup(Dart_GetError(library)); 493 *error = strdup(Dart_GetError(library));
492 Dart_ExitScope(); 494 Dart_ExitScope();
493 Dart_ShutdownIsolate(); 495 Dart_ShutdownIsolate();
494 return false; 496 return false;
495 } 497 }
496 if (!Dart_IsLibrary(library)) { 498 if (!Dart_IsLibrary(library)) {
497 char errbuf[256]; 499 char errbuf[256];
498 snprintf(errbuf, sizeof(errbuf), 500 snprintf(errbuf, sizeof(errbuf),
499 "Expected a library when loading script: %s", 501 "Expected a library when loading script: %s",
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 Dart_ShutdownIsolate(); 695 Dart_ShutdownIsolate();
694 // Terminate process exit-code handler. 696 // Terminate process exit-code handler.
695 Process::TerminateExitCodeHandler(); 697 Process::TerminateExitCodeHandler();
696 698
697 free(const_cast<char*>(original_script_name)); 699 free(const_cast<char*>(original_script_name));
698 free(const_cast<char*>(original_working_directory)); 700 free(const_cast<char*>(original_working_directory));
699 free(const_cast<char*>(original_script_url)); 701 free(const_cast<char*>(original_script_url));
700 702
701 return 0; 703 return 0;
702 } 704 }
OLDNEW
« no previous file with comments | « bin/gen_snapshot.cc ('k') | include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698