1320408 - Part 16: Change NativeObject::removeProperty to static method.

This commit is contained in:
Gaming4JC 2019-06-08 23:42:05 -04:00 • committed by Roy Tam
commit 9e0f10ac59
3 changed files with 28 additions and 29 deletions

View file

@ -672,10 +672,10 @@ NativeObject::maybeDensifySparseElements(js::ExclusiveContext* cx, HandleNativeO
*/ */
if (shape != obj->lastProperty()) { if (shape != obj->lastProperty()) {
shape = shape->previous(); shape = shape->previous();
if (!obj->removeProperty(cx, id)) if (!NativeObject::removeProperty(cx, obj, id))
return DenseElementResult::Failure; return DenseElementResult::Failure;
} else { } else {
if (!obj->removeProperty(cx, id)) if (!NativeObject::removeProperty(cx, obj, id))
return DenseElementResult::Failure; return DenseElementResult::Failure;
shape = obj->lastProperty(); shape = obj->lastProperty();
} }
@ -1045,7 +1045,7 @@ CallAddPropertyHook(ExclusiveContext* cx, HandleNativeObject obj, HandleShape sh
RootedId id(cx, shape->propid()); RootedId id(cx, shape->propid());
if (!CallJSAddPropertyOp(cx->asJSContext(), addProperty, obj, id, value)) { if (!CallJSAddPropertyOp(cx->asJSContext(), addProperty, obj, id, value)) {
obj->removeProperty(cx, shape->propid()); NativeObject::removeProperty(cx, obj, shape->propid());
return false; return false;
} }
} }
@ -2528,7 +2528,7 @@ js::NativeDeleteProperty(JSContext* cx, HandleNativeObject obj, HandleId id,
obj->setDenseElementHole(cx, JSID_TO_INT(id)); obj->setDenseElementHole(cx, JSID_TO_INT(id));
} else { } else {
if (!obj->removeProperty(cx, id)) if (!NativeObject::removeProperty(cx, obj, id))
return false; return false;
} }

View file

@ -764,7 +764,7 @@ class NativeObject : public ShapedObject
unsigned attrs, JSGetterOp getter, JSSetterOp setter); unsigned attrs, JSGetterOp getter, JSSetterOp setter);
/* Remove the property named by id from this object. */ /* Remove the property named by id from this object. */
bool removeProperty(ExclusiveContext* cx, jsid id); static bool removeProperty(ExclusiveContext* cx, HandleNativeObject obj, jsid id);
/* Clear the scope, making it empty. */ /* Clear the scope, making it empty. */
static void clear(ExclusiveContext* cx, HandleNativeObject obj); static void clear(ExclusiveContext* cx, HandleNativeObject obj);

View file

