Chromium Code Reviews| 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(false); | |
| 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(); | |
|
Michael Lippautz (Google)
2014/07/15 17:52:55
This is not UNREACHABLE(), as we can still use scr
| |
| 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8863 script_obj ^= scripts.At(i); | 8886 script_obj ^= scripts.At(i); |
| 8864 if (script_obj.raw() == candidate.raw()) { | 8887 if (script_obj.raw() == candidate.raw()) { |
| 8865 // We already have a reference to this script. | 8888 // We already have a reference to this script. |
| 8866 return; | 8889 return; |
| 8867 } | 8890 } |
| 8868 } | 8891 } |
| 8869 // Add script to the list of scripts. | 8892 // Add script to the list of scripts. |
| 8870 scripts.Add(candidate); | 8893 scripts.Add(candidate); |
| 8871 } | 8894 } |
| 8872 | 8895 |
| 8873 RawArray* Library::LoadedScripts() const { | 8896 RawArray* Library::LoadedScripts(bool cached) const { |
|
Michael Lippautz (Google)
2014/07/15 17:52:55
This whole function could be rewritten to use Clas
| |
| 8874 // We compute the list of loaded scripts lazily. The result is | 8897 // We compute the list of loaded scripts lazily. The result is |
| 8875 // cached in loaded_scripts_. | 8898 // cached in loaded_scripts_. |
| 8876 if (loaded_scripts() == Array::null()) { | 8899 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
| |
| 8877 // Iterate over the library dictionary and collect all scripts. | 8900 // Iterate over the library dictionary and collect all scripts. |
| 8878 const GrowableObjectArray& scripts = | 8901 const GrowableObjectArray& scripts = |
| 8879 GrowableObjectArray::Handle(GrowableObjectArray::New(8)); | 8902 GrowableObjectArray::Handle(GrowableObjectArray::New(8)); |
| 8880 Object& entry = Object::Handle(); | 8903 Object& entry = Object::Handle(); |
| 8881 Class& cls = Class::Handle(); | 8904 Class& cls = Class::Handle(); |
| 8882 Class& patch_cls = Class::Handle(); | 8905 Class& patch_cls = Class::Handle(); |
| 8883 Script& owner_script = Script::Handle(); | 8906 Script& owner_script = Script::Handle(); |
| 8884 Script& patch_script = Script::Handle(); | 8907 Script& patch_script = Script::Handle(); |
| 8885 DictionaryIterator it(*this); | 8908 DictionaryIterator it(*this); |
| 8886 while (it.HasNext()) { | 8909 while (it.HasNext()) { |
| 8887 entry = it.GetNext(); | 8910 entry = it.GetNext(); |
| 8888 if (entry.IsClass()) { | 8911 if (entry.IsClass()) { |
| 8889 owner_script = Class::Cast(entry).script(); | 8912 owner_script = Class::Cast(entry).script(); |
| 8890 patch_cls = Class::Cast(entry).patch_class(); | 8913 patch_cls = Class::Cast(entry).patch_class(); |
| 8891 if (!patch_cls.IsNull()) { | 8914 if (!patch_cls.IsNull()) { |
| 8892 patch_script = patch_cls.script(); | 8915 patch_script = patch_cls.script(); |
| 8893 AddScriptIfUnique(scripts, patch_script); | 8916 AddScriptIfUnique(scripts, patch_script); |
| 8894 } | 8917 } |
| 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++) { | |
| 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 |