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

Side by Side Diff: runtime/bin/dartutils.cc

Issue 328923002: Lazy loading of deferred libraries (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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 | « runtime/bin/builtin_sources.gypi ('k') | runtime/lib/lib_prefix.dart » ('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 "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_native_api.h" 8 #include "include/dart_native_api.h"
9 9
10 #include "platform/assert.h" 10 #include "platform/assert.h"
11 #include "platform/globals.h" 11 #include "platform/globals.h"
12 12
13 #include "bin/crypto.h" 13 #include "bin/crypto.h"
14 #include "bin/directory.h" 14 #include "bin/directory.h"
15 #include "bin/extensions.h" 15 #include "bin/extensions.h"
16 #include "bin/file.h" 16 #include "bin/file.h"
17 #include "bin/io_buffer.h" 17 #include "bin/io_buffer.h"
18 #include "bin/socket.h" 18 #include "bin/socket.h"
19 #include "bin/utils.h" 19 #include "bin/utils.h"
20 20
21 namespace dart { 21 namespace dart {
22 namespace bin { 22 namespace bin {
23 23
24 const char* DartUtils::original_working_directory = NULL; 24 const char* DartUtils::original_working_directory = NULL;
25 const char* DartUtils::kDartScheme = "dart:"; 25 const char* DartUtils::kDartScheme = "dart:";
26 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; 26 const char* DartUtils::kDartExtensionScheme = "dart-ext:";
27 const char* DartUtils::kAsyncLibURL = "dart:async"; 27 const char* DartUtils::kAsyncLibURL = "dart:async";
28 const char* DartUtils::kBuiltinLibURL = "dart:builtin"; 28 const char* DartUtils::kBuiltinLibURL = "dart:_builtin";
29 const char* DartUtils::kCoreLibURL = "dart:core"; 29 const char* DartUtils::kCoreLibURL = "dart:core";
30 const char* DartUtils::kInternalLibURL = "dart:_internal"; 30 const char* DartUtils::kInternalLibURL = "dart:_internal";
31 const char* DartUtils::kIsolateLibURL = "dart:isolate"; 31 const char* DartUtils::kIsolateLibURL = "dart:isolate";
32 const char* DartUtils::kIOLibURL = "dart:io"; 32 const char* DartUtils::kIOLibURL = "dart:io";
33 const char* DartUtils::kIOLibPatchURL = "dart:io-patch"; 33 const char* DartUtils::kIOLibPatchURL = "dart:io-patch";
34 const char* DartUtils::kUriLibURL = "dart:uri"; 34 const char* DartUtils::kUriLibURL = "dart:uri";
35 const char* DartUtils::kHttpScheme = "http:"; 35 const char* DartUtils::kHttpScheme = "http:";
36 const char* DartUtils::kVMServiceLibURL = "dart:vmservice"; 36 const char* DartUtils::kVMServiceLibURL = "dart:vmservice";
37 37
38 uint8_t DartUtils::magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc }; 38 uint8_t DartUtils::magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc };
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 672
673 673
674 // Callback function that gets called from asynchronous script loading code 674 // Callback function that gets called from asynchronous script loading code
675 // when the data has been read. Loads the script or snapshot into the VM. 675 // when the data has been read. Loads the script or snapshot into the VM.
676 void FUNCTION_NAME(Builtin_LoadScript)(Dart_NativeArguments args) { 676 void FUNCTION_NAME(Builtin_LoadScript)(Dart_NativeArguments args) {
677 Dart_Handle resolved_script_uri = Dart_GetNativeArgument(args, 0); 677 Dart_Handle resolved_script_uri = Dart_GetNativeArgument(args, 0);
678 Dart_Handle data = Dart_GetNativeArgument(args, 1); 678 Dart_Handle data = Dart_GetNativeArgument(args, 1);
679 679
680 intptr_t num_bytes = 0; 680 intptr_t num_bytes = 0;
681 Dart_Handle result = Dart_ListLength(data, &num_bytes); 681 Dart_Handle result = Dart_ListLength(data, &num_bytes);
682 DART_CHECK_VALID(result); 682 if (Dart_IsError(result)) {
683 Dart_PropagateError(result);
684 }
683 685
684 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(num_bytes)); 686 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(num_bytes));
685 Dart_ListGetAsBytes(data, 0, buffer, num_bytes); 687 Dart_ListGetAsBytes(data, 0, buffer, num_bytes);
686 688
687 bool is_snapshot = false; 689 bool is_snapshot = false;
688 const uint8_t *payload = 690 const uint8_t *payload =
689 DartUtils::SniffForMagicNumber(buffer, &num_bytes, &is_snapshot); 691 DartUtils::SniffForMagicNumber(buffer, &num_bytes, &is_snapshot);
690 692
691 if (is_snapshot) { 693 if (is_snapshot) {
692 result = Dart_LoadScriptFromSnapshot(payload, num_bytes); 694 result = Dart_LoadScriptFromSnapshot(payload, num_bytes);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 } else { 734 } else {
733 ASSERT(tag == Dart_kSourceTag); 735 ASSERT(tag == Dart_kSourceTag);
734 Dart_Handle library = Dart_LookupLibrary(library_uri); 736 Dart_Handle library = Dart_LookupLibrary(library_uri);
735 DART_CHECK_VALID(library); 737 DART_CHECK_VALID(library);
736 result = Dart_LoadSource(library, resolved_script_uri, sourceText); 738 result = Dart_LoadSource(library, resolved_script_uri, sourceText);
737 } 739 }
738 if (Dart_IsError(result)) Dart_PropagateError(result); 740 if (Dart_IsError(result)) Dart_PropagateError(result);
739 } 741 }
740 742
741 743
744 // Callback function that gets called from dartutils when there are
745 // no more outstanding load requests. Invoke Dart core library function
746 // that completes futures of loadLibrary calls (deferred library loading).
747 // Invoking this function finalizes newly loaded classes as a side
748 // effect.
749 void FUNCTION_NAME(Builtin_DoneLoading)(Dart_NativeArguments args) {
750 Dart_Handle corelib_url = DartUtils::NewString(DartUtils::kCoreLibURL);
751 DART_CHECK_VALID(corelib_url);
752 Dart_Handle corelib = Dart_LookupLibrary(corelib_url);
753 DART_CHECK_VALID(corelib);
754 Dart_Handle res =
755 Dart_Invoke(corelib,
756 DartUtils::NewString("_completeDeferredLoads"),
757 0,
758 NULL);
759 if (Dart_IsError(res)) {
760 Dart_PropagateError(res);
761 }
762 }
763
764
742 Dart_Handle DartUtils::LoadSource(Dart_Handle library, 765 Dart_Handle DartUtils::LoadSource(Dart_Handle library,
743 Dart_Handle url, 766 Dart_Handle url,
744 Dart_LibraryTag tag, 767 Dart_LibraryTag tag,
745 const char* url_string) { 768 const char* url_string) {
746 bool is_http_scheme_url = DartUtils::IsHttpSchemeURL(url_string); 769 bool is_http_scheme_url = DartUtils::IsHttpSchemeURL(url_string);
747 Dart_Handle source; 770 Dart_Handle source;
748 if (is_http_scheme_url) { 771 if (is_http_scheme_url) {
749 // Read the file over http. 772 // Read the file over http.
750 source = DartUtils::ReadStringFromHttp(url_string); 773 source = DartUtils::ReadStringFromHttp(url_string);
751 } else { 774 } else {
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 new CObjectString(CObject::NewString(os_error->message())); 1164 new CObjectString(CObject::NewString(os_error->message()));
1142 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 1165 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
1143 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 1166 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
1144 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 1167 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
1145 result->SetAt(2, error_message); 1168 result->SetAt(2, error_message);
1146 return result; 1169 return result;
1147 } 1170 }
1148 1171
1149 } // namespace bin 1172 } // namespace bin
1150 } // namespace dart 1173 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/builtin_sources.gypi ('k') | runtime/lib/lib_prefix.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698