Index: runtime/vm/object.cc |
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
index 0bcaa9ec8ba5aa9ea8d11e8f03889e5a40688c62..1f6a7b2dfbfffe1a77caa5993498d0ea873410d1 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(false); |
+ for (intptr_t j = 0; j < scripts.Length(); j++) { |
+ if (scripts.At(j) == raw()) { |
+ return lib.raw(); |
+ } |
+ } |
+ } |
+ return Library::null(); |
Michael Lippautz (Google)
2014/07/15 17:52:55
This is not UNREACHABLE(), as we can still use scr
|
+} |
+ |
+ |
// 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()); |
@@ -8870,10 +8893,10 @@ static void AddScriptIfUnique(const GrowableObjectArray& scripts, |
scripts.Add(candidate); |
} |
-RawArray* Library::LoadedScripts() const { |
+RawArray* Library::LoadedScripts(bool cached) const { |
Michael Lippautz (Google)
2014/07/15 17:52:55
This whole function could be rewritten to use Clas
|
// We compute the list of loaded scripts lazily. The result is |
// cached in loaded_scripts_. |
- if (loaded_scripts() == Array::null()) { |
+ if (!cached || loaded_scripts() == Array::null()) { |
hausner
2014/07/15 20:34:03
I'm afraid this may have unintended side effects.
Michael Lippautz (Google)
2014/07/15 21:20:55
Thanks for the (offline) clarifications. The cache
|
// Iterate over the library dictionary and collect all scripts. |
const GrowableObjectArray& scripts = |
GrowableObjectArray::Handle(GrowableObjectArray::New(8)); |
@@ -8902,6 +8925,21 @@ RawArray* Library::LoadedScripts() const { |
} |
AddScriptIfUnique(scripts, owner_script); |
} |
+ 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)); |