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

Side by Side Diff: runtime/vm/object.cc

Issue 23982002: Fix bug where Script files that only contained patches were lost from the list of LoadedScripts() T… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: removed dupe code Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 6768 matching lines...) Expand 10 before | Expand all | Expand 10 after
6779 dict.SetAt(index, obj); 6779 dict.SetAt(index, obj);
6780 } 6780 }
6781 6781
6782 6782
6783 void Library::AddClass(const Class& cls) const { 6783 void Library::AddClass(const Class& cls) const {
6784 AddObject(cls, String::Handle(cls.Name())); 6784 AddObject(cls, String::Handle(cls.Name()));
6785 // Link class to this library. 6785 // Link class to this library.
6786 cls.set_library(*this); 6786 cls.set_library(*this);
6787 } 6787 }
6788 6788
6789 static void AddScriptIfUnique(const GrowableObjectArray& scripts,
6790 Script& candidate) {
6791 if (candidate.IsNull()) {
6792 return;
6793 }
6794 Script& script_obj = Script::Handle();
6795
6796 for (int i = 0; i < scripts.Length(); i++) {
6797 script_obj ^= scripts.At(i);
6798 if (script_obj.raw() == candidate.raw()) {
6799 // We already have a reference to this script.
6800 return;
6801 }
6802 }
6803 // Add script to the list of scripts.
6804 scripts.Add(candidate);
6805 }
6789 6806
6790 RawArray* Library::LoadedScripts() const { 6807 RawArray* Library::LoadedScripts() const {
6791 // We compute the list of loaded scripts lazily. The result is 6808 // We compute the list of loaded scripts lazily. The result is
6792 // cached in loaded_scripts_. 6809 // cached in loaded_scripts_.
6793 if (loaded_scripts() == Array::null()) { 6810 if (loaded_scripts() == Array::null()) {
6794 // Iterate over the library dictionary and collect all scripts. 6811 // Iterate over the library dictionary and collect all scripts.
6795 const GrowableObjectArray& scripts = 6812 const GrowableObjectArray& scripts =
6796 GrowableObjectArray::Handle(GrowableObjectArray::New(8)); 6813 GrowableObjectArray::Handle(GrowableObjectArray::New(8));
6797 Object& entry = Object::Handle(); 6814 Object& entry = Object::Handle();
6798 Class& cls = Class::Handle(); 6815 Class& cls = Class::Handle();
6816 Class& patch_cls = Class::Handle();
6799 Script& owner_script = Script::Handle(); 6817 Script& owner_script = Script::Handle();
6818 Script& patch_script = Script::Handle();
6800 DictionaryIterator it(*this); 6819 DictionaryIterator it(*this);
6801 Script& script_obj = Script::Handle();
6802 while (it.HasNext()) { 6820 while (it.HasNext()) {
6803 entry = it.GetNext(); 6821 entry = it.GetNext();
6804 if (entry.IsClass()) { 6822 if (entry.IsClass()) {
6805 owner_script = Class::Cast(entry).script(); 6823 owner_script = Class::Cast(entry).script();
6824 patch_cls = Class::Cast(entry).patch_class();
6825 if (!patch_cls.IsNull()) {
6826 patch_script = patch_cls.script();
6827 AddScriptIfUnique(scripts, patch_script);
6828 }
6806 } else if (entry.IsFunction()) { 6829 } else if (entry.IsFunction()) {
6807 owner_script = Function::Cast(entry).script(); 6830 owner_script = Function::Cast(entry).script();
6808 } else if (entry.IsField()) { 6831 } else if (entry.IsField()) {
6809 cls = Field::Cast(entry).owner(); 6832 cls = Field::Cast(entry).owner();
6810 owner_script = cls.script(); 6833 owner_script = cls.script();
6811 } else { 6834 } else {
6812 continue; 6835 continue;
6813 } 6836 }
6814 if (owner_script.IsNull()) { 6837 AddScriptIfUnique(scripts, owner_script);
6815 continue;
6816 }
6817 bool is_unique = true;
6818 for (int i = 0; i < scripts.Length(); i++) {
6819 script_obj ^= scripts.At(i);
6820 if (script_obj.raw() == owner_script.raw()) {
6821 // We already have a reference to this script.
6822 is_unique = false;
6823 break;
6824 }
6825 }
6826 if (is_unique) {
6827 // Add script to the list of scripts.
6828 scripts.Add(owner_script);
6829 }
6830 } 6838 }
6831 6839
6832 // Create the array of scripts and cache it in loaded_scripts_. 6840 // Create the array of scripts and cache it in loaded_scripts_.
6833 const Array& scripts_array = Array::Handle(Array::MakeArray(scripts)); 6841 const Array& scripts_array = Array::Handle(Array::MakeArray(scripts));
6834 StorePointer(&raw_ptr()->loaded_scripts_, scripts_array.raw()); 6842 StorePointer(&raw_ptr()->loaded_scripts_, scripts_array.raw());
6835 } 6843 }
6836 return loaded_scripts(); 6844 return loaded_scripts();
6837 } 6845 }
6838 6846
6839 6847
(...skipping 8085 matching lines...) Expand 10 before | Expand all | Expand 10 after
14925 } 14933 }
14926 14934
14927 14935
14928 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14936 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14929 stream->OpenObject(); 14937 stream->OpenObject();
14930 stream->CloseObject(); 14938 stream->CloseObject();
14931 } 14939 }
14932 14940
14933 14941
14934 } // namespace dart 14942 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698