Index: runtime/bin/loader.cc |
diff --git a/runtime/bin/loader.cc b/runtime/bin/loader.cc |
index 70ee44471d6628f2a7a1892515fe274d6a771c2b..f83081d71e91b0ba8b80497fd5eb68940306412f 100644 |
--- a/runtime/bin/loader.cc |
+++ b/runtime/bin/loader.cc |
@@ -20,6 +20,7 @@ namespace bin { |
static bool trace_loader = false; |
// Keep in sync with loader.dart. |
static const intptr_t _Dart_kImportExtension = 9; |
+static const intptr_t _Dart_kResolveAsFilePath = 10; |
Loader::Loader(IsolateData* isolate_data) |
: port_(ILLEGAL_PORT), |
@@ -424,7 +425,7 @@ bool Loader::ProcessResultLocked(Loader* loader, Loader::IOResult* result) { |
} |
-bool Loader::ProcessUrlLoadResultLocked(Loader* loader, |
+bool Loader::ProcessPayloadResultLocked(Loader* loader, |
Loader::IOResult* result) { |
// A negative result tag indicates a loading error occurred in the service |
// isolate. The payload is a C string of the error message. |
@@ -537,7 +538,50 @@ Dart_Handle Loader::LoadUrlContents(Dart_Handle url, |
loader->SendRequest(Dart_kScriptTag, url, Dart_Null()); |
// Wait for a reply to the load request. |
- loader->BlockUntilComplete(ProcessUrlLoadResultLocked); |
+ loader->BlockUntilComplete(ProcessPayloadResultLocked); |
+ |
+ // Copy fields from the loader before deleting it. |
+ // The payload array itself which was malloced above is freed by |
+ // the caller of LoadUrlContents. |
+ Dart_Handle error = loader->error(); |
+ *payload = loader->payload_; |
+ *payload_length = loader->payload_length_; |
+ |
+ // Destroy the loader. The destructor does a bunch of leg work. |
+ delete loader; |
+ |
+ // An error occurred during loading. |
+ if (!Dart_IsNull(error)) { |
+ return error; |
+ } |
+ return Dart_Null(); |
+} |
+ |
+ |
+Dart_Handle Loader::ResolveAsFilePath(Dart_Handle url, |
+ uint8_t** payload, |
+ intptr_t* payload_length) { |
+ IsolateData* isolate_data = |
+ reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
+ ASSERT(isolate_data != NULL); |
+ ASSERT(!isolate_data->HasLoader()); |
+ Loader* loader = NULL; |
+ |
+ // Setup the loader. The constructor does a bunch of leg work. |
+ loader = new Loader(isolate_data); |
+ loader->Init(isolate_data->package_root, isolate_data->packages_file, |
+ DartUtils::original_working_directory, NULL); |
+ ASSERT(loader != NULL); |
+ ASSERT(isolate_data->HasLoader()); |
+ |
+ // Now send a load request to the service isolate. |
+ // TODO(28863) The use of tags that aren't declared in dart_api.h's enum |
+ // is undefined behavior. |
+ Dart_LibraryTag tag = static_cast<Dart_LibraryTag>(_Dart_kResolveAsFilePath); |
+ loader->SendRequest(tag, url, Dart_Null()); |
+ |
+ // Wait for a reply to the load request. |
+ loader->BlockUntilComplete(ProcessPayloadResultLocked); |
// Copy fields from the loader before deleting it. |
// The payload array itself which was malloced above is freed by |