| 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" | 19 #include "bin/isolate_data.h" |
| 20 #include "bin/platform.h" | 20 #include "bin/platform.h" |
| 21 #include "bin/socket.h" | 21 #include "bin/socket.h" |
| 22 #include "bin/utils.h" | 22 #include "bin/utils.h" |
| 23 | 23 |
| 24 // Return the error from the containing function if handle is in error handle. |
| 25 #define RETURN_IF_ERROR(handle) \ |
| 26 { \ |
| 27 Dart_Handle __handle = handle; \ |
| 28 if (Dart_IsError((__handle))) { \ |
| 29 return __handle; \ |
| 30 } \ |
| 31 } |
| 32 |
| 24 namespace dart { | 33 namespace dart { |
| 25 namespace bin { | 34 namespace bin { |
| 26 | 35 |
| 27 const char* DartUtils::original_working_directory = NULL; | 36 const char* DartUtils::original_working_directory = NULL; |
| 28 const char* DartUtils::kDartScheme = "dart:"; | 37 const char* DartUtils::kDartScheme = "dart:"; |
| 29 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; | 38 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; |
| 30 const char* DartUtils::kAsyncLibURL = "dart:async"; | 39 const char* DartUtils::kAsyncLibURL = "dart:async"; |
| 31 const char* DartUtils::kBuiltinLibURL = "dart:_builtin"; | 40 const char* DartUtils::kBuiltinLibURL = "dart:_builtin"; |
| 32 const char* DartUtils::kCoreLibURL = "dart:core"; | 41 const char* DartUtils::kCoreLibURL = "dart:core"; |
| 33 const char* DartUtils::kInternalLibURL = "dart:_internal"; | 42 const char* DartUtils::kInternalLibURL = "dart:_internal"; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 128 |
| 120 | 129 |
| 121 bool DartUtils::GetBooleanValue(Dart_Handle bool_obj) { | 130 bool DartUtils::GetBooleanValue(Dart_Handle bool_obj) { |
| 122 bool value = false; | 131 bool value = false; |
| 123 Dart_Handle result = Dart_BooleanValue(bool_obj, &value); | 132 Dart_Handle result = Dart_BooleanValue(bool_obj, &value); |
| 124 if (Dart_IsError(result)) Dart_PropagateError(result); | 133 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 125 return value; | 134 return value; |
| 126 } | 135 } |
| 127 | 136 |
| 128 | 137 |
| 129 void DartUtils::SetIntegerField(Dart_Handle handle, | 138 Dart_Handle DartUtils::SetIntegerField(Dart_Handle handle, |
| 130 const char* name, | 139 const char* name, |
| 131 int64_t val) { | 140 int64_t val) { |
| 132 Dart_Handle result = Dart_SetField(handle, | 141 return Dart_SetField(handle, NewString(name), Dart_NewInteger(val)); |
| 133 NewString(name), | |
| 134 Dart_NewInteger(val)); | |
| 135 if (Dart_IsError(result)) Dart_PropagateError(result); | |
| 136 } | 142 } |
| 137 | 143 |
| 138 | 144 |
| 139 void DartUtils::SetStringField(Dart_Handle handle, | 145 Dart_Handle DartUtils::SetStringField(Dart_Handle handle, |
| 140 const char* name, | 146 const char* name, |
| 141 const char* val) { | 147 const char* val) { |
| 142 Dart_Handle result = Dart_SetField(handle, NewString(name), NewString(val)); | 148 return Dart_SetField(handle, NewString(name), NewString(val)); |
| 143 if (Dart_IsError(result)) Dart_PropagateError(result); | |
| 144 } | 149 } |
| 145 | 150 |
| 146 | 151 |
| 147 bool DartUtils::IsDartSchemeURL(const char* url_name) { | 152 bool DartUtils::IsDartSchemeURL(const char* url_name) { |
| 148 static const intptr_t kDartSchemeLen = strlen(kDartScheme); | 153 static const intptr_t kDartSchemeLen = strlen(kDartScheme); |
| 149 // If the URL starts with "dart:" then it is considered as a special | 154 // If the URL starts with "dart:" then it is considered as a special |
| 150 // library URL which is handled differently from other URLs. | 155 // library URL which is handled differently from other URLs. |
| 151 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0); | 156 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0); |
| 152 } | 157 } |
| 153 | 158 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 // Handle URI canonicalization requests. | 381 // Handle URI canonicalization requests. |
| 377 if (tag == Dart_kCanonicalizeUrl) { | 382 if (tag == Dart_kCanonicalizeUrl) { |
| 378 // If this is a Dart Scheme URL or 'part' of a io library | 383 // If this is a Dart Scheme URL or 'part' of a io library |
| 379 // then it is not modified as it will be handled internally. | 384 // then it is not modified as it will be handled internally. |
| 380 if (is_dart_scheme_url || is_io_library) { | 385 if (is_dart_scheme_url || is_io_library) { |
| 381 return url; | 386 return url; |
| 382 } | 387 } |
| 383 // Resolve the url within the context of the library's URL. | 388 // Resolve the url within the context of the library's URL. |
| 384 Dart_Handle builtin_lib = | 389 Dart_Handle builtin_lib = |
| 385 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 390 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 386 DART_CHECK_VALID(builtin_lib); | 391 RETURN_IF_ERROR(builtin_lib); |
| 387 return ResolveUri(library_url, url, builtin_lib); | 392 return ResolveUri(library_url, url, builtin_lib); |
| 388 } | 393 } |
| 389 | 394 |
| 390 // Handle 'import' of dart scheme URIs (i.e they start with 'dart:'). | 395 // Handle 'import' of dart scheme URIs (i.e they start with 'dart:'). |
| 391 if (is_dart_scheme_url) { | 396 if (is_dart_scheme_url) { |
| 392 if (tag == Dart_kImportTag) { | 397 if (tag == Dart_kImportTag) { |
| 393 // Handle imports of other built-in libraries present in the SDK. | 398 // Handle imports of other built-in libraries present in the SDK. |
| 394 if (DartUtils::IsDartIOLibURL(url_string)) { | 399 if (DartUtils::IsDartIOLibURL(url_string)) { |
| 395 return Builtin::LoadLibrary(url, Builtin::kIOLibrary); | 400 return Builtin::LoadLibrary(url, Builtin::kIOLibrary); |
| 396 } | 401 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 416 part_uri_obj, | 421 part_uri_obj, |
| 417 Builtin::PartSource(Builtin::kIOLibrary, url_string), 0, 0); | 422 Builtin::PartSource(Builtin::kIOLibrary, url_string), 0, 0); |
| 418 } else { | 423 } else { |
| 419 ASSERT(tag == Dart_kImportTag); | 424 ASSERT(tag == Dart_kImportTag); |
| 420 return NewError("Unable to import '%s' ", url_string); | 425 return NewError("Unable to import '%s' ", url_string); |
| 421 } | 426 } |
| 422 } | 427 } |
| 423 | 428 |
| 424 Dart_Handle builtin_lib = | 429 Dart_Handle builtin_lib = |
| 425 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 430 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 426 DART_CHECK_VALID(builtin_lib); | 431 RETURN_IF_ERROR(builtin_lib); |
| 427 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 432 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
| 428 // Load a native code shared library to use in a native extension | 433 // Load a native code shared library to use in a native extension |
| 429 if (tag != Dart_kImportTag) { | 434 if (tag != Dart_kImportTag) { |
| 430 return NewError("Dart extensions must use import: '%s'", url_string); | 435 return NewError("Dart extensions must use import: '%s'", url_string); |
| 431 } | 436 } |
| 432 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url, builtin_lib); | 437 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url, builtin_lib); |
| 433 if (Dart_IsError(path_parts)) { | 438 if (Dart_IsError(path_parts)) { |
| 434 return path_parts; | 439 return path_parts; |
| 435 } | 440 } |
| 436 const char* extension_directory = NULL; | 441 const char* extension_directory = NULL; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 Dart_Handle source = Dart_NewStringFromUTF8(data, num_bytes); | 567 Dart_Handle source = Dart_NewStringFromUTF8(data, num_bytes); |
| 563 if (Dart_IsError(source)) { | 568 if (Dart_IsError(source)) { |
| 564 result = DartUtils::NewError("%s is not a valid UTF-8 script", | 569 result = DartUtils::NewError("%s is not a valid UTF-8 script", |
| 565 resolved_script_uri); | 570 resolved_script_uri); |
| 566 } else { | 571 } else { |
| 567 if (tag == Dart_kImportTag) { | 572 if (tag == Dart_kImportTag) { |
| 568 result = Dart_LoadLibrary(resolved_script_uri, source, 0, 0); | 573 result = Dart_LoadLibrary(resolved_script_uri, source, 0, 0); |
| 569 } else { | 574 } else { |
| 570 ASSERT(tag == Dart_kSourceTag); | 575 ASSERT(tag == Dart_kSourceTag); |
| 571 Dart_Handle library = Dart_LookupLibrary(library_uri); | 576 Dart_Handle library = Dart_LookupLibrary(library_uri); |
| 572 DART_CHECK_VALID(library); | 577 if (Dart_IsError(library)) { |
| 578 Dart_PropagateError(library); |
| 579 } |
| 573 result = Dart_LoadSource(library, resolved_script_uri, source, 0, 0); | 580 result = Dart_LoadSource(library, resolved_script_uri, source, 0, 0); |
| 574 } | 581 } |
| 575 } | 582 } |
| 576 } | 583 } |
| 577 | 584 |
| 578 if (buffer_copy != NULL) { | 585 if (buffer_copy != NULL) { |
| 579 free(const_cast<uint8_t *>(buffer_copy)); | 586 free(const_cast<uint8_t *>(buffer_copy)); |
| 580 } | 587 } |
| 581 | 588 |
| 582 if (Dart_IsError(result)) { | 589 if (Dart_IsError(result)) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 | 635 |
| 629 Dart_Handle DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, | 636 Dart_Handle DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, |
| 630 Dart_Handle internal_lib, | 637 Dart_Handle internal_lib, |
| 631 bool is_service_isolate, | 638 bool is_service_isolate, |
| 632 bool trace_loading, | 639 bool trace_loading, |
| 633 const char* package_root, | 640 const char* package_root, |
| 634 const char* packages_file) { | 641 const char* packages_file) { |
| 635 // Setup the internal library's 'internalPrint' function. | 642 // Setup the internal library's 'internalPrint' function. |
| 636 Dart_Handle print = Dart_Invoke( | 643 Dart_Handle print = Dart_Invoke( |
| 637 builtin_lib, NewString("_getPrintClosure"), 0, NULL); | 644 builtin_lib, NewString("_getPrintClosure"), 0, NULL); |
| 638 DART_CHECK_VALID(print); | 645 RETURN_IF_ERROR(print); |
| 639 Dart_Handle result = | 646 Dart_Handle result = |
| 640 Dart_SetField(internal_lib, NewString("_printClosure"), print); | 647 Dart_SetField(internal_lib, NewString("_printClosure"), print); |
| 641 DART_CHECK_VALID(result); | 648 RETURN_IF_ERROR(result); |
| 642 | 649 |
| 643 if (!is_service_isolate) { | 650 if (!is_service_isolate) { |
| 644 if (IsWindowsHost()) { | 651 if (IsWindowsHost()) { |
| 645 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); | 652 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); |
| 646 DART_CHECK_VALID(result); | 653 RETURN_IF_ERROR(result); |
| 647 } | 654 } |
| 648 if (trace_loading) { | 655 if (trace_loading) { |
| 649 result = Dart_SetField(builtin_lib, | 656 result = Dart_SetField(builtin_lib, |
| 650 NewString("_traceLoading"), Dart_True()); | 657 NewString("_traceLoading"), Dart_True()); |
| 651 DART_CHECK_VALID(result); | 658 RETURN_IF_ERROR(result); |
| 652 } | 659 } |
| 653 // Set current working directory. | 660 // Set current working directory. |
| 654 result = SetWorkingDirectory(builtin_lib); | 661 result = SetWorkingDirectory(builtin_lib); |
| 655 DART_CHECK_VALID(result); | 662 RETURN_IF_ERROR(result); |
| 656 // Wait for the service isolate to initialize the load port. | 663 // Wait for the service isolate to initialize the load port. |
| 657 Dart_Port load_port = Dart_ServiceWaitForLoadPort(); | 664 Dart_Port load_port = Dart_ServiceWaitForLoadPort(); |
| 658 if (load_port == ILLEGAL_PORT) { | 665 if (load_port == ILLEGAL_PORT) { |
| 659 return NewDartUnsupportedError("Service did not return load port."); | 666 return NewDartUnsupportedError("Service did not return load port."); |
| 660 } | 667 } |
| 661 Builtin::SetLoadPort(load_port); | 668 result = Builtin::SetLoadPort(load_port); |
| 669 RETURN_IF_ERROR(result); |
| 662 } | 670 } |
| 663 | 671 |
| 664 // Set up package root if specified. | 672 // Set up package root if specified. |
| 665 if (package_root != NULL) { | 673 if (package_root != NULL) { |
| 666 ASSERT(packages_file == NULL); | 674 ASSERT(packages_file == NULL); |
| 667 result = NewString(package_root); | 675 result = NewString(package_root); |
| 668 DART_CHECK_VALID(result); | 676 RETURN_IF_ERROR(result); |
| 669 const int kNumArgs = 1; | 677 const int kNumArgs = 1; |
| 670 Dart_Handle dart_args[kNumArgs]; | 678 Dart_Handle dart_args[kNumArgs]; |
| 671 dart_args[0] = result; | 679 dart_args[0] = result; |
| 672 result = Dart_Invoke(builtin_lib, | 680 result = Dart_Invoke(builtin_lib, |
| 673 NewString("_setPackageRoot"), | 681 NewString("_setPackageRoot"), |
| 674 kNumArgs, | 682 kNumArgs, |
| 675 dart_args); | 683 dart_args); |
| 676 DART_CHECK_VALID(result); | 684 RETURN_IF_ERROR(result); |
| 677 } else if (packages_file != NULL) { | 685 } else if (packages_file != NULL) { |
| 678 result = NewString(packages_file); | 686 result = NewString(packages_file); |
| 679 DART_CHECK_VALID(result); | 687 RETURN_IF_ERROR(result); |
| 680 const int kNumArgs = 1; | 688 const int kNumArgs = 1; |
| 681 Dart_Handle dart_args[kNumArgs]; | 689 Dart_Handle dart_args[kNumArgs]; |
| 682 dart_args[0] = result; | 690 dart_args[0] = result; |
| 683 result = Dart_Invoke(builtin_lib, | 691 result = Dart_Invoke(builtin_lib, |
| 684 NewString("_loadPackagesMap"), | 692 NewString("_loadPackagesMap"), |
| 685 kNumArgs, | 693 kNumArgs, |
| 686 dart_args); | 694 dart_args); |
| 687 DART_CHECK_VALID(result); | 695 RETURN_IF_ERROR(result); |
| 688 } | 696 } |
| 689 return Dart_True(); | 697 return Dart_True(); |
| 690 } | 698 } |
| 691 | 699 |
| 692 | 700 |
| 693 void DartUtils::PrepareCoreLibrary(Dart_Handle core_lib, | 701 Dart_Handle DartUtils::PrepareCoreLibrary(Dart_Handle core_lib, |
| 694 Dart_Handle builtin_lib, | 702 Dart_Handle builtin_lib, |
| 695 bool is_service_isolate) { | 703 bool is_service_isolate) { |
| 696 if (!is_service_isolate) { | 704 if (!is_service_isolate) { |
| 697 // Setup the 'Uri.base' getter in dart:core. | 705 // Setup the 'Uri.base' getter in dart:core. |
| 698 Dart_Handle uri_base = Dart_Invoke( | 706 Dart_Handle uri_base = Dart_Invoke( |
| 699 builtin_lib, NewString("_getUriBaseClosure"), 0, NULL); | 707 builtin_lib, NewString("_getUriBaseClosure"), 0, NULL); |
| 700 DART_CHECK_VALID(uri_base); | 708 RETURN_IF_ERROR(uri_base); |
| 701 Dart_Handle result = Dart_SetField(core_lib, | 709 Dart_Handle result = Dart_SetField(core_lib, |
| 702 NewString("_uriBaseClosure"), | 710 NewString("_uriBaseClosure"), |
| 703 uri_base); | 711 uri_base); |
| 704 DART_CHECK_VALID(result); | 712 RETURN_IF_ERROR(result); |
| 705 } | 713 } |
| 714 return Dart_True(); |
| 706 } | 715 } |
| 707 | 716 |
| 708 | 717 |
| 709 void DartUtils::PrepareAsyncLibrary(Dart_Handle async_lib, | 718 Dart_Handle DartUtils::PrepareAsyncLibrary(Dart_Handle async_lib, |
| 710 Dart_Handle isolate_lib) { | 719 Dart_Handle isolate_lib) { |
| 711 Dart_Handle schedule_immediate_closure = | 720 Dart_Handle schedule_immediate_closure = |
| 712 Dart_Invoke(isolate_lib, NewString("_getIsolateScheduleImmediateClosure"), | 721 Dart_Invoke(isolate_lib, NewString("_getIsolateScheduleImmediateClosure"), |
| 713 0, NULL); | 722 0, NULL); |
| 723 RETURN_IF_ERROR(schedule_immediate_closure); |
| 714 Dart_Handle args[1]; | 724 Dart_Handle args[1]; |
| 715 args[0] = schedule_immediate_closure; | 725 args[0] = schedule_immediate_closure; |
| 716 DART_CHECK_VALID(Dart_Invoke( | 726 return Dart_Invoke( |
| 717 async_lib, NewString("_setScheduleImmediateClosure"), 1, args)); | 727 async_lib, NewString("_setScheduleImmediateClosure"), 1, args); |
| 718 } | 728 } |
| 719 | 729 |
| 720 | 730 |
| 721 void DartUtils::PrepareIOLibrary(Dart_Handle io_lib) { | 731 Dart_Handle DartUtils::PrepareIOLibrary(Dart_Handle io_lib) { |
| 722 DART_CHECK_VALID(Dart_Invoke(io_lib, NewString("_setupHooks"), 0, NULL)); | 732 return Dart_Invoke(io_lib, NewString("_setupHooks"), 0, NULL); |
| 723 } | 733 } |
| 724 | 734 |
| 725 | 735 |
| 726 void DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { | 736 Dart_Handle DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { |
| 727 DART_CHECK_VALID(Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL)); | 737 return Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL); |
| 728 } | 738 } |
| 729 | 739 |
| 730 | 740 |
| 731 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, | 741 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, |
| 732 const char* packages_file, | 742 const char* packages_file, |
| 733 bool is_service_isolate, | 743 bool is_service_isolate, |
| 734 bool trace_loading, | 744 bool trace_loading, |
| 735 Dart_Handle builtin_lib) { | 745 Dart_Handle builtin_lib) { |
| 736 // First ensure all required libraries are available. | 746 // First ensure all required libraries are available. |
| 737 Dart_Handle url = NewString(kCoreLibURL); | 747 Dart_Handle url = NewString(kCoreLibURL); |
| 738 DART_CHECK_VALID(url); | 748 RETURN_IF_ERROR(url); |
| 739 Dart_Handle core_lib = Dart_LookupLibrary(url); | 749 Dart_Handle core_lib = Dart_LookupLibrary(url); |
| 740 DART_CHECK_VALID(core_lib); | 750 RETURN_IF_ERROR(core_lib); |
| 741 url = NewString(kAsyncLibURL); | 751 url = NewString(kAsyncLibURL); |
| 742 DART_CHECK_VALID(url); | 752 RETURN_IF_ERROR(url); |
| 743 Dart_Handle async_lib = Dart_LookupLibrary(url); | 753 Dart_Handle async_lib = Dart_LookupLibrary(url); |
| 744 DART_CHECK_VALID(async_lib); | 754 RETURN_IF_ERROR(async_lib); |
| 745 url = NewString(kIsolateLibURL); | 755 url = NewString(kIsolateLibURL); |
| 746 DART_CHECK_VALID(url); | 756 RETURN_IF_ERROR(url); |
| 747 Dart_Handle isolate_lib = Dart_LookupLibrary(url); | 757 Dart_Handle isolate_lib = Dart_LookupLibrary(url); |
| 748 DART_CHECK_VALID(isolate_lib); | 758 RETURN_IF_ERROR(isolate_lib); |
| 749 url = NewString(kInternalLibURL); | 759 url = NewString(kInternalLibURL); |
| 750 DART_CHECK_VALID(url); | 760 RETURN_IF_ERROR(url); |
| 751 Dart_Handle internal_lib = Dart_LookupLibrary(url); | 761 Dart_Handle internal_lib = Dart_LookupLibrary(url); |
| 752 DART_CHECK_VALID(internal_lib); | 762 RETURN_IF_ERROR(internal_lib); |
| 753 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 763 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
| 754 DART_CHECK_VALID(io_lib); | 764 RETURN_IF_ERROR(io_lib); |
| 755 | 765 |
| 756 // We need to ensure that all the scripts loaded so far are finalized | 766 // We need to ensure that all the scripts loaded so far are finalized |
| 757 // as we are about to invoke some Dart code below to setup closures. | 767 // as we are about to invoke some Dart code below to setup closures. |
| 758 Dart_Handle result = Dart_FinalizeLoading(false); | 768 Dart_Handle result = Dart_FinalizeLoading(false); |
| 759 DART_CHECK_VALID(result); | 769 RETURN_IF_ERROR(result); |
| 760 | 770 |
| 761 result = PrepareBuiltinLibrary(builtin_lib, | 771 result = PrepareBuiltinLibrary(builtin_lib, |
| 762 internal_lib, | 772 internal_lib, |
| 763 is_service_isolate, | 773 is_service_isolate, |
| 764 trace_loading, | 774 trace_loading, |
| 765 package_root, | 775 package_root, |
| 766 packages_file); | 776 packages_file); |
| 767 DART_CHECK_VALID(result); | 777 RETURN_IF_ERROR(result); |
| 768 | 778 |
| 769 PrepareAsyncLibrary(async_lib, isolate_lib); | 779 RETURN_IF_ERROR(PrepareAsyncLibrary(async_lib, isolate_lib)); |
| 770 PrepareCoreLibrary(core_lib, builtin_lib, is_service_isolate); | 780 RETURN_IF_ERROR(PrepareCoreLibrary( |
| 771 PrepareIsolateLibrary(isolate_lib); | 781 core_lib, builtin_lib, is_service_isolate)); |
| 772 PrepareIOLibrary(io_lib); | 782 RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib)); |
| 783 RETURN_IF_ERROR(PrepareIOLibrary(io_lib)); |
| 773 return result; | 784 return result; |
| 774 } | 785 } |
| 775 | 786 |
| 776 | 787 |
| 777 void DartUtils::SetupIOLibrary(const char* script_uri) { | 788 Dart_Handle DartUtils::SetupIOLibrary(const char* script_uri) { |
| 778 Dart_Handle io_lib_url = NewString(kIOLibURL); | 789 Dart_Handle io_lib_url = NewString(kIOLibURL); |
| 779 DART_CHECK_VALID(io_lib_url); | 790 RETURN_IF_ERROR(io_lib_url); |
| 780 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); | 791 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); |
| 781 DART_CHECK_VALID(io_lib); | 792 RETURN_IF_ERROR(io_lib); |
| 782 Dart_Handle platform_type = GetDartType(DartUtils::kIOLibURL, "_Platform"); | 793 Dart_Handle platform_type = GetDartType(DartUtils::kIOLibURL, "_Platform"); |
| 783 DART_CHECK_VALID(platform_type); | 794 RETURN_IF_ERROR(platform_type); |
| 784 Dart_Handle script_name = NewString("_nativeScript"); | 795 Dart_Handle script_name = NewString("_nativeScript"); |
| 785 DART_CHECK_VALID(script_name); | 796 RETURN_IF_ERROR(script_name); |
| 786 Dart_Handle dart_script = NewString(script_uri); | 797 Dart_Handle dart_script = NewString(script_uri); |
| 787 DART_CHECK_VALID(dart_script); | 798 RETURN_IF_ERROR(dart_script); |
| 788 Dart_Handle set_script_name = | 799 Dart_Handle set_script_name = |
| 789 Dart_SetField(platform_type, script_name, dart_script); | 800 Dart_SetField(platform_type, script_name, dart_script); |
| 790 DART_CHECK_VALID(set_script_name); | 801 RETURN_IF_ERROR(set_script_name); |
| 802 return Dart_Null(); |
| 791 } | 803 } |
| 792 | 804 |
| 793 | 805 |
| 794 bool DartUtils::PostNull(Dart_Port port_id) { | 806 bool DartUtils::PostNull(Dart_Port port_id) { |
| 795 // Post a message with just the null object. | 807 // Post a message with just the null object. |
| 796 return Dart_PostCObject(port_id, CObject::Null()->AsApiCObject()); | 808 return Dart_PostCObject(port_id, CObject::Null()->AsApiCObject()); |
| 797 } | 809 } |
| 798 | 810 |
| 799 | 811 |
| 800 bool DartUtils::PostInt32(Dart_Port port_id, int32_t value) { | 812 bool DartUtils::PostInt32(Dart_Port port_id, int32_t value) { |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 new CObjectString(CObject::NewString(os_error->message())); | 1241 new CObjectString(CObject::NewString(os_error->message())); |
| 1230 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1242 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 1231 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1243 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 1232 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1244 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 1233 result->SetAt(2, error_message); | 1245 result->SetAt(2, error_message); |
| 1234 return result; | 1246 return result; |
| 1235 } | 1247 } |
| 1236 | 1248 |
| 1237 } // namespace bin | 1249 } // namespace bin |
| 1238 } // namespace dart | 1250 } // namespace dart |
| OLD | NEW |