OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 8287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8298 result.SetLocationOffset(0, 0); | 8298 result.SetLocationOffset(0, 0); |
8299 return result.raw(); | 8299 return result.raw(); |
8300 } | 8300 } |
8301 | 8301 |
8302 | 8302 |
8303 const char* Script::ToCString() const { | 8303 const char* Script::ToCString() const { |
8304 return "Script"; | 8304 return "Script"; |
8305 } | 8305 } |
8306 | 8306 |
8307 | 8307 |
8308 RawLibrary* Script::FindLibrary() const { | |
8309 Isolate* isolate = Isolate::Current(); | |
8310 const GrowableObjectArray& libs = GrowableObjectArray::Handle( | |
8311 isolate, isolate->object_store()->libraries()); | |
8312 Library& lib = Library::Handle(); | |
8313 Array& scripts = Array::Handle(); | |
8314 for (intptr_t i = 0; i < libs.Length(); i++) { | |
8315 lib ^= libs.At(i); | |
8316 scripts = lib.LoadedScripts(); | |
8317 for (intptr_t j = 0; j < scripts.Length(); j++) { | |
8318 if (scripts.At(j) == raw()) { | |
8319 return lib.raw(); | |
8320 } | |
8321 } | |
8322 } | |
8323 return Library::null(); | |
8324 } | |
8325 | |
8326 | |
8308 // See also Dart_ScriptGetTokenInfo. | 8327 // See also Dart_ScriptGetTokenInfo. |
8309 void Script::PrintJSONImpl(JSONStream* stream, bool ref) const { | 8328 void Script::PrintJSONImpl(JSONStream* stream, bool ref) const { |
8310 JSONObject jsobj(stream); | 8329 JSONObject jsobj(stream); |
8311 jsobj.AddProperty("type", JSONType(ref)); | 8330 jsobj.AddProperty("type", JSONType(ref)); |
8312 const String& name = String::Handle(url()); | 8331 const String& name = String::Handle(url()); |
8313 ASSERT(!name.IsNull()); | 8332 ASSERT(!name.IsNull()); |
8314 const String& encoded_url = String::Handle(String::EncodeURI(name)); | 8333 const String& encoded_url = String::Handle(String::EncodeURI(name)); |
8315 ASSERT(!encoded_url.IsNull()); | 8334 ASSERT(!encoded_url.IsNull()); |
8316 jsobj.AddPropertyF("id", "scripts/%s", encoded_url.ToCString()); | 8335 const Library& lib = Library::Handle(FindLibrary()); |
8336 intptr_t lib_index = (lib.IsNull()) ? -1 : lib.index(); | |
8337 jsobj.AddPropertyF("id", "libraries/%" Pd "/scripts/%s", | |
8338 lib_index, encoded_url.ToCString()); | |
8317 jsobj.AddProperty("name", name.ToCString()); | 8339 jsobj.AddProperty("name", name.ToCString()); |
8318 jsobj.AddProperty("user_name", name.ToCString()); | 8340 jsobj.AddProperty("user_name", name.ToCString()); |
8319 jsobj.AddProperty("kind", GetKindAsCString()); | 8341 jsobj.AddProperty("kind", GetKindAsCString()); |
8320 if (ref) { | 8342 if (ref) { |
8321 return; | 8343 return; |
8322 } | 8344 } |
8345 jsobj.AddProperty("owning_library", lib); | |
8323 const String& source = String::Handle(Source()); | 8346 const String& source = String::Handle(Source()); |
8324 jsobj.AddProperty("source", source.ToCString()); | 8347 jsobj.AddProperty("source", source.ToCString()); |
8325 | 8348 |
8326 // Print the line number table | 8349 // Print the line number table |
8327 { | 8350 { |
8328 JSONArray tokenPosTable(&jsobj, "tokenPosTable"); | 8351 JSONArray tokenPosTable(&jsobj, "tokenPosTable"); |
8329 | 8352 |
8330 const GrowableObjectArray& lineNumberArray = | 8353 const GrowableObjectArray& lineNumberArray = |
8331 GrowableObjectArray::Handle(GenerateLineNumberArray()); | 8354 GrowableObjectArray::Handle(GenerateLineNumberArray()); |
8332 Object& value = Object::Handle(); | 8355 Object& value = Object::Handle(); |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8895 } else if (entry.IsFunction()) { | 8918 } else if (entry.IsFunction()) { |
8896 owner_script = Function::Cast(entry).script(); | 8919 owner_script = Function::Cast(entry).script(); |
8897 } else if (entry.IsField()) { | 8920 } else if (entry.IsField()) { |
8898 cls = Field::Cast(entry).owner(); | 8921 cls = Field::Cast(entry).owner(); |
8899 owner_script = cls.script(); | 8922 owner_script = cls.script(); |
8900 } else { | 8923 } else { |
8901 continue; | 8924 continue; |
8902 } | 8925 } |
8903 AddScriptIfUnique(scripts, owner_script); | 8926 AddScriptIfUnique(scripts, owner_script); |
8904 } | 8927 } |
8928 Array& anon_classes = Array::Handle(anonymous_classes()); | |
8929 Function& func = Function::Handle(); | |
8930 Array& functions = Array::Handle(); | |
8931 for (intptr_t i = 0; i < anon_classes.Length(); i++) { | |
hausner
2014/07/15 21:38:18
What scripts do you find in anon_classes that are
Michael Lippautz (Google)
2014/07/15 22:40:42
Added comment to code:
// Special case: Scripts th
| |
8932 cls ^= anon_classes.At(i); | |
8933 if (cls.IsNull()) continue; | |
8934 owner_script = cls.script(); | |
8935 AddScriptIfUnique(scripts, owner_script); | |
8936 functions = cls.functions(); | |
8937 for (intptr_t j = 0; j < functions.Length(); j++) { | |
8938 func ^= functions.At(j); | |
8939 owner_script = func.script(); | |
8940 AddScriptIfUnique(scripts, owner_script); | |
8941 } | |
8942 } | |
8905 | 8943 |
8906 // Create the array of scripts and cache it in loaded_scripts_. | 8944 // Create the array of scripts and cache it in loaded_scripts_. |
8907 const Array& scripts_array = Array::Handle(Array::MakeArray(scripts)); | 8945 const Array& scripts_array = Array::Handle(Array::MakeArray(scripts)); |
8908 StorePointer(&raw_ptr()->loaded_scripts_, scripts_array.raw()); | 8946 StorePointer(&raw_ptr()->loaded_scripts_, scripts_array.raw()); |
8909 } | 8947 } |
8910 return loaded_scripts(); | 8948 return loaded_scripts(); |
8911 } | 8949 } |
8912 | 8950 |
8913 | 8951 |
8914 // TODO(hausner): we might want to add a script dictionary to the | 8952 // TODO(hausner): we might want to add a script dictionary to the |
(...skipping 10166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19081 return tag_label.ToCString(); | 19119 return tag_label.ToCString(); |
19082 } | 19120 } |
19083 | 19121 |
19084 | 19122 |
19085 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 19123 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
19086 Instance::PrintJSONImpl(stream, ref); | 19124 Instance::PrintJSONImpl(stream, ref); |
19087 } | 19125 } |
19088 | 19126 |
19089 | 19127 |
19090 } // namespace dart | 19128 } // namespace dart |
OLD | NEW |