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

Unified Diff: runtime/vm/object.cc

Issue 392933003: vm/observatory: Clean up script access (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/report_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 0bcaa9ec8ba5aa9ea8d11e8f03889e5a40688c62..1363214ee7fd611034b66a389dfc533c17197c2f 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -8305,6 +8305,25 @@ const char* Script::ToCString() const {
}
+RawLibrary* Script::FindLibrary() const {
+ Isolate* isolate = Isolate::Current();
+ const GrowableObjectArray& libs = GrowableObjectArray::Handle(
+ isolate, isolate->object_store()->libraries());
+ Library& lib = Library::Handle();
+ Array& scripts = Array::Handle();
+ for (intptr_t i = 0; i < libs.Length(); i++) {
+ lib ^= libs.At(i);
+ scripts = lib.LoadedScripts();
+ for (intptr_t j = 0; j < scripts.Length(); j++) {
+ if (scripts.At(j) == raw()) {
+ return lib.raw();
+ }
+ }
+ }
+ return Library::null();
+}
+
+
// See also Dart_ScriptGetTokenInfo.
void Script::PrintJSONImpl(JSONStream* stream, bool ref) const {
JSONObject jsobj(stream);
@@ -8313,13 +8332,17 @@ void Script::PrintJSONImpl(JSONStream* stream, bool ref) const {
ASSERT(!name.IsNull());
const String& encoded_url = String::Handle(String::EncodeURI(name));
ASSERT(!encoded_url.IsNull());
- jsobj.AddPropertyF("id", "scripts/%s", encoded_url.ToCString());
+ const Library& lib = Library::Handle(FindLibrary());
+ intptr_t lib_index = (lib.IsNull()) ? -1 : lib.index();
+ jsobj.AddPropertyF("id", "libraries/%" Pd "/scripts/%s",
+ lib_index, encoded_url.ToCString());
jsobj.AddProperty("name", name.ToCString());
jsobj.AddProperty("user_name", name.ToCString());
jsobj.AddProperty("kind", GetKindAsCString());
if (ref) {
return;
}
+ jsobj.AddProperty("owning_library", lib);
const String& source = String::Handle(Source());
jsobj.AddProperty("source", source.ToCString());
@@ -8903,6 +8926,25 @@ RawArray* Library::LoadedScripts() const {
AddScriptIfUnique(scripts, owner_script);
}
+ // Special case: Scripts that only contain external top-level functions are
+ // not included above, but can be referenced through a library's anonymous
+ // classes. Example: dart-core:identical.dart.
+ Array& anon_classes = Array::Handle(anonymous_classes());
+ Function& func = Function::Handle();
+ Array& functions = Array::Handle();
+ for (intptr_t i = 0; i < anon_classes.Length(); i++) {
+ cls ^= anon_classes.At(i);
+ if (cls.IsNull()) continue;
+ owner_script = cls.script();
+ AddScriptIfUnique(scripts, owner_script);
+ functions = cls.functions();
+ for (intptr_t j = 0; j < functions.Length(); j++) {
+ func ^= functions.At(j);
+ owner_script = func.script();
+ AddScriptIfUnique(scripts, owner_script);
+ }
+ }
+
// Create the array of scripts and cache it in loaded_scripts_.
const Array& scripts_array = Array::Handle(Array::MakeArray(scripts));
StorePointer(&raw_ptr()->loaded_scripts_, scripts_array.raw());
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/report_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698