| 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 "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "include/dart_tools_api.h" | 8 #include "include/dart_tools_api.h" |
| 9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
| 10 | 10 |
| 11 #include "platform/assert.h" | 11 #include "platform/assert.h" |
| 12 #include "platform/globals.h" | 12 #include "platform/globals.h" |
| 13 | 13 |
| 14 #include "bin/crypto.h" | 14 #include "bin/crypto.h" |
| 15 #include "bin/directory.h" | 15 #include "bin/directory.h" |
| 16 #include "bin/extensions.h" | 16 #include "bin/extensions.h" |
| 17 #include "bin/file.h" | 17 #include "bin/file.h" |
| 18 #include "bin/io_buffer.h" | 18 #include "bin/io_buffer.h" |
| 19 #include "bin/isolate_data.h" | |
| 20 #include "bin/platform.h" | 19 #include "bin/platform.h" |
| 21 #include "bin/socket.h" | 20 #include "bin/socket.h" |
| 22 #include "bin/utils.h" | 21 #include "bin/utils.h" |
| 23 | 22 |
| 24 // Return the error from the containing function if handle is in error handle. | 23 // Return the error from the containing function if handle is in error handle. |
| 25 #define RETURN_IF_ERROR(handle) \ | 24 #define RETURN_IF_ERROR(handle) \ |
| 26 { \ | 25 { \ |
| 27 Dart_Handle __handle = handle; \ | 26 Dart_Handle __handle = handle; \ |
| 28 if (Dart_IsError((__handle))) { \ | 27 if (Dart_IsError((__handle))) { \ |
| 29 return __handle; \ | 28 return __handle; \ |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 ASSERT(td_len == len); | 297 ASSERT(td_len == len); |
| 299 ASSERT(td_data != NULL); | 298 ASSERT(td_data != NULL); |
| 300 memmove(td_data, buffer, td_len); | 299 memmove(td_data, buffer, td_len); |
| 301 result = Dart_TypedDataReleaseData(array); | 300 result = Dart_TypedDataReleaseData(array); |
| 302 RETURN_IF_ERROR(result); | 301 RETURN_IF_ERROR(result); |
| 303 } | 302 } |
| 304 return array; | 303 return array; |
| 305 } | 304 } |
| 306 | 305 |
| 307 | 306 |
| 308 Dart_Handle DartUtils::SetWorkingDirectory(Dart_Handle builtin_lib) { | 307 Dart_Handle DartUtils::SetWorkingDirectory() { |
| 308 IsolateData* isolate_data = |
| 309 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
| 310 Dart_Handle builtin_lib = isolate_data->builtin_lib(); |
| 309 Dart_Handle directory = NewString(original_working_directory); | 311 Dart_Handle directory = NewString(original_working_directory); |
| 310 return SingleArgDart_Invoke(builtin_lib, "_setWorkingDirectory", directory); | 312 return SingleArgDart_Invoke(builtin_lib, "_setWorkingDirectory", directory); |
| 311 } | 313 } |
| 312 | 314 |
| 313 | 315 |
| 314 Dart_Handle DartUtils::ResolveUriInWorkingDirectory(Dart_Handle script_uri, | 316 Dart_Handle DartUtils::ResolveUriInWorkingDirectory(Dart_Handle script_uri) { |
| 315 Dart_Handle builtin_lib) { | |
| 316 const int kNumArgs = 1; | 317 const int kNumArgs = 1; |
| 317 Dart_Handle dart_args[kNumArgs]; | 318 Dart_Handle dart_args[kNumArgs]; |
| 318 dart_args[0] = script_uri; | 319 dart_args[0] = script_uri; |
| 319 return Dart_Invoke(builtin_lib, | 320 return Dart_Invoke(DartUtils::BuiltinLib(), |
| 320 NewString("_resolveInWorkingDirectory"), | 321 NewString("_resolveInWorkingDirectory"), |
| 321 kNumArgs, | 322 kNumArgs, |
| 322 dart_args); | 323 dart_args); |
| 323 } | 324 } |
| 324 | 325 |
| 325 | 326 |
| 326 Dart_Handle DartUtils::FilePathFromUri(Dart_Handle script_uri, | 327 Dart_Handle DartUtils::FilePathFromUri(Dart_Handle script_uri) { |
| 327 Dart_Handle builtin_lib) { | |
| 328 const int kNumArgs = 1; | 328 const int kNumArgs = 1; |
| 329 Dart_Handle dart_args[kNumArgs]; | 329 Dart_Handle dart_args[kNumArgs]; |
| 330 dart_args[0] = script_uri; | 330 dart_args[0] = script_uri; |
| 331 return Dart_Invoke(builtin_lib, | 331 return Dart_Invoke(DartUtils::BuiltinLib(), |
| 332 NewString("_filePathFromUri"), | 332 NewString("_filePathFromUri"), |
| 333 kNumArgs, | 333 kNumArgs, |
| 334 dart_args); | 334 dart_args); |
| 335 } | 335 } |
| 336 | 336 |
| 337 | 337 |
| 338 Dart_Handle DartUtils::ExtensionPathFromUri(Dart_Handle extension_uri, | 338 Dart_Handle DartUtils::ExtensionPathFromUri(Dart_Handle extension_uri) { |
| 339 Dart_Handle builtin_lib) { | |
| 340 const int kNumArgs = 1; | 339 const int kNumArgs = 1; |
| 341 Dart_Handle dart_args[kNumArgs]; | 340 Dart_Handle dart_args[kNumArgs]; |
| 342 dart_args[0] = extension_uri; | 341 dart_args[0] = extension_uri; |
| 343 return Dart_Invoke(builtin_lib, | 342 return Dart_Invoke(DartUtils::BuiltinLib(), |
| 344 NewString("_extensionPathFromUri"), | 343 NewString("_extensionPathFromUri"), |
| 345 kNumArgs, | 344 kNumArgs, |
| 346 dart_args); | 345 dart_args); |
| 347 } | 346 } |
| 348 | 347 |
| 349 | 348 |
| 350 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, | 349 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, Dart_Handle url) { |
| 351 Dart_Handle url, | |
| 352 Dart_Handle builtin_lib) { | |
| 353 const int kNumArgs = 2; | 350 const int kNumArgs = 2; |
| 354 Dart_Handle dart_args[kNumArgs]; | 351 Dart_Handle dart_args[kNumArgs]; |
| 355 dart_args[0] = library_url; | 352 dart_args[0] = library_url; |
| 356 dart_args[1] = url; | 353 dart_args[1] = url; |
| 357 return Dart_Invoke( | 354 return Dart_Invoke(DartUtils::BuiltinLib(), |
| 358 builtin_lib, NewString("_resolveUri"), kNumArgs, dart_args); | 355 NewString("_resolveUri"), |
| 356 kNumArgs, |
| 357 dart_args); |
| 359 } | 358 } |
| 360 | 359 |
| 361 | 360 |
| 362 static Dart_Handle LoadDataAsync_Invoke(Dart_Handle tag, | 361 static Dart_Handle LoadDataAsync_Invoke(Dart_Handle tag, |
| 363 Dart_Handle url, | 362 Dart_Handle url, |
| 364 Dart_Handle library_url, | 363 Dart_Handle library_url) { |
| 365 Dart_Handle builtin_lib) { | |
| 366 const int kNumArgs = 3; | 364 const int kNumArgs = 3; |
| 367 Dart_Handle dart_args[kNumArgs]; | 365 Dart_Handle dart_args[kNumArgs]; |
| 368 dart_args[0] = tag; | 366 dart_args[0] = tag; |
| 369 dart_args[1] = url; | 367 dart_args[1] = url; |
| 370 dart_args[2] = library_url; | 368 dart_args[2] = library_url; |
| 371 return Dart_Invoke(builtin_lib, | 369 return Dart_Invoke(DartUtils::BuiltinLib(), |
| 372 DartUtils::NewString("_loadDataAsync"), | 370 DartUtils::NewString("_loadDataAsync"), |
| 373 kNumArgs, | 371 kNumArgs, |
| 374 dart_args); | 372 dart_args); |
| 375 } | 373 } |
| 376 | 374 |
| 377 | 375 |
| 378 Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag, | 376 Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag, |
| 379 Dart_Handle library, | 377 Dart_Handle library, |
| 380 Dart_Handle url) { | 378 Dart_Handle url) { |
| 381 if (!Dart_IsLibrary(library)) { | 379 if (!Dart_IsLibrary(library)) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 400 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); | 398 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); |
| 401 | 399 |
| 402 // Handle URI canonicalization requests. | 400 // Handle URI canonicalization requests. |
| 403 if (tag == Dart_kCanonicalizeUrl) { | 401 if (tag == Dart_kCanonicalizeUrl) { |
| 404 // If this is a Dart Scheme URL or 'part' of a io library | 402 // If this is a Dart Scheme URL or 'part' of a io library |
| 405 // then it is not modified as it will be handled internally. | 403 // then it is not modified as it will be handled internally. |
| 406 if (is_dart_scheme_url || is_io_library) { | 404 if (is_dart_scheme_url || is_io_library) { |
| 407 return url; | 405 return url; |
| 408 } | 406 } |
| 409 // Resolve the url within the context of the library's URL. | 407 // Resolve the url within the context of the library's URL. |
| 410 Dart_Handle builtin_lib = | 408 return ResolveUri(library_url, url); |
| 411 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | |
| 412 RETURN_IF_ERROR(builtin_lib); | |
| 413 return ResolveUri(library_url, url, builtin_lib); | |
| 414 } | 409 } |
| 415 | 410 |
| 416 // Handle 'import' of dart scheme URIs (i.e they start with 'dart:'). | 411 // Handle 'import' of dart scheme URIs (i.e they start with 'dart:'). |
| 417 if (is_dart_scheme_url) { | 412 if (is_dart_scheme_url) { |
| 418 if (tag == Dart_kImportTag) { | 413 if (tag == Dart_kImportTag) { |
| 419 // Handle imports of other built-in libraries present in the SDK. | 414 // Handle imports of other built-in libraries present in the SDK. |
| 420 if (DartUtils::IsDartIOLibURL(url_string)) { | 415 if (DartUtils::IsDartIOLibURL(url_string)) { |
| 421 return Builtin::LoadLibrary(url, Builtin::kIOLibrary); | 416 return Builtin::LoadLibrary(url, Builtin::kIOLibrary); |
| 422 } | 417 } |
| 423 return NewError("The built-in library '%s' is not available" | 418 return NewError("The built-in library '%s' is not available" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 440 return Dart_LoadSource( | 435 return Dart_LoadSource( |
| 441 library, | 436 library, |
| 442 part_uri_obj, | 437 part_uri_obj, |
| 443 Builtin::PartSource(Builtin::kIOLibrary, url_string), 0, 0); | 438 Builtin::PartSource(Builtin::kIOLibrary, url_string), 0, 0); |
| 444 } else { | 439 } else { |
| 445 ASSERT(tag == Dart_kImportTag); | 440 ASSERT(tag == Dart_kImportTag); |
| 446 return NewError("Unable to import '%s' ", url_string); | 441 return NewError("Unable to import '%s' ", url_string); |
| 447 } | 442 } |
| 448 } | 443 } |
| 449 | 444 |
| 450 Dart_Handle builtin_lib = | |
| 451 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | |
| 452 RETURN_IF_ERROR(builtin_lib); | |
| 453 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 445 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
| 454 // Load a native code shared library to use in a native extension | 446 // Load a native code shared library to use in a native extension |
| 455 if (tag != Dart_kImportTag) { | 447 if (tag != Dart_kImportTag) { |
| 456 return NewError("Dart extensions must use import: '%s'", url_string); | 448 return NewError("Dart extensions must use import: '%s'", url_string); |
| 457 } | 449 } |
| 458 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url, builtin_lib); | 450 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url); |
| 459 if (Dart_IsError(path_parts)) { | 451 if (Dart_IsError(path_parts)) { |
| 460 return path_parts; | 452 return path_parts; |
| 461 } | 453 } |
| 462 const char* extension_directory = NULL; | 454 const char* extension_directory = NULL; |
| 463 Dart_StringToCString(Dart_ListGetAt(path_parts, 0), &extension_directory); | 455 Dart_StringToCString(Dart_ListGetAt(path_parts, 0), &extension_directory); |
| 464 const char* extension_filename = NULL; | 456 const char* extension_filename = NULL; |
| 465 Dart_StringToCString(Dart_ListGetAt(path_parts, 1), &extension_filename); | 457 Dart_StringToCString(Dart_ListGetAt(path_parts, 1), &extension_filename); |
| 466 const char* extension_name = NULL; | 458 const char* extension_name = NULL; |
| 467 Dart_StringToCString(Dart_ListGetAt(path_parts, 2), &extension_name); | 459 Dart_StringToCString(Dart_ListGetAt(path_parts, 2), &extension_name); |
| 468 | 460 |
| 469 return Extensions::LoadExtension(extension_directory, | 461 return Extensions::LoadExtension(extension_directory, |
| 470 extension_filename, | 462 extension_filename, |
| 471 extension_name, | 463 extension_name, |
| 472 library); | 464 library); |
| 473 } | 465 } |
| 474 | 466 |
| 475 // Handle 'import' or 'part' requests for all other URIs. Call dart code to | 467 // Handle 'import' or 'part' requests for all other URIs. Call dart code to |
| 476 // read the source code asynchronously. | 468 // read the source code asynchronously. |
| 477 return LoadDataAsync_Invoke(Dart_NewInteger(tag), | 469 return LoadDataAsync_Invoke(Dart_NewInteger(tag), url, library_url); |
| 478 url, | |
| 479 library_url, | |
| 480 builtin_lib); | |
| 481 } | 470 } |
| 482 | 471 |
| 483 | 472 |
| 484 const uint8_t* DartUtils::SniffForMagicNumber(const uint8_t* text_buffer, | 473 const uint8_t* DartUtils::SniffForMagicNumber(const uint8_t* text_buffer, |
| 485 intptr_t* buffer_len, | 474 intptr_t* buffer_len, |
| 486 bool* is_snapshot) { | 475 bool* is_snapshot) { |
| 487 intptr_t len = sizeof(magic_number); | 476 intptr_t len = sizeof(magic_number); |
| 488 if (*buffer_len <= len) { | 477 if (*buffer_len <= len) { |
| 489 *is_snapshot = false; | 478 *is_snapshot = false; |
| 490 return text_buffer; | 479 return text_buffer; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 502 } | 491 } |
| 503 | 492 |
| 504 | 493 |
| 505 void DartUtils::WriteMagicNumber(File* file) { | 494 void DartUtils::WriteMagicNumber(File* file) { |
| 506 // Write a magic number and version information into the snapshot file. | 495 // Write a magic number and version information into the snapshot file. |
| 507 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number)); | 496 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number)); |
| 508 ASSERT(bytes_written); | 497 ASSERT(bytes_written); |
| 509 } | 498 } |
| 510 | 499 |
| 511 | 500 |
| 512 Dart_Handle DartUtils::LoadScript(const char* script_uri, | 501 Dart_Handle DartUtils::LoadScript(const char* script_uri) { |
| 513 Dart_Handle builtin_lib) { | |
| 514 Dart_Handle uri = Dart_NewStringFromCString(script_uri); | 502 Dart_Handle uri = Dart_NewStringFromCString(script_uri); |
| 515 IsolateData* isolate_data = | 503 IsolateData* isolate_data = |
| 516 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 504 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
| 517 Dart_TimelineAsyncBegin("LoadScript", &(isolate_data->load_async_id)); | 505 Dart_TimelineAsyncBegin("LoadScript", &(isolate_data->load_async_id)); |
| 518 return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null(), builtin_lib); | 506 return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null()); |
| 519 } | 507 } |
| 520 | 508 |
| 521 | 509 |
| 522 // Callback function, gets called from asynchronous script and library | 510 // Callback function, gets called from asynchronous script and library |
| 523 // reading code when there is an i/o error. | 511 // reading code when there is an i/o error. |
| 524 void FUNCTION_NAME(Builtin_AsyncLoadError)(Dart_NativeArguments args) { | 512 void FUNCTION_NAME(Builtin_AsyncLoadError)(Dart_NativeArguments args) { |
| 525 // Dart_Handle source_uri = Dart_GetNativeArgument(args, 0); | 513 // Dart_Handle source_uri = Dart_GetNativeArgument(args, 0); |
| 526 Dart_Handle library_uri = Dart_GetNativeArgument(args, 1); | 514 Dart_Handle library_uri = Dart_GetNativeArgument(args, 1); |
| 527 Dart_Handle error = Dart_GetNativeArgument(args, 2); | 515 Dart_Handle error = Dart_GetNativeArgument(args, 2); |
| 528 | 516 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 } else { | 637 } else { |
| 650 Dart_Handle err = DartUtils::NewError("Failed to get current directory."); | 638 Dart_Handle err = DartUtils::NewError("Failed to get current directory."); |
| 651 Dart_PropagateError(err); | 639 Dart_PropagateError(err); |
| 652 } | 640 } |
| 653 } | 641 } |
| 654 | 642 |
| 655 | 643 |
| 656 Dart_Handle DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, | 644 Dart_Handle DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, |
| 657 Dart_Handle internal_lib, | 645 Dart_Handle internal_lib, |
| 658 bool is_service_isolate, | 646 bool is_service_isolate, |
| 659 bool trace_loading, | 647 bool trace_loading) { |
| 660 const char* package_root, | |
| 661 const char* packages_config) { | |
| 662 // Setup the internal library's 'internalPrint' function. | 648 // Setup the internal library's 'internalPrint' function. |
| 663 Dart_Handle print = Dart_Invoke( | 649 Dart_Handle print = Dart_Invoke( |
| 664 builtin_lib, NewString("_getPrintClosure"), 0, NULL); | 650 builtin_lib, NewString("_getPrintClosure"), 0, NULL); |
| 665 RETURN_IF_ERROR(print); | 651 RETURN_IF_ERROR(print); |
| 666 Dart_Handle result = | 652 Dart_Handle result = |
| 667 Dart_SetField(internal_lib, NewString("_printClosure"), print); | 653 Dart_SetField(internal_lib, NewString("_printClosure"), print); |
| 668 RETURN_IF_ERROR(result); | 654 RETURN_IF_ERROR(result); |
| 669 | 655 |
| 670 if (!is_service_isolate) { | 656 if (!is_service_isolate) { |
| 671 if (IsWindowsHost()) { | 657 if (IsWindowsHost()) { |
| 672 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); | 658 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); |
| 673 RETURN_IF_ERROR(result); | 659 RETURN_IF_ERROR(result); |
| 674 } | 660 } |
| 675 if (trace_loading) { | 661 if (trace_loading) { |
| 676 result = Dart_SetField(builtin_lib, | 662 result = Dart_SetField(builtin_lib, |
| 677 NewString("_traceLoading"), Dart_True()); | 663 NewString("_traceLoading"), Dart_True()); |
| 678 RETURN_IF_ERROR(result); | 664 RETURN_IF_ERROR(result); |
| 679 } | 665 } |
| 680 // Set current working directory. | 666 // Set current working directory. |
| 681 result = SetWorkingDirectory(builtin_lib); | 667 result = SetWorkingDirectory(); |
| 682 RETURN_IF_ERROR(result); | |
| 683 // Wait for the service isolate to initialize the load port. | |
| 684 Dart_Port load_port = Dart_ServiceWaitForLoadPort(); | |
| 685 if (load_port == ILLEGAL_PORT) { | |
| 686 return Dart_NewUnhandledExceptionError( | |
| 687 NewDartUnsupportedError("Service did not return load port.")); | |
| 688 } | |
| 689 result = Builtin::SetLoadPort(load_port); | |
| 690 RETURN_IF_ERROR(result); | |
| 691 } | |
| 692 | |
| 693 // Set up package root if specified. | |
| 694 if (package_root != NULL) { | |
| 695 ASSERT(packages_config == NULL); | |
| 696 result = NewString(package_root); | |
| 697 RETURN_IF_ERROR(result); | |
| 698 const int kNumArgs = 1; | |
| 699 Dart_Handle dart_args[kNumArgs]; | |
| 700 dart_args[0] = result; | |
| 701 result = Dart_Invoke(builtin_lib, | |
| 702 NewString("_setPackageRoot"), | |
| 703 kNumArgs, | |
| 704 dart_args); | |
| 705 RETURN_IF_ERROR(result); | |
| 706 } else if (packages_config != NULL) { | |
| 707 result = NewString(packages_config); | |
| 708 RETURN_IF_ERROR(result); | |
| 709 const int kNumArgs = 1; | |
| 710 Dart_Handle dart_args[kNumArgs]; | |
| 711 dart_args[0] = result; | |
| 712 result = Dart_Invoke(builtin_lib, | |
| 713 NewString("_loadPackagesMap"), | |
| 714 kNumArgs, | |
| 715 dart_args); | |
| 716 RETURN_IF_ERROR(result); | 668 RETURN_IF_ERROR(result); |
| 717 } | 669 } |
| 718 return Dart_True(); | 670 return Dart_True(); |
| 719 } | 671 } |
| 720 | 672 |
| 721 | 673 |
| 722 Dart_Handle DartUtils::PrepareCoreLibrary(Dart_Handle core_lib, | 674 Dart_Handle DartUtils::PrepareCoreLibrary(Dart_Handle core_lib, |
| 723 Dart_Handle builtin_lib, | 675 Dart_Handle builtin_lib, |
| 724 bool is_service_isolate) { | 676 bool is_service_isolate) { |
| 725 if (!is_service_isolate) { | 677 if (!is_service_isolate) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 752 Dart_Handle DartUtils::PrepareIOLibrary(Dart_Handle io_lib) { | 704 Dart_Handle DartUtils::PrepareIOLibrary(Dart_Handle io_lib) { |
| 753 return Dart_Invoke(io_lib, NewString("_setupHooks"), 0, NULL); | 705 return Dart_Invoke(io_lib, NewString("_setupHooks"), 0, NULL); |
| 754 } | 706 } |
| 755 | 707 |
| 756 | 708 |
| 757 Dart_Handle DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { | 709 Dart_Handle DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { |
| 758 return Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL); | 710 return Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL); |
| 759 } | 711 } |
| 760 | 712 |
| 761 | 713 |
| 762 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, | 714 Dart_Handle DartUtils::SetupServiceLoadPort() { |
| 763 const char* packages_config, | 715 // Wait for the service isolate to initialize the load port. |
| 764 bool is_service_isolate, | 716 Dart_Port load_port = Dart_ServiceWaitForLoadPort(); |
| 765 bool trace_loading, | 717 if (load_port == ILLEGAL_PORT) { |
| 766 Dart_Handle builtin_lib) { | 718 return Dart_NewUnhandledExceptionError( |
| 719 NewDartUnsupportedError("Service did not return load port.")); |
| 720 } |
| 721 return Builtin::SetLoadPort(load_port); |
| 722 } |
| 723 |
| 724 |
| 725 Dart_Handle DartUtils::SetupPackageRoot(const char* package_root, |
| 726 const char* packages_config) { |
| 727 // Set up package root if specified. |
| 728 if (package_root != NULL) { |
| 729 ASSERT(packages_config == NULL); |
| 730 Dart_Handle result = NewString(package_root); |
| 731 RETURN_IF_ERROR(result); |
| 732 const int kNumArgs = 1; |
| 733 Dart_Handle dart_args[kNumArgs]; |
| 734 dart_args[0] = result; |
| 735 result = Dart_Invoke(DartUtils::BuiltinLib(), |
| 736 NewString("_setPackageRoot"), |
| 737 kNumArgs, |
| 738 dart_args); |
| 739 RETURN_IF_ERROR(result); |
| 740 } else if (packages_config != NULL) { |
| 741 Dart_Handle result = NewString(packages_config); |
| 742 RETURN_IF_ERROR(result); |
| 743 const int kNumArgs = 1; |
| 744 Dart_Handle dart_args[kNumArgs]; |
| 745 dart_args[0] = result; |
| 746 result = Dart_Invoke(DartUtils::BuiltinLib(), |
| 747 NewString("_loadPackagesMap"), |
| 748 kNumArgs, |
| 749 dart_args); |
| 750 RETURN_IF_ERROR(result); |
| 751 } |
| 752 return Dart_True(); |
| 753 } |
| 754 |
| 755 |
| 756 Dart_Handle DartUtils::PrepareForScriptLoading(bool is_service_isolate, |
| 757 bool trace_loading) { |
| 767 // First ensure all required libraries are available. | 758 // First ensure all required libraries are available. |
| 768 Dart_Handle url = NewString(kCoreLibURL); | 759 Dart_Handle url = NewString(kCoreLibURL); |
| 769 RETURN_IF_ERROR(url); | 760 RETURN_IF_ERROR(url); |
| 770 Dart_Handle core_lib = Dart_LookupLibrary(url); | 761 Dart_Handle core_lib = Dart_LookupLibrary(url); |
| 771 RETURN_IF_ERROR(core_lib); | 762 RETURN_IF_ERROR(core_lib); |
| 772 url = NewString(kAsyncLibURL); | 763 url = NewString(kAsyncLibURL); |
| 773 RETURN_IF_ERROR(url); | 764 RETURN_IF_ERROR(url); |
| 774 Dart_Handle async_lib = Dart_LookupLibrary(url); | 765 Dart_Handle async_lib = Dart_LookupLibrary(url); |
| 775 RETURN_IF_ERROR(async_lib); | 766 RETURN_IF_ERROR(async_lib); |
| 776 url = NewString(kIsolateLibURL); | 767 url = NewString(kIsolateLibURL); |
| 777 RETURN_IF_ERROR(url); | 768 RETURN_IF_ERROR(url); |
| 778 Dart_Handle isolate_lib = Dart_LookupLibrary(url); | 769 Dart_Handle isolate_lib = Dart_LookupLibrary(url); |
| 779 RETURN_IF_ERROR(isolate_lib); | 770 RETURN_IF_ERROR(isolate_lib); |
| 780 url = NewString(kInternalLibURL); | 771 url = NewString(kInternalLibURL); |
| 781 RETURN_IF_ERROR(url); | 772 RETURN_IF_ERROR(url); |
| 782 Dart_Handle internal_lib = Dart_LookupLibrary(url); | 773 Dart_Handle internal_lib = Dart_LookupLibrary(url); |
| 783 RETURN_IF_ERROR(internal_lib); | 774 RETURN_IF_ERROR(internal_lib); |
| 775 Dart_Handle builtin_lib = |
| 776 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 777 RETURN_IF_ERROR(builtin_lib); |
| 784 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 778 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
| 785 RETURN_IF_ERROR(io_lib); | 779 RETURN_IF_ERROR(io_lib); |
| 786 | 780 |
| 781 // Setup the builtin library in a persistent handle attached the isolate |
| 782 // specific data as we seem to lookup and use builtin lib a lot. |
| 783 IsolateData* isolate_data = |
| 784 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
| 785 ASSERT(isolate_data != NULL); |
| 786 isolate_data->set_builtin_lib(builtin_lib); |
| 787 |
| 787 // We need to ensure that all the scripts loaded so far are finalized | 788 // We need to ensure that all the scripts loaded so far are finalized |
| 788 // as we are about to invoke some Dart code below to setup closures. | 789 // as we are about to invoke some Dart code below to setup closures. |
| 789 Dart_Handle result = Dart_FinalizeLoading(false); | 790 Dart_Handle result = Dart_FinalizeLoading(false); |
| 790 RETURN_IF_ERROR(result); | 791 RETURN_IF_ERROR(result); |
| 791 | 792 |
| 792 result = PrepareBuiltinLibrary(builtin_lib, | 793 result = PrepareBuiltinLibrary(builtin_lib, |
| 793 internal_lib, | 794 internal_lib, |
| 794 is_service_isolate, | 795 is_service_isolate, |
| 795 trace_loading, | 796 trace_loading); |
| 796 package_root, | |
| 797 packages_config); | |
| 798 RETURN_IF_ERROR(result); | 797 RETURN_IF_ERROR(result); |
| 799 | 798 |
| 800 RETURN_IF_ERROR(PrepareAsyncLibrary(async_lib, isolate_lib)); | 799 RETURN_IF_ERROR(PrepareAsyncLibrary(async_lib, isolate_lib)); |
| 801 RETURN_IF_ERROR(PrepareCoreLibrary( | 800 RETURN_IF_ERROR(PrepareCoreLibrary( |
| 802 core_lib, builtin_lib, is_service_isolate)); | 801 core_lib, builtin_lib, is_service_isolate)); |
| 803 RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib)); | 802 RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib)); |
| 804 RETURN_IF_ERROR(PrepareIOLibrary(io_lib)); | 803 RETURN_IF_ERROR(PrepareIOLibrary(io_lib)); |
| 805 return result; | 804 return result; |
| 806 } | 805 } |
| 807 | 806 |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1262 new CObjectString(CObject::NewString(os_error->message())); | 1261 new CObjectString(CObject::NewString(os_error->message())); |
| 1263 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1262 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 1264 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1263 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 1265 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1264 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 1266 result->SetAt(2, error_message); | 1265 result->SetAt(2, error_message); |
| 1267 return result; | 1266 return result; |
| 1268 } | 1267 } |
| 1269 | 1268 |
| 1270 } // namespace bin | 1269 } // namespace bin |
| 1271 } // namespace dart | 1270 } // namespace dart |
| OLD | NEW |