| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 *map_name = '\0'; | 369 *map_name = '\0'; |
| 370 map_name += 1; | 370 map_name += 1; |
| 371 Dart_ListSetAt(import_map, index, Dart_NewString(name)); | 371 Dart_ListSetAt(import_map, index, Dart_NewString(name)); |
| 372 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); | 372 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); |
| 373 } else { | 373 } else { |
| 374 Dart_ListSetAt(import_map, index, Dart_NewString(name)); | 374 Dart_ListSetAt(import_map, index, Dart_NewString(name)); |
| 375 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); | 375 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); |
| 376 } | 376 } |
| 377 free(name); | 377 free(name); |
| 378 } | 378 } |
| 379 return Dart_LoadScript(script_url, source, LibraryTagHandler, import_map); | 379 return Dart_LoadScript(script_url, source, import_map); |
| 380 } | 380 } |
| 381 | 381 |
| 382 | 382 |
| 383 // Returns true on success, false on failure. | 383 // Returns true on success, false on failure. |
| 384 static bool CreateIsolateAndSetup(const char* name_prefix, | 384 static bool CreateIsolateAndSetup(const char* name_prefix, |
| 385 void* data, char** error) { | 385 void* data, char** error) { |
| 386 Dart_Isolate isolate = | 386 Dart_Isolate isolate = |
| 387 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); | 387 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); |
| 388 if (isolate == NULL) { | 388 if (isolate == NULL) { |
| 389 return false; | 389 return false; |
| 390 } | 390 } |
| 391 | 391 |
| 392 Dart_EnterScope(); | 392 Dart_EnterScope(); |
| 393 | 393 |
| 394 if (snapshot_buffer != NULL) { | 394 if (snapshot_buffer != NULL) { |
| 395 // Setup the native resolver as the snapshot does not carry it. | 395 // Setup the native resolver as the snapshot does not carry it. |
| 396 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 396 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 397 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 397 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 398 } | 398 } |
| 399 | 399 |
| 400 // Set up the library tag handler for this isolate. |
| 401 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); |
| 402 if (Dart_IsError(result)) { |
| 403 *error = strdup(Dart_GetError(result)); |
| 404 return false; |
| 405 } |
| 406 |
| 400 // Prepare builtin and its dependent libraries for use to resolve URIs. | 407 // Prepare builtin and its dependent libraries for use to resolve URIs. |
| 401 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary); | 408 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary); |
| 402 if (Dart_IsError(uri_lib)) { | 409 if (Dart_IsError(uri_lib)) { |
| 403 *error = strdup(Dart_GetError(uri_lib)); | 410 *error = strdup(Dart_GetError(uri_lib)); |
| 404 return false; | 411 return false; |
| 405 } | 412 } |
| 406 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); | 413 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); |
| 407 if (Dart_IsError(builtin_lib)) { | 414 if (Dart_IsError(builtin_lib)) { |
| 408 *error = strdup(Dart_GetError(builtin_lib)); | 415 *error = strdup(Dart_GetError(builtin_lib)); |
| 409 return false; | 416 return false; |
| 410 } | 417 } |
| 411 Dart_Handle library = Dart_LibraryImportLibrary(builtin_lib, uri_lib); | |
| 412 if (Dart_IsError(library)) { | |
| 413 *error = strdup(Dart_GetError(library)); | |
| 414 return false; | |
| 415 } | |
| 416 | 418 |
| 417 if (package_root != NULL) { | 419 if (package_root != NULL) { |
| 418 Dart_Handle dart_args[1]; | 420 Dart_Handle dart_args[1]; |
| 419 | 421 |
| 420 Dart_Handle handle = Dart_NewString(package_root); | 422 Dart_Handle handle = Dart_NewString(package_root); |
| 421 if (Dart_IsError(handle)) { | 423 if (Dart_IsError(handle)) { |
| 422 *error = strdup(Dart_GetError(handle)); | 424 *error = strdup(Dart_GetError(handle)); |
| 423 return false; | 425 return false; |
| 424 } | 426 } |
| 425 dart_args[0] = handle; | 427 dart_args[0] = handle; |
| 426 | 428 |
| 427 Dart_Handle result = Dart_Invoke(builtin_lib, | 429 Dart_Handle result = Dart_Invoke(builtin_lib, |
| 428 Dart_NewString("_setPackageRoot"), 1, dart_args); | 430 Dart_NewString("_setPackageRoot"), 1, dart_args); |
| 429 if (Dart_IsError(result)) { | 431 if (Dart_IsError(result)) { |
| 430 *error = strdup(Dart_GetError(result)); | 432 *error = strdup(Dart_GetError(result)); |
| 431 return false; | 433 return false; |
| 432 } | 434 } |
| 433 } | 435 } |
| 434 | 436 |
| 435 // Load the specified application script into the newly created isolate. | 437 // Load the specified application script into the newly created isolate. |
| 436 library = LoadScript(builtin_lib, import_map_options); | 438 Dart_Handle library = LoadScript(builtin_lib, import_map_options); |
| 437 if (Dart_IsError(library)) { | 439 if (Dart_IsError(library)) { |
| 438 *error = strdup(Dart_GetError(library)); | 440 *error = strdup(Dart_GetError(library)); |
| 439 Dart_ExitScope(); | 441 Dart_ExitScope(); |
| 440 Dart_ShutdownIsolate(); | 442 Dart_ShutdownIsolate(); |
| 441 return false; | 443 return false; |
| 442 } | 444 } |
| 443 if (!Dart_IsLibrary(library)) { | 445 if (!Dart_IsLibrary(library)) { |
| 444 char errbuf[256]; | 446 char errbuf[256]; |
| 445 snprintf(errbuf, sizeof(errbuf), | 447 snprintf(errbuf, sizeof(errbuf), |
| 446 "Expected a library when loading script: %s", | 448 "Expected a library when loading script: %s", |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 Dart_ShutdownIsolate(); | 633 Dart_ShutdownIsolate(); |
| 632 // Terminate process exit-code handler. | 634 // Terminate process exit-code handler. |
| 633 Process::TerminateExitCodeHandler(); | 635 Process::TerminateExitCodeHandler(); |
| 634 | 636 |
| 635 free(const_cast<char*>(original_script_name)); | 637 free(const_cast<char*>(original_script_name)); |
| 636 free(const_cast<char*>(original_working_directory)); | 638 free(const_cast<char*>(original_working_directory)); |
| 637 free(const_cast<char*>(original_script_url)); | 639 free(const_cast<char*>(original_script_url)); |
| 638 | 640 |
| 639 return 0; | 641 return 0; |
| 640 } | 642 } |
| OLD | NEW |