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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "include/dart_debugger_api.h" 5 #include "include/dart_debugger_api.h"
6 6
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/dart_api_state.h" 8 #include "vm/dart_api_state.h"
9 #include "vm/debugger.h" 9 #include "vm/debugger.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
11 #include "vm/longjump.h" 11 #include "vm/longjump.h"
12 #include "vm/object_store.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
15 #define UNWRAP_AND_CHECK_PARAM(type, var, param) \ 16 #define UNWRAP_AND_CHECK_PARAM(type, var, param) \
16 do { \ 17 do { \
17 const Object& tmp = Object::Handle(Api::UnwrapHandle(param)); \ 18 const Object& tmp = Object::Handle(Api::UnwrapHandle(param)); \
18 if (tmp.IsNull()) { \ 19 if (tmp.IsNull()) { \
19 return Api::NewError("%s expects argument '%s' to be non-null.", \ 20 return Api::NewError("%s expects argument '%s' to be non-null.", \
20 CURRENT_FUNC, #param); \ 21 CURRENT_FUNC, #param); \
21 } else if (tmp.IsApiError()) { \ 22 } else if (tmp.IsApiError()) { \
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 DART_EXPORT Dart_Handle Dart_DeleteBreakpoint( 213 DART_EXPORT Dart_Handle Dart_DeleteBreakpoint(
213 Dart_Breakpoint breakpoint_in) { 214 Dart_Breakpoint breakpoint_in) {
214 Isolate* isolate = Isolate::Current(); 215 Isolate* isolate = Isolate::Current();
215 DARTSCOPE(isolate); 216 DARTSCOPE(isolate);
216 217
217 CHECK_AND_CAST(Breakpoint, breakpoint, breakpoint_in); 218 CHECK_AND_CAST(Breakpoint, breakpoint, breakpoint_in);
218 isolate->debugger()->RemoveBreakpoint(breakpoint); 219 isolate->debugger()->RemoveBreakpoint(breakpoint);
219 return Api::True(); 220 return Api::True();
220 } 221 }
221 222
223
224 DART_EXPORT Dart_Handle Dart_GetScriptSource(
225 Dart_Handle library_url_in,
226 Dart_Handle script_url_in) {
227 Isolate* isolate = Isolate::Current();
228 DARTSCOPE(isolate);
229 String& library_url = String::Handle();
230 UNWRAP_AND_CHECK_PARAM(String, library_url, library_url_in);
231 String& script_url = String::Handle();
232 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in);
233
234 const Library& library = Library::Handle(Library::LookupLibrary(library_url));
235 if (library.IsNull()) {
236 return Api::NewError("%s: library '%s' not found",
237 CURRENT_FUNC, library_url.ToCString());
238 }
239
240 const Script& script = Script::Handle(library.LookupScript(script_url));
241 if (script.IsNull()) {
242 return Api::NewError("%s: script '%s' not found in library '%s'",
243 CURRENT_FUNC, script_url.ToCString(),
244 library_url.ToCString());
245 }
246
247 const String& source = String::Handle(script.source());
248 return Api::NewLocalHandle(source);
249 }
250
251
252 DART_EXPORT Dart_Handle Dart_GetScriptURLs(Dart_Handle library_url_in) {
253 Isolate* isolate = Isolate::Current();
254 DARTSCOPE(isolate);
255 String& library_url = String::Handle();
256 UNWRAP_AND_CHECK_PARAM(String, library_url, library_url_in);
257
258 const Library& library = Library::Handle(Library::LookupLibrary(library_url));
259 if (library.IsNull()) {
260 return Api::NewError("%s: library '%s' not found",
261 CURRENT_FUNC, library_url.ToCString());
262 }
263 const Array& loaded_scripts = Array::Handle(library.LoadedScripts());
264 ASSERT(!loaded_scripts.IsNull());
265 Dart_Handle script_list = Dart_NewList(loaded_scripts.Length());
266 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.
267 Script& script = Script::Handle();
268 for (int i = 0; i < num_scripts; i++) {
269 script ^= loaded_scripts.At(i);
270 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.
271 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.
272 }
273 return script_list;
274 }
275
276
277 DART_EXPORT Dart_Handle Dart_GetLibraryURLs() {
278 Isolate* isolate = Isolate::Current();
279 ASSERT(isolate != NULL);
280 DARTSCOPE(isolate);
281
282 // Find out how many libraries are loaded in this isolate.
283 int num_libs = 0;
284 Library &lib = Library::Handle();
285 lib = isolate->object_store()->registered_libraries();
286 while (!lib.IsNull()) {
287 num_libs++;
288 lib = lib.next_registered();
289 }
290
291 // Create new list and populate with the url of loaded libraries.
292 Dart_Handle library_list = Dart_NewList(num_libs);
293 lib = isolate->object_store()->registered_libraries();
294 for (int i = 0; i < num_libs; i++) {
295 ASSERT(!lib.IsNull());
296 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.
297 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.
298 lib = lib.next_registered();
299 }
300 return library_list;
301 }
302
222 } // namespace dart 303 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698