Author: whessev8
Date: Thu Oct  2 06:45:21 2008
New Revision: 411

Modified:
    branches/bleeding_edge/src/accessors.cc
    branches/bleeding_edge/src/handles.cc
    branches/bleeding_edge/src/handles.h
    branches/bleeding_edge/src/objects.cc
    branches/bleeding_edge/src/objects.h
    branches/bleeding_edge/src/runtime.cc

Log:
Replaces two non-private uses of AddProperty with  
IgnoreAttributesAndSetLocalProperty.  Adds attributes parameter to  
IgnoreAtt..Property().  Makes IgnoreAtt..Property() an exact clone of  
SetProperty(), with explicit changes.

Review URL: http://codereview.chromium.org/5665

Modified: branches/bleeding_edge/src/accessors.cc
==============================================================================
--- branches/bleeding_edge/src/accessors.cc     (original)
+++ branches/bleeding_edge/src/accessors.cc     Thu Oct  2 06:45:21 2008
@@ -122,10 +122,11 @@
      } else {
        // This means one of the object's prototypes is a JSArray and
        // the object does not have a 'length' property.
-      return object->AddProperty(Heap::length_symbol(), value, NONE);
+      // Calling SetProperty causes an infinite loop.
+      return  
object->IgnoreAttributesAndSetLocalProperty(Heap::length_symbol(),
+                                                         value, NONE);
      }
    }
-
    return Top::Throw(*Factory::NewRangeError("invalid_array_length",
                                              HandleVector<Object>(NULL,  
0)));
  }

Modified: branches/bleeding_edge/src/handles.cc
==============================================================================
--- branches/bleeding_edge/src/handles.cc       (original)
+++ branches/bleeding_edge/src/handles.cc       Thu Oct  2 06:45:21 2008
@@ -137,13 +137,6 @@
  }


-void AddProperty(Handle<JSObject> object,
-                 Handle<String> key,
-                 Handle<Object> value,
-                 PropertyAttributes attributes) {
-  CALL_HEAP_FUNCTION_VOID(object->AddProperty(*key, *value, attributes));
-}
-
  Handle<Object> SetProperty(Handle<JSObject> object,
                             Handle<String> key,
                             Handle<Object> value,
@@ -156,10 +149,18 @@
                             Handle<Object> key,
                             Handle<Object> value,
                             PropertyAttributes attributes) {
-  CALL_HEAP_FUNCTION(Runtime::SetObjectProperty(object, key, value,  
attributes),
-                     Object);
+  CALL_HEAP_FUNCTION(
+      Runtime::SetObjectProperty(object, key, value, attributes), Object);
  }

+
+Handle<Object> IgnoreAttributesAndSetLocalProperty(Handle<JSObject> object,
+                           Handle<String> key,
+                           Handle<Object> value,
+                           PropertyAttributes attributes) {
+  CALL_HEAP_FUNCTION(object->
+      IgnoreAttributesAndSetLocalProperty(*key, *value, attributes),  
Object);
+}

  Handle<Object> SetPropertyWithInterceptor(Handle<JSObject> object,
                                            Handle<String> key,

Modified: branches/bleeding_edge/src/handles.h
==============================================================================
--- branches/bleeding_edge/src/handles.h        (original)
+++ branches/bleeding_edge/src/handles.h        Thu Oct  2 06:45:21 2008
@@ -102,11 +102,6 @@
                                 int unused_property_fields);
  void FlattenString(Handle<String> str);

-void AddProperty(Handle<JSObject> object,
-                 Handle<String> key,
-                 Handle<Object> value,
-                 PropertyAttributes attributes);
-
  Handle<Object> SetProperty(Handle<JSObject> object,
                             Handle<String> key,
                             Handle<Object> value,
@@ -116,6 +111,11 @@
                             Handle<Object> key,
                             Handle<Object> value,
                             PropertyAttributes attributes);