@ -968,16 +968,15 @@ NativeObject::changeProperty(ExclusiveContext* cx, HandleNativeObject obj, Handl
return newShape; return newShape;
} }
bool /* static */ bool
NativeObject::removeProperty(ExclusiveContext* cx, jsid id_) NativeObject::removeProperty(ExclusiveContext* cx, HandleNativeObject obj, jsid id_)
{ {
RootedId id(cx, id_); RootedId id(cx, id_);
RootedNativeObject self(cx, this);
AutoKeepShapeTables keep(cx); AutoKeepShapeTables keep(cx);
ShapeTable::Entry* entry; ShapeTable::Entry* entry;
RootedShape shape(cx); RootedShape shape(cx);
if (!Shape::search(cx, lastProperty(), id, keep, shape.address(), &entry)) if (!Shape::search(cx, obj->lastProperty(), id, keep, shape.address(), &entry))
return false; return false;
if (!shape) if (!shape)
@ -987,10 +986,10 @@ NativeObject::removeProperty(ExclusiveContext* cx, jsid id_)
* If shape is not the last property added, or the last property cannot * If shape is not the last property added, or the last property cannot
* be removed, switch to dictionary mode. * be removed, switch to dictionary mode.
*/ */
if (!self->inDictionaryMode() && (shape != self->lastProperty() || !self->canRemoveLastProperty())) { if (!obj->inDictionaryMode() && (shape != obj->lastProperty() || !obj->canRemoveLastProperty())) {
if (!self->toDictionaryMode(cx)) if (!obj->toDictionaryMode(cx))
return false; return false;
ShapeTable* table = self->lastProperty()->maybeTable(keep); ShapeTable* table = obj->lastProperty()->maybeTable(keep);
MOZ_ASSERT(table); MOZ_ASSERT(table);
entry = &table->search<MaybeAdding::NotAdding>(shape->propid(), keep); entry = &table->search<MaybeAdding::NotAdding>(shape->propid(), keep);
shape = entry->shape(); shape = entry->shape();
@ -1004,21 +1003,21 @@ NativeObject::removeProperty(ExclusiveContext* cx, jsid id_)
* the object or table, so the remaining removal is infallible. * the object or table, so the remaining removal is infallible.
*/ */
RootedShape spare(cx); RootedShape spare(cx);
if (self->inDictionaryMode()) { if (obj->inDictionaryMode()) {
/* For simplicity, always allocate an accessor shape for now. */ /* For simplicity, always allocate an accessor shape for now. */
spare = Allocate<AccessorShape>(cx); spare = Allocate<AccessorShape>(cx);
if (!spare) if (!spare)
return false; return false;
new (spare) Shape(shape->base()->unowned(), 0); new (spare) Shape(shape->base()->unowned(), 0);
if (shape == self->lastProperty()) { if (shape == obj->lastProperty()) {
/* /*
* Get an up to date unowned base shape for the new last property * Get an up to date unowned base shape for the new last property
* when removing the dictionary's last property. Information in * when removing the dictionary's last property. Information in
* base shapes for non-last properties may be out of sync with the * base shapes for non-last properties may be out of sync with the
* object's state. * object's state.
*/ */
RootedShape previous(cx, self->lastProperty()->parent); RootedShape previous(cx, obj->lastProperty()->parent);
StackBaseShape base(self->lastProperty()->base()); StackBaseShape base(obj->lastProperty()->base());
BaseShape* nbase = BaseShape::getUnowned(cx, base); BaseShape* nbase = BaseShape::getUnowned(cx, base);
if (!nbase) if (!nbase)
return false; return false;
@ -1028,7 +1027,7 @@ NativeObject::removeProperty(ExclusiveContext* cx, jsid id_)
/* If shape has a slot, free its slot number. */ /* If shape has a slot, free its slot number. */
if (shape->hasSlot()) { if (shape->hasSlot()) {
self->freeSlot(cx, shape->slot()); obj->freeSlot(cx, shape->slot());
if (cx->isJSContext()) if (cx->isJSContext())
++cx->asJSContext()->runtime()->propertyRemovals; ++cx->asJSContext()->runtime()->propertyRemovals;
} }
@ -1038,8 +1037,8 @@ NativeObject::removeProperty(ExclusiveContext* cx, jsid id_)
* doubly linked list, hashed by lastProperty()->table. So we can edit the * doubly linked list, hashed by lastProperty()->table. So we can edit the
* list and hash in place. * list and hash in place.
*/ */
if (self->inDictionaryMode()) { if (obj->inDictionaryMode()) {
ShapeTable* table = self->lastProperty()->maybeTable(keep); ShapeTable* table = obj->lastProperty()->maybeTable(keep);
MOZ_ASSERT(table); MOZ_ASSERT(table);
if (entry->hadCollision()) { if (entry->hadCollision()) {
@ -1056,23 +1055,23 @@ NativeObject::removeProperty(ExclusiveContext* cx, jsid id_)
* checks not to alter significantly the complexity of the * checks not to alter significantly the complexity of the
* delete in debug builds, see bug 534493. * delete in debug builds, see bug 534493.
*/ */
Shape* aprop = self->lastProperty(); Shape* aprop = obj->lastProperty();
for (int n = 50; --n >= 0 && aprop->parent; aprop = aprop->parent) for (int n = 50; --n >= 0 && aprop->parent; aprop = aprop->parent)
MOZ_ASSERT_IF(aprop != shape, self->contains(cx, aprop)); MOZ_ASSERT_IF(aprop != shape, obj->contains(cx, aprop));
#endif #endif
} }
{ {
/* Remove shape from its non-circular doubly linked list. */ /* Remove shape from its non-circular doubly linked list. */
Shape* oldLastProp = self->lastProperty(); Shape* oldLastProp = obj->lastProperty();
shape->removeFromDictionary(self); shape->removeFromDictionary(obj);
/* Hand off table from the old to new last property. */ /* Hand off table from the old to new last property. */
oldLastProp->handoffTableTo(self->lastProperty()); oldLastProp->handoffTableTo(obj->lastProperty());
} }
/* Generate a new shape for the object, infallibly. */ /* Generate a new shape for the object, infallibly. */
JS_ALWAYS_TRUE(self->generateOwnShape(cx, spare)); JS_ALWAYS_TRUE(obj->generateOwnShape(cx, spare));
/* Consider shrinking table if its load factor is <= .25. */ /* Consider shrinking table if its load factor is <= .25. */
uint32_t size = table->capacity(); uint32_t size = table->capacity();
@ -1085,11 +1084,11 @@ NativeObject::removeProperty(ExclusiveContext* cx, jsid id_)
* lazily make via a later hashify the exact table for the new property * lazily make via a later hashify the exact table for the new property
* lineage. * lineage.
*/ */
MOZ_ASSERT(shape == self->lastProperty()); MOZ_ASSERT(shape == obj->lastProperty());
self->removeLastProperty(cx); obj->removeLastProperty(cx);
} }
self->checkShapeConsistency(); obj->checkShapeConsistency();
return true; return true;
} }
@ -1133,7 +1132,7 @@ NativeObject::rollbackProperties(ExclusiveContext* cx, HandleNativeObject obj, u
if (slot < slotSpan) if (slot < slotSpan)
break; break;
} }
if (!obj->removeProperty(cx, obj->lastProperty()->propid())) if (!NativeObject::removeProperty(cx, obj, obj->lastProperty()->propid()))
return false; return false;
} }