diff --git a/runtime/bin/gen_snapshot.cc b/runtime/bin/gen_snapshot.cc index 80df47dc613..4c00a150592 100644 --- a/runtime/bin/gen_snapshot.cc +++ b/runtime/bin/gen_snapshot.cc @@ -741,15 +741,11 @@ static void SetupStubNativeResolver(size_t lib_index, // run after |SetupStubNativeResolversForPrecompilation| because the former // loads some libraries. static void SetupStubNativeResolvers() { - Dart_Handle library_ids = Dart_GetLibraryIds(); - intptr_t library_ids_length; - Dart_ListLength(library_ids, &library_ids_length); - for (intptr_t i = 0; i < library_ids_length; i++) { - Dart_Handle library_id_handle = Dart_ListGetAt(library_ids, i); - DART_CHECK_VALID(library_id_handle); - int64_t library_id; - Dart_IntegerToInt64(library_id_handle, &library_id); - Dart_Handle library = Dart_GetLibraryFromId(library_id); + Dart_Handle libraries = Dart_GetLoadedLibraries(); + intptr_t libraries_length; + Dart_ListLength(libraries, &libraries_length); + for (intptr_t i = 0; i < libraries_length; i++) { + Dart_Handle library = Dart_ListGetAt(libraries, i); DART_CHECK_VALID(library); Dart_NativeEntryResolver old_resolver = NULL; Dart_GetNativeResolver(library, &old_resolver); diff --git a/runtime/include/dart_api.h b/runtime/include/dart_api.h index 84b3afadf91..ed19c9e2d4e 100644 --- a/runtime/include/dart_api.h +++ b/runtime/include/dart_api.h @@ -2931,6 +2931,13 @@ DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, */ DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library); + +/** + * \return An array of libraries. + */ +DART_EXPORT Dart_Handle Dart_GetLoadedLibraries(); + + DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url); /* TODO(turnidge): Consider returning Dart_Null() when the library is * not found to distinguish that from a true error case. */ diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index 9f4c9468e63..29f2b025f22 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -5514,6 +5514,26 @@ DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { } +DART_EXPORT Dart_Handle Dart_GetLoadedLibraries() { + DARTSCOPE(Thread::Current()); + Isolate* I = T->isolate(); + + const GrowableObjectArray& libs = + GrowableObjectArray::Handle(Z, I->object_store()->libraries()); + int num_libs = libs.Length(); + + // Create new list and populate with the loaded libraries. + Library& lib = Library::Handle(); + const Array& library_list = Array::Handle(Z, Array::New(num_libs)); + for (int i = 0; i < num_libs; i++) { + lib ^= libs.At(i); + ASSERT(!lib.IsNull()); + library_list.SetAt(i, lib); + } + return Api::NewHandle(T, library_list.raw()); +} + + DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { DARTSCOPE(Thread::Current()); const String& url_str = Api::UnwrapStringHandle(Z, url);