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

Unified Diff: runtime/vm/object.cc

Issue 10824209: - Allow patching of top-level methods and accessors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 10353)
+++ runtime/vm/object.cc (working copy)
@@ -4145,6 +4145,7 @@
result.set_kind(kind);
result.set_is_static(is_static);
result.set_is_const(is_const);
+ result.set_is_abstract(is_abstract);
result.set_is_external(is_external);
result.set_owner(owner);
result.set_token_pos(token_pos);
@@ -4156,7 +4157,6 @@
result.set_is_optimizable(true);
result.set_has_finally(false);
result.set_is_native(false);
- result.set_is_abstract(is_abstract);
return result.raw();
}
@@ -5455,6 +5455,52 @@
}
+void Library::ReplaceObject(const Object& obj, const String& name) const {
+ ASSERT(obj.IsClass() || obj.IsFunction() || obj.IsField());
+ ASSERT(LookupLocalObject(name) != Object::null());
+
+ Isolate* isolate = Isolate::Current();
+ const Array& dict = Array::Handle(isolate, dictionary());
+ intptr_t dict_size = dict.Length() - 1;
+ intptr_t index = name.Hash() % dict_size;
+
+ Object& entry = Object::Handle(isolate, Object::null());
hausner 2012/08/07 22:56:36 No need to explicitly specify null. We don't do it
Ivan Posva 2012/08/08 00:56:52 Done.
+ Class& cls = Class::Handle(isolate, Class::null());
+ Function& func = Function::Handle(isolate, Function::null());
+ Field& field = Field::Handle(isolate, Field::null());
+ LibraryPrefix& library_prefix = LibraryPrefix::Handle(isolate,
+ LibraryPrefix::null());
+ String& entry_name = String::Handle(isolate, String::null());
+ entry = dict.At(index);
+ // Search the entry in the hash set.
+ while (!entry.IsNull()) {
hausner 2012/08/07 22:56:36 Maybe factor out the lookup code into a separate f
Ivan Posva 2012/08/08 00:56:52 Done.
+ // TODO(hausner): find a better way to handle this polymorphism.
+ // Either introduce a common base class for Class, Function, Field
+ // and LibraryPrefix or make the name() function virtual in Object.
+ if (entry.IsClass()) {
+ cls ^= entry.raw();
+ entry_name = cls.Name();
+ } else if (entry.IsFunction()) {
+ func ^= entry.raw();
+ entry_name = func.name();
+ } else if (entry.IsField()) {
+ field ^= entry.raw();
+ entry_name = field.name();
+ } else if (entry.IsLibraryPrefix()) {
+ library_prefix ^= entry.raw();
+ entry_name = library_prefix.name();
+ } else {
+ UNREACHABLE();
+ }
+ if (entry_name.Equals(name)) {
+ dict.SetAt(index, obj);
+ }
+ index = (index + 1) % dict_size;
+ entry = dict.At(index);
+ }
+}
+
+
void Library::AddClass(const Class& cls) const {
AddObject(cls, String::Handle(cls.Name()));
// Link class to this library.
@@ -6202,6 +6248,13 @@
}
+RawError* Library::Patch(const String& url, const String& source) const {
+ const Script& script = Script::Handle(
+ Script::New(url, source, RawScript::kPatchTag));
+ return Compiler::Compile(*this, script);
+}
+
+
bool Library::IsKeyUsed(intptr_t key) {
intptr_t lib_key;
const GrowableObjectArray& libs = GrowableObjectArray::Handle(
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.h » ('j') | runtime/vm/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698