Reviewers: Mads Ager, Description: Add Object::IsDirty function in the API.
Please review this at http://codereview.chromium.org/209013 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M include/v8.h M src/api.cc M src/objects.h M src/objects.cc Index: include/v8.h =================================================================== --- include/v8.h (revision 2910) +++ include/v8.h (working copy) @@ -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 Index: src/api.cc =================================================================== --- src/api.cc (revision 2910) +++ src/api.cc (working copy) @@ -2156,6 +2156,11 @@ } +bool v8::Object::IsDirty() { + return Utils::OpenHandle(this)->IsDirty(); +} + + Local<v8::Object> v8::Object::Clone() { ON_BAILOUT("v8::Object::Clone()", return Local<Object>()); ENTER_V8; Index: src/objects.cc =================================================================== --- src/objects.cc (revision 2910) +++ src/objects.cc (working copy) @@ -476,6 +476,21 @@ } +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, LookupResult* result, String* name, Index: src/objects.h =================================================================== --- src/objects.h (revision 2910) +++ src/objects.h (working copy) @@ -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 -~----------~----~----~----~------~----~------~--~---
