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

Unified Diff: runtime/vm/debugger_api_impl.cc

Issue 9117015: Add functions to list library and script urls in an isolate. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/debugger_api_impl.cc
===================================================================
--- runtime/vm/debugger_api_impl.cc (revision 3502)
+++ runtime/vm/debugger_api_impl.cc (working copy)
@@ -9,6 +9,7 @@
#include "vm/debugger.h"
#include "vm/isolate.h"
#include "vm/longjump.h"
+#include "vm/object_store.h"
namespace dart {
@@ -219,4 +220,84 @@
return Api::True();
}
+
+DART_EXPORT Dart_Handle Dart_GetScriptSource(
+ Dart_Handle library_url_in,
+ Dart_Handle script_url_in) {
+ Isolate* isolate = Isolate::Current();
+ DARTSCOPE(isolate);
+ String& library_url = String::Handle();
+ UNWRAP_AND_CHECK_PARAM(String, library_url, library_url_in);
+ String& script_url = String::Handle();
+ UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in);
+
+ const Library& library = Library::Handle(Library::LookupLibrary(library_url));
+ if (library.IsNull()) {
+ return Api::NewError("%s: library '%s' not found",
+ CURRENT_FUNC, library_url.ToCString());
+ }
+
+ const Script& script = Script::Handle(library.LookupScript(script_url));
+ if (script.IsNull()) {
+ return Api::NewError("%s: script '%s' not found in library '%s'",
+ CURRENT_FUNC, script_url.ToCString(),
+ library_url.ToCString());
+ }
+
+ const String& source = String::Handle(script.source());
+ return Api::NewLocalHandle(source);
+}
+
+
+DART_EXPORT Dart_Handle Dart_GetScriptURLs(Dart_Handle library_url_in) {
+ Isolate* isolate = Isolate::Current();
+ DARTSCOPE(isolate);
+ String& library_url = String::Handle();
+ UNWRAP_AND_CHECK_PARAM(String, library_url, library_url_in);
+
+ const Library& library = Library::Handle(Library::LookupLibrary(library_url));
+ if (library.IsNull()) {
+ return Api::NewError("%s: library '%s' not found",
+ CURRENT_FUNC, library_url.ToCString());
+ }
+ const Array& loaded_scripts = Array::Handle(library.LoadedScripts());
+ ASSERT(!loaded_scripts.IsNull());
+ Dart_Handle script_list = Dart_NewList(loaded_scripts.Length());
+ intptr_t num_scripts = loaded_scripts.Length();
siva 2012/01/24 18:37:14 Move this line up and using num_scripts for creati
hausner 2012/01/24 21:34:42 Done.
+ Script& script = Script::Handle();
+ for (int i = 0; i < num_scripts; i++) {
+ script ^= loaded_scripts.At(i);
+ const String& url = String::Handle(script.url());
siva 2012/01/24 18:37:14 This handle could be allocated outside the loop.
hausner 2012/01/24 21:34:42 Ah yes.
+ Dart_ListSetAt(script_list, i, Api::NewLocalHandle(url));
siva 2012/01/24 18:37:14 Do we have to create the List using the API functi
hausner 2012/01/24 21:34:42 Seems to work. Good tip.
+ }
+ return script_list;
+}
+
+
+DART_EXPORT Dart_Handle Dart_GetLibraryURLs() {
+ Isolate* isolate = Isolate::Current();
+ ASSERT(isolate != NULL);
+ DARTSCOPE(isolate);
+
+ // Find out how many libraries are loaded in this isolate.
+ int num_libs = 0;
+ Library &lib = Library::Handle();
+ lib = isolate->object_store()->registered_libraries();
+ while (!lib.IsNull()) {
+ num_libs++;
+ lib = lib.next_registered();
+ }
+
+ // Create new list and populate with the url of loaded libraries.
+ Dart_Handle library_list = Dart_NewList(num_libs);
+ lib = isolate->object_store()->registered_libraries();
+ for (int i = 0; i < num_libs; i++) {
+ ASSERT(!lib.IsNull());
+ const String& lib_url = String::Handle(lib.url());
siva 2012/01/24 18:37:14 This handle could be created outside the loop?
hausner 2012/01/24 21:34:42 Done.
+ Dart_ListSetAt(library_list, i, Api::NewLocalHandle(lib_url));
siva 2012/01/24 18:37:14 Ditto comment about creating the list using API fu
hausner 2012/01/24 21:34:42 Done.
+ lib = lib.next_registered();
+ }
+ return library_list;
+}
+
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698