[vm] Fix resolution of native extensions imported within packages.

We need to use the actual file URL of the importing library to find the extension library,
such as "file:///library/lib.dart" rather than the package URL (like "package:library/lib.dart").


Change-Id: I32a36f7a67321f356c9af34d1a458aeb122d0c24
Reviewed-on: https://dart-review.googlesource.com/71167
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
This commit is contained in:
Samir Jindel
2018-08-22 17:45:34 +00:00
committed by commit-bot@chromium.org
parent 5b9a42de29
commit 7e358186ab
3 changed files with 31 additions and 4 deletions
+9 -3
View File
@@ -682,12 +682,15 @@ Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag,
const char* path = DartUtils::RemoveScheme(url_string);
const char* lib_uri = NULL;
result = Dart_StringToCString(Dart_LibraryUrl(library), &lib_uri);
result = Dart_StringToCString(Dart_LibraryResolvedUrl(library), &lib_uri);
RETURN_ERROR(result);
UriDecoder decoder(lib_uri);
lib_uri = decoder.decoded();
char* lib_path = NULL;
if (strncmp(lib_uri, "file://", 7) == 0) {
lib_path = DartUtils::DirName(DartUtils::RemoveScheme(lib_uri));
lib_path = DartUtils::DirName(lib_uri + 7);
} else {
lib_path = strdup(lib_uri);
}
@@ -699,7 +702,10 @@ Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag,
path);
}
return Extensions::LoadExtension(lib_path, path, library);
Dart_Handle result =
Extensions::LoadExtension(decoder.decoded(), path, library);
free(lib_path);
return result;
}
if (tag != Dart_kScriptTag) {
// Special case for handling dart: imports and parts.
+7 -1
View File
@@ -3053,10 +3053,16 @@ DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library,
* of it are removed from the embedder code. */
/**
* Returns the url from which a library was loaded.
* Returns an import path to a Library, such as "file:///test.dart" or
* "dart:core".
*/
DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library);
/**
* Returns a URL from which a Library was loaded.
*/
DART_EXPORT Dart_Handle Dart_LibraryResolvedUrl(Dart_Handle library);
/**
* \return An array of libraries.
*/
+15
View File
@@ -5301,6 +5301,21 @@ DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) {
return Api::NewHandle(T, url.raw());
}
DART_EXPORT Dart_Handle Dart_LibraryResolvedUrl(Dart_Handle library) {
DARTSCOPE(Thread::Current());
const Library& lib = Api::UnwrapLibraryHandle(Z, library);
if (lib.IsNull()) {
RETURN_TYPE_ERROR(Z, library, Library);
}
const Class& toplevel = Class::Handle(lib.toplevel_class());
ASSERT(!toplevel.IsNull());
const Script& script = Script::Handle(toplevel.script());
ASSERT(!script.IsNull());
const String& url = String::Handle(script.resolved_url());
ASSERT(!url.IsNull());
return Api::NewHandle(T, url.raw());
}
DART_EXPORT Dart_Handle Dart_GetLoadedLibraries() {
DARTSCOPE(Thread::Current());
Isolate* I = T->isolate();