Commit c1ac963e authored by whessev8's avatar whessev8

Replaces two non-private uses of AddProperty with...

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@411 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a30916cf
...@@ -122,10 +122,11 @@ Object* Accessors::ArraySetLength(JSObject* object, Object* value, void*) { ...@@ -122,10 +122,11 @@ Object* Accessors::ArraySetLength(JSObject* object, Object* value, void*) {
} else { } else {
// This means one of the object's prototypes is a JSArray and // This means one of the object's prototypes is a JSArray and
// the object does not have a 'length' property. // 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", return Top::Throw(*Factory::NewRangeError("invalid_array_length",
HandleVector<Object>(NULL, 0))); HandleVector<Object>(NULL, 0)));
} }
......
...@@ -137,13 +137,6 @@ Handle<Object> SetPrototype(Handle<JSFunction> function, ...@@ -137,13 +137,6 @@ Handle<Object> SetPrototype(Handle<JSFunction> function,
} }
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<Object> SetProperty(Handle<JSObject> object,
Handle<String> key, Handle<String> key,
Handle<Object> value, Handle<Object> value,
...@@ -156,11 +149,19 @@ Handle<Object> SetProperty(Handle<Object> object, ...@@ -156,11 +149,19 @@ Handle<Object> SetProperty(Handle<Object> object,
Handle<Object> key, Handle<Object> key,
Handle<Object> value, Handle<Object> value,
PropertyAttributes attributes) { PropertyAttributes attributes) {
CALL_HEAP_FUNCTION(Runtime::SetObjectProperty(object, key, value, attributes), CALL_HEAP_FUNCTION(
Object); 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<Object> SetPropertyWithInterceptor(Handle<JSObject> object,
Handle<String> key, Handle<String> key,
Handle<Object> value, Handle<Object> value,
......
...@@ -102,11 +102,6 @@ void TransformToFastProperties(Handle<JSObject> object, ...@@ -102,11 +102,6 @@ void TransformToFastProperties(Handle<JSObject> object,
int unused_property_fields); int unused_property_fields);
void FlattenString(Handle<String> str); 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<Object> SetProperty(Handle<JSObject> object,
Handle<String> key, Handle<String> key,
Handle<Object> value, Handle<Object> value,
...@@ -117,6 +112,11 @@ Handle<Object> SetProperty(Handle<Object> object, ...@@ -117,6 +112,11 @@ Handle<Object> SetProperty(Handle<Object> object,
Handle<Object> value, Handle<Object> value,
PropertyAttributes attributes); PropertyAttributes attributes);
Handle<Object> IgnoreAttributesAndSetLocalProperty(Handle<JSObject> object,
Handle<String> key,
Handle<Object> value,
PropertyAttributes attributes);
Handle<Object> SetPropertyWithInterceptor(Handle<JSObject> object, Handle<Object> SetPropertyWithInterceptor(Handle<JSObject> object,
Handle<String> key, Handle<String> key,
Handle<Object> value, Handle<Object> value,
......
...@@ -1569,51 +1569,94 @@ Object* JSObject::SetProperty(LookupResult* result, ...@@ -1569,51 +1569,94 @@ Object* JSObject::SetProperty(LookupResult* result,
// Set a real local property, even if it is READ_ONLY. If the property is not // 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 // present, add it with attributes NONE. This code is an exact clone of
// SetProperty, except for the check for IsReadOnly and the check for a // SetProperty, with the check for IsReadOnly and the check for a
// callback setter. // callback setter removed. The two lines looking up the LookupResult
Object* JSObject::IgnoreAttributesAndSetLocalProperty(String* name, // result are also added. If one of the functions is changed, the other
Object* value) { // should be.
Object* JSObject::IgnoreAttributesAndSetLocalProperty(
String* name,
Object* value,
PropertyAttributes attributes) {
// Make sure that the top context does not change when doing callbacks or // Make sure that the top context does not change when doing callbacks or
// interceptor calls. // interceptor calls.
AssertNoContextChange ncc; AssertNoContextChange ncc;
// ADDED TO CLONE
LookupResult result; LookupResult result_struct;
LocalLookup(name, &result); LocalLookup(name, &result_struct);
LookupResult* result = &result_struct;
// END ADDED TO CLONE
// Check access rights if needed. // Check access rights if needed.
if (IsAccessCheckNeeded() && if (IsAccessCheckNeeded()
!Top::MayNamedAccess(this, name, v8::ACCESS_SET)) { && !Top::MayNamedAccess(this, name, v8::ACCESS_SET)) {
Top::ReportFailedAccessCheck(this, v8::ACCESS_SET); return SetPropertyWithFailedAccessCheck(result, name, value);
return value;
} }
/*
if (result.IsValid()) { REMOVED FROM CLONE
switch (result.type()) { if (result->IsNotFound() || !result->IsProperty()) {
case NORMAL: // We could not find a local property so let's check whether there is an
property_dictionary()->ValueAtPut(result.GetDictionaryEntry(), value); // accessor that wants to handle the property.
return value; LookupResult accessor_result;
case FIELD: LookupCallbackSetterInPrototypes(name, &accessor_result);
properties()->set(result.GetFieldIndex(), value); if (accessor_result.IsValid()) {
return value; return SetPropertyWithCallback(accessor_result.GetCallbackObject(),
case MAP_TRANSITION: name,
return AddFastPropertyUsingMap(result.GetTransitionMap(), name, value); value,
case CONSTANT_FUNCTION: accessor_result.holder());
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;
} }
*/
if (result->IsNotFound()) {
return AddProperty(name, value, attributes);
} }
if (!result->IsLoaded()) {
// The property was not found return SetLazyProperty(result, name, value, attributes);
return AddProperty(name, value, NONE); }
/*
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();
}
UNREACHABLE();
return value;
} }
......
...@@ -1137,7 +1137,8 @@ class JSObject: public HeapObject { ...@@ -1137,7 +1137,8 @@ class JSObject: public HeapObject {
Object* value, Object* value,
PropertyAttributes attributes); PropertyAttributes attributes);
Object* IgnoreAttributesAndSetLocalProperty(String* key, Object* IgnoreAttributesAndSetLocalProperty(String* key,
Object* value); Object* value,
PropertyAttributes attributes);
// Sets a property that currently has lazy loading. // Sets a property that currently has lazy loading.
Object* SetLazyProperty(LookupResult* result, Object* SetLazyProperty(LookupResult* result,
......
...@@ -397,7 +397,7 @@ static Object* Runtime_DeclareGlobals(Arguments args) { ...@@ -397,7 +397,7 @@ static Object* Runtime_DeclareGlobals(Arguments args) {
// of callbacks in the prototype chain (this rules out using // of callbacks in the prototype chain (this rules out using
// SetProperty). Also, we must use the handle-based version to // SetProperty). Also, we must use the handle-based version to
// avoid GC issues. // avoid GC issues.
AddProperty(global, name, value, attributes); IgnoreAttributesAndSetLocalProperty(global, name, value, attributes);
} }
} }
// Done. // Done.
...@@ -1416,7 +1416,7 @@ static Object* Runtime_IgnoreAttributesAndSetProperty(Arguments args) { ...@@ -1416,7 +1416,7 @@ static Object* Runtime_IgnoreAttributesAndSetProperty(Arguments args) {
CONVERT_CHECKED(JSObject, object, args[0]); CONVERT_CHECKED(JSObject, object, args[0]);
CONVERT_CHECKED(String, name, args[1]); CONVERT_CHECKED(String, name, args[1]);
return object->IgnoreAttributesAndSetLocalProperty(name, args[2]); return object->IgnoreAttributesAndSetLocalProperty(name, args[2], NONE);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment