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 6762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6773 dict.SetAt(index, obj); | 6773 dict.SetAt(index, obj); |
| 6774 } | 6774 } |
| 6775 | 6775 |
| 6776 | 6776 |
| 6777 void Library::AddClass(const Class& cls) const { | 6777 void Library::AddClass(const Class& cls) const { |
| 6778 AddObject(cls, String::Handle(cls.Name())); | 6778 AddObject(cls, String::Handle(cls.Name())); |
| 6779 // Link class to this library. | 6779 // Link class to this library. |
| 6780 cls.set_library(*this); | 6780 cls.set_library(*this); |
| 6781 } | 6781 } |
| 6782 | 6782 |
| 6783 void AddScriptIfUnique(const GrowableObjectArray& scripts, Script& candidate) { | |
|
hausner
2013/09/05 21:23:51
static
Jacob
2013/09/06 00:56:58
Done.
| |
| 6784 Script& script_obj = Script::Handle(); | |
| 6785 for (int i = 0; i < scripts.Length(); i++) { | |
| 6786 script_obj ^= scripts.At(i); | |
| 6787 if (script_obj.raw() == candidate.raw()) { | |
| 6788 // We already have a reference to this script. | |
| 6789 return; | |
| 6790 } | |
| 6791 } | |
| 6792 // Add script to the list of scripts. | |
| 6793 scripts.Add(candidate); | |
| 6794 } | |
| 6783 | 6795 |
| 6784 RawArray* Library::LoadedScripts() const { | 6796 RawArray* Library::LoadedScripts() const { |
| 6785 // We compute the list of loaded scripts lazily. The result is | 6797 // We compute the list of loaded scripts lazily. The result is |
| 6786 // cached in loaded_scripts_. | 6798 // cached in loaded_scripts_. |
| 6787 if (loaded_scripts() == Array::null()) { | 6799 if (loaded_scripts() == Array::null()) { |
| 6788 // Iterate over the library dictionary and collect all scripts. | 6800 // Iterate over the library dictionary and collect all scripts. |
| 6789 const GrowableObjectArray& scripts = | 6801 const GrowableObjectArray& scripts = |
| 6790 GrowableObjectArray::Handle(GrowableObjectArray::New(8)); | 6802 GrowableObjectArray::Handle(GrowableObjectArray::New(8)); |
| 6791 Object& entry = Object::Handle(); | 6803 Object& entry = Object::Handle(); |
| 6792 Class& cls = Class::Handle(); | 6804 Class& cls = Class::Handle(); |
| 6793 Script& owner_script = Script::Handle(); | 6805 Script& owner_script = Script::Handle(); |
| 6806 Script& function_script = Script::Handle(); | |
|
siva
2013/09/05 18:35:11
Class& patch_cls = Class::Handle();
Script& patch_
Jacob
2013/09/05 23:58:24
Done.
| |
| 6807 Function& function = Function::Handle(); | |
| 6794 DictionaryIterator it(*this); | 6808 DictionaryIterator it(*this); |
| 6795 Script& script_obj = Script::Handle(); | |
| 6796 while (it.HasNext()) { | 6809 while (it.HasNext()) { |
| 6797 entry = it.GetNext(); | 6810 entry = it.GetNext(); |
| 6798 if (entry.IsClass()) { | 6811 if (entry.IsClass()) { |
| 6799 owner_script = Class::Cast(entry).script(); | 6812 owner_script = Class::Cast(entry).script(); |
| 6813 Array& functions_list = Array::Handle(Class::Cast(entry).functions()); | |
| 6814 intptr_t functions_len = functions_list.Length(); | |
| 6815 for (intptr_t i = 0; i < functions_len; i++) { | |
| 6816 function ^= functions_list.At(i); | |
| 6817 function_script = function.script(); | |
| 6818 if (!(function_script.raw() == owner_script.raw())) { | |
| 6819 // The function was patched in. | |
| 6820 AddScriptIfUnique(scripts, function_script); | |
| 6821 } | |
| 6822 } | |
|
siva
2013/09/05 18:35:11
I don't think it is necessary to go over all the f
Jacob
2013/09/05 23:58:24
That is simpler. Done.
| |
| 6800 } else if (entry.IsFunction()) { | 6823 } else if (entry.IsFunction()) { |
| 6801 owner_script = Function::Cast(entry).script(); | 6824 owner_script = Function::Cast(entry).script(); |
| 6802 } else if (entry.IsField()) { | 6825 } else if (entry.IsField()) { |
| 6803 cls = Field::Cast(entry).owner(); | 6826 cls = Field::Cast(entry).owner(); |
| 6804 owner_script = cls.script(); | 6827 owner_script = cls.script(); |
| 6805 } else { | 6828 } else { |
| 6806 continue; | 6829 continue; |
| 6807 } | 6830 } |
| 6808 if (owner_script.IsNull()) { | 6831 AddScriptIfUnique(scripts, owner_script); |
| 6809 continue; | |
| 6810 } | |
| 6811 bool is_unique = true; | |
| 6812 for (int i = 0; i < scripts.Length(); i++) { | |
| 6813 script_obj ^= scripts.At(i); | |
| 6814 if (script_obj.raw() == owner_script.raw()) { | |
| 6815 // We already have a reference to this script. | |
| 6816 is_unique = false; | |
| 6817 break; | |
| 6818 } | |
| 6819 } | |
| 6820 if (is_unique) { | |
| 6821 // Add script to the list of scripts. | |
| 6822 scripts.Add(owner_script); | |
| 6823 } | |
| 6824 } | 6832 } |
| 6825 | 6833 |
| 6826 // Create the array of scripts and cache it in loaded_scripts_. | 6834 // Create the array of scripts and cache it in loaded_scripts_. |
| 6827 const Array& scripts_array = Array::Handle(Array::MakeArray(scripts)); | 6835 const Array& scripts_array = Array::Handle(Array::MakeArray(scripts)); |
| 6828 StorePointer(&raw_ptr()->loaded_scripts_, scripts_array.raw()); | 6836 StorePointer(&raw_ptr()->loaded_scripts_, scripts_array.raw()); |
| 6829 } | 6837 } |
| 6830 return loaded_scripts(); | 6838 return loaded_scripts(); |
| 6831 } | 6839 } |
| 6832 | 6840 |
| 6833 | 6841 |
| (...skipping 8078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14912 } | 14920 } |
| 14913 | 14921 |
| 14914 | 14922 |
| 14915 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14923 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 14916 stream->OpenObject(); | 14924 stream->OpenObject(); |
| 14917 stream->CloseObject(); | 14925 stream->CloseObject(); |
| 14918 } | 14926 } |
| 14919 | 14927 |
| 14920 | 14928 |
| 14921 } // namespace dart | 14929 } // namespace dart |
| OLD | NEW |