| OLD | NEW |
| 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 Loading... |
| 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, import_map); | 432 return Dart_LoadScript(script_url, source, LibraryTagHandler, 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 | |
| 460 // Prepare builtin and its dependent libraries for use to resolve URIs. | 453 // Prepare builtin and its dependent libraries for use to resolve URIs. |
| 461 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary); | 454 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary); |
| 462 if (Dart_IsError(uri_lib)) { | 455 if (Dart_IsError(uri_lib)) { |
| 463 *error = strdup(Dart_GetError(uri_lib)); | 456 *error = strdup(Dart_GetError(uri_lib)); |
| 464 return false; | 457 return false; |
| 465 } | 458 } |
| 466 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); | 459 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); |
| 467 if (Dart_IsError(builtin_lib)) { | 460 if (Dart_IsError(builtin_lib)) { |
| 468 *error = strdup(Dart_GetError(builtin_lib)); | 461 *error = strdup(Dart_GetError(builtin_lib)); |
| 469 return false; | 462 return false; |
| 470 } | 463 } |
| 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 } |
| 471 | 469 |
| 472 if (package_root != NULL) { | 470 if (package_root != NULL) { |
| 473 Dart_Handle dart_args[1]; | 471 Dart_Handle dart_args[1]; |
| 474 | 472 |
| 475 Dart_Handle handle = Dart_NewString(package_root); | 473 Dart_Handle handle = Dart_NewString(package_root); |
| 476 if (Dart_IsError(handle)) { | 474 if (Dart_IsError(handle)) { |
| 477 *error = strdup(Dart_GetError(handle)); | 475 *error = strdup(Dart_GetError(handle)); |
| 478 return false; | 476 return false; |
| 479 } | 477 } |
| 480 dart_args[0] = handle; | 478 dart_args[0] = handle; |
| 481 | 479 |
| 482 Dart_Handle result = Dart_Invoke(builtin_lib, | 480 Dart_Handle result = Dart_Invoke(builtin_lib, |
| 483 Dart_NewString("_setPackageRoot"), 1, dart_args); | 481 Dart_NewString("_setPackageRoot"), 1, dart_args); |
| 484 if (Dart_IsError(result)) { | 482 if (Dart_IsError(result)) { |
| 485 *error = strdup(Dart_GetError(result)); | 483 *error = strdup(Dart_GetError(result)); |
| 486 return false; | 484 return false; |
| 487 } | 485 } |
| 488 } | 486 } |
| 489 | 487 |
| 490 // Load the specified application script into the newly created isolate. | 488 // Load the specified application script into the newly created isolate. |
| 491 Dart_Handle library = LoadScript(builtin_lib, import_map_options); | 489 library = LoadScript(builtin_lib, import_map_options); |
| 492 if (Dart_IsError(library)) { | 490 if (Dart_IsError(library)) { |
| 493 *error = strdup(Dart_GetError(library)); | 491 *error = strdup(Dart_GetError(library)); |
| 494 Dart_ExitScope(); | 492 Dart_ExitScope(); |
| 495 Dart_ShutdownIsolate(); | 493 Dart_ShutdownIsolate(); |
| 496 return false; | 494 return false; |
| 497 } | 495 } |
| 498 if (!Dart_IsLibrary(library)) { | 496 if (!Dart_IsLibrary(library)) { |
| 499 char errbuf[256]; | 497 char errbuf[256]; |
| 500 snprintf(errbuf, sizeof(errbuf), | 498 snprintf(errbuf, sizeof(errbuf), |
| 501 "Expected a library when loading script: %s", | 499 "Expected a library when loading script: %s", |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 Dart_ShutdownIsolate(); | 693 Dart_ShutdownIsolate(); |
| 696 // Terminate process exit-code handler. | 694 // Terminate process exit-code handler. |
| 697 Process::TerminateExitCodeHandler(); | 695 Process::TerminateExitCodeHandler(); |
| 698 | 696 |
| 699 free(const_cast<char*>(original_script_name)); | 697 free(const_cast<char*>(original_script_name)); |
| 700 free(const_cast<char*>(original_working_directory)); | 698 free(const_cast<char*>(original_working_directory)); |
| 701 free(const_cast<char*>(original_script_url)); | 699 free(const_cast<char*>(original_script_url)); |
| 702 | 700 |
| 703 return 0; | 701 return 0; |
| 704 } | 702 } |
| OLD | NEW |