Revision: 2911 Author: [email protected] Date: Thu Sep 17 01:58:06 2009 Log: Add Object::IsDirty function in the API.
Review URL: http://codereview.chromium.org/209013 http://code.google.com/p/v8/source/detail?r=2911 Modified: /branches/bleeding_edge/include/v8.h /branches/bleeding_edge/src/api.cc /branches/bleeding_edge/src/objects.cc /branches/bleeding_edge/src/objects.h ======================================= --- /branches/bleeding_edge/include/v8.h Tue Sep 15 04:11:09 2009 +++ /branches/bleeding_edge/include/v8.h Thu Sep 17 01:58:06 2009 @@ -1238,6 +1238,15 @@ bool SetHiddenValue(Handle<String> key, Handle<Value> value); Local<Value> GetHiddenValue(Handle<String> key); bool DeleteHiddenValue(Handle<String> key); + + /** + * Returns true if this is an instance of an api function (one + * created from a function created from a function template) and has + * been modified since it was created. Note that this method is + * conservative and may return true for objects that haven't actually + * been modified. + */ + bool IsDirty(); /** * Clone this object with a fast but shallow copy. Values will point ======================================= --- /branches/bleeding_edge/src/api.cc Tue Sep 15 04:51:40 2009 +++ /branches/bleeding_edge/src/api.cc Thu Sep 17 01:58:06 2009 @@ -2154,6 +2154,11 @@ new_map->set_is_access_check_needed(true); obj->set_map(*new_map); } + + +bool v8::Object::IsDirty() { + return Utils::OpenHandle(this)->IsDirty(); +} Local<v8::Object> v8::Object::Clone() { ======================================= --- /branches/bleeding_edge/src/objects.cc Tue Sep 15 04:39:47 2009 +++ /branches/bleeding_edge/src/objects.cc Thu Sep 17 01:58:06 2009 @@ -474,6 +474,21 @@ } return Heap::true_value(); } + + +bool JSObject::IsDirty() { + Object* cons_obj = map()->constructor(); + if (!cons_obj->IsJSFunction()) + return true; + JSFunction* fun = JSFunction::cast(cons_obj); + if (!fun->shared()->function_data()->IsFunctionTemplateInfo()) + return true; + // If the object is fully fast case and has the same map it was + // created with then no changes can have been made to it. + return map() != fun->initial_map() + || !HasFastElements() + || !HasFastProperties(); +} Object* Object::GetProperty(Object* receiver, ======================================= --- /branches/bleeding_edge/src/objects.h Tue Sep 15 04:35:23 2009 +++ /branches/bleeding_edge/src/objects.h Thu Sep 17 01:58:06 2009 @@ -1427,6 +1427,10 @@ // Tells whether this object needs to be loaded. inline bool IsLoaded(); + + // Returns true if this is an instance of an api function and has + // been modified since it was created. May give false positives. + bool IsDirty(); bool HasProperty(String* name) { return GetPropertyAttribute(name) != ABSENT; --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