+
+Handle<Object> IgnoreAttributesAndSetLocalProperty(Handle<JSObject> object,
+                                                   Handle<String> key,
+                                                   Handle<Object> value,
+    PropertyAttributes attributes);

  Handle<Object> SetPropertyWithInterceptor(Handle<JSObject> object,
                                            Handle<String> key,

Modified: branches/bleeding_edge/src/objects.cc
==============================================================================
--- branches/bleeding_edge/src/objects.cc       (original)
+++ branches/bleeding_edge/src/objects.cc       Thu Oct  2 06:45:21 2008
@@ -1569,51 +1569,94 @@


  // Set a real local property, even if it is READ_ONLY.  If the property is  
not
-// present, add it with attributes NONE.  This code is the same as in
-// SetProperty, except for the check for IsReadOnly and the check for a
-// callback setter.
-Object* JSObject::IgnoreAttributesAndSetLocalProperty(String* name,
-                                                      Object* value) {
+// present, add it with attributes NONE.  This code is an exact clone of
+// SetProperty, with the check for IsReadOnly and the check for a
+// callback setter removed.  The two lines looking up the LookupResult
+// result are also added.  If one of the functions is changed, the other
+// should be.
+Object* JSObject::IgnoreAttributesAndSetLocalProperty(
+    String* name,
+    Object* value,
+    PropertyAttributes attributes) {
    // Make sure that the top context does not change when doing callbacks or
    // interceptor calls.
    AssertNoContextChange ncc;
-
-  LookupResult result;
-  LocalLookup(name, &result);
-
+  // ADDED TO CLONE
+  LookupResult result_struct;
+  LocalLookup(name, &result_struct);
+  LookupResult* result = &result_struct;
+  // END ADDED TO CLONE
    // Check access rights if needed.
-  if (IsAccessCheckNeeded() &&
-      !Top::MayNamedAccess(this, name, v8::ACCESS_SET)) {
-    Top::ReportFailedAccessCheck(this, v8::ACCESS_SET);
-    return value;
+  if (IsAccessCheckNeeded()
+    && !Top::MayNamedAccess(this, name, v8::ACCESS_SET)) {
+    return SetPropertyWithFailedAccessCheck(result, name, value);
    }
-
-  if (result.IsValid()) {
-    switch (result.type()) {
-      case NORMAL:
-        property_dictionary()->ValueAtPut(result.GetDictionaryEntry(),  
value);
-        return value;
-      case FIELD:
-        properties()->set(result.GetFieldIndex(), value);
-        return value;
-      case MAP_TRANSITION:
-        return AddFastPropertyUsingMap(result.GetTransitionMap(), name,  
value);
-      case CONSTANT_FUNCTION:
-        return ReplaceConstantFunctionProperty(name, value);
-      case CALLBACKS:
-        return SetPropertyWithCallback(result.GetCallbackObject(), name,  
value,
-                                       result.holder());
-      case INTERCEPTOR:
-        return SetPropertyWithInterceptor(name, value, NONE);
-      case CONSTANT_TRANSITION:
-      case NULL_DESCRIPTOR:
-        UNREACHABLE();
-        break;
+  /*
+    REMOVED FROM CLONE
+    if (result->IsNotFound() || !result->IsProperty()) {
+    // We could not find a local property so let's check whether there is  
an
+    // accessor that wants to handle the property.
+    LookupResult accessor_result;
+    LookupCallbackSetterInPrototypes(name, &accessor_result);
+    if (accessor_result.IsValid()) {
+      return SetPropertyWithCallback(accessor_result.GetCallbackObject(),
+                                     name,
+                                     value,
+                                     accessor_result.holder());
      }
+    }
+  */
+  if (result->IsNotFound()) {
+    return AddProperty(name, value, attributes);
+  }
+  if (!result->IsLoaded()) {
+    return SetLazyProperty(result, name, value, attributes);
+  }
+  /*
+    REMOVED FROM CLONE
+    if (result->IsReadOnly() && result->IsProperty()) return value;
+  */
+  // This is a real property that is not read-only, or it is a
+  // transition or null descriptor and there are no setters in the  
prototypes.
+  switch (result->type()) {
+    case NORMAL:
+      property_dictionary()->ValueAtPut(result->GetDictionaryEntry(),  
value);
+      return value;
+    case FIELD:
+      properties()->set(result->GetFieldIndex(), value);
+      return value;
+    case MAP_TRANSITION:
+      if (attributes == result->GetAttributes()) {
+        // Only use map transition if the attributes match.
+        return AddFastPropertyUsingMap(result->GetTransitionMap(),
+                                       name,
+                                       value);
+      } else {
+        return AddFastProperty(name, value, attributes);
+      }
+    case CONSTANT_FUNCTION:
+      if (value == result->GetConstantFunction()) return value;
+      // Only replace the function if necessary.
+      return ReplaceConstantFunctionProperty(name, value);
+    case CALLBACKS:
+      return SetPropertyWithCallback(result->GetCallbackObject(),
+                                     name,
+                                     value,
+                                     result->holder());
+    case INTERCEPTOR:
+      return SetPropertyWithInterceptor(name, value, attributes);
+    case CONSTANT_TRANSITION:
+      // Replace with a MAP_TRANSITION to a new map with a FIELD, even
+      // if the value is a function.
+      // AddProperty has been extended to do this, in this case.
+      return AddFastProperty(name, value, attributes);
+    case NULL_DESCRIPTOR:
+      UNREACHABLE();
+    default:
+      UNREACHABLE();
    }
-
-  // The property was not found
-  return AddProperty(name, value, NONE);
+  UNREACHABLE();
+  return value;
  }



Modified: branches/bleeding_edge/src/objects.h
==============================================================================
--- branches/bleeding_edge/src/objects.h        (original)
+++ branches/bleeding_edge/src/objects.h        Thu Oct  2 06:45:21 2008
@@ -1137,7 +1137,8 @@
                                       Object* value,
                                       PropertyAttributes attributes);
    Object* IgnoreAttributesAndSetLocalProperty(String* key,
-                                              Object* value);
+                                              Object* value,
+                                              PropertyAttributes  
attributes);

    // Sets a property that currently has lazy loading.
    Object* SetLazyProperty(LookupResult* result,

Modified: branches/bleeding_edge/src/runtime.cc
==============================================================================
--- branches/bleeding_edge/src/runtime.cc       (original)
+++ branches/bleeding_edge/src/runtime.cc       Thu Oct  2 06:45:21 2008
@@ -397,7 +397,7 @@
        // of callbacks in the prototype chain (this rules out using
        // SetProperty).  Also, we must use the handle-based version to
        // avoid GC issues.
-      AddProperty(global, name, value, attributes);
+      IgnoreAttributesAndSetLocalProperty(global, name, value, attributes);
      }
    }
    // Done.
@@ -1416,7 +1416,7 @@
    CONVERT_CHECKED(JSObject, object, args[0]);
    CONVERT_CHECKED(String, name, args[1]);

-  return object->IgnoreAttributesAndSetLocalProperty(name, args[2]);
+  return object->IgnoreAttributesAndSetLocalProperty(name, args[2], NONE);
  }



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to