1320408 - Part 25: Change NativeObject::toDictionaryMode to static method.

This commit is contained in:
Gaming4JC 2019-06-09 01:02:39 -04:00 • committed by Roy Tam
commit f232a0b574
2 changed files with 17 additions and 19 deletions

View file

@ -510,7 +510,7 @@ class NativeObject : public ShapedObject
*/ */
bool setSlotSpan(ExclusiveContext* cx, uint32_t span); bool setSlotSpan(ExclusiveContext* cx, uint32_t span);
bool toDictionaryMode(ExclusiveContext* cx); static MOZ_MUST_USE bool toDictionaryMode(ExclusiveContext* cx, HandleNativeObject obj);
private: private:
friend class TenuringTracer; friend class TenuringTracer;

View file

@ -460,15 +460,13 @@ NativeObject::getChildProperty(ExclusiveContext* cx,
return shape; return shape;
} }
bool /* static */ bool
js::NativeObject::toDictionaryMode(ExclusiveContext* cx) js::NativeObject::toDictionaryMode(ExclusiveContext* cx, HandleNativeObject obj)
{ {
MOZ_ASSERT(!inDictionaryMode()); MOZ_ASSERT(!obj->inDictionaryMode());
MOZ_ASSERT(cx->isInsideCurrentCompartment(this)); MOZ_ASSERT(cx->isInsideCurrentCompartment(obj));
uint32_t span = slotSpan(); uint32_t span = obj->slotSpan();
Rooted<NativeObject*> self(cx, this);
// Clone the shapes into a new dictionary list. Don't update the last // Clone the shapes into a new dictionary list. Don't update the last
// property of this object until done, otherwise a GC triggered while // property of this object until done, otherwise a GC triggered while
@ -476,7 +474,7 @@ js::NativeObject::toDictionaryMode(ExclusiveContext* cx)
RootedShape root(cx); RootedShape root(cx);
RootedShape dictionaryShape(cx); RootedShape dictionaryShape(cx);
RootedShape shape(cx, lastProperty()); RootedShape shape(cx, obj->lastProperty());
while (shape) { while (shape) {
MOZ_ASSERT(!shape->inDictionary()); MOZ_ASSERT(!shape->inDictionary());
@ -488,7 +486,7 @@ js::NativeObject::toDictionaryMode(ExclusiveContext* cx)
GCPtrShape* listp = dictionaryShape ? &dictionaryShape->parent : nullptr; GCPtrShape* listp = dictionaryShape ? &dictionaryShape->parent : nullptr;
StackShape child(shape); StackShape child(shape);
dprop->initDictionaryShape(child, self->numFixedSlots(), listp); dprop->initDictionaryShape(child, obj->numFixedSlots(), listp);
if (!dictionaryShape) if (!dictionaryShape)
root = dprop; root = dprop;
@ -503,18 +501,18 @@ js::NativeObject::toDictionaryMode(ExclusiveContext* cx)
return false; return false;
} }
if (IsInsideNursery(self) && if (IsInsideNursery(obj) &&
!cx->asJSContext()->gc.nursery.queueDictionaryModeObjectToSweep(self)) !cx->asJSContext()->gc.nursery.queueDictionaryModeObjectToSweep(obj))
{ {
ReportOutOfMemory(cx); ReportOutOfMemory(cx);
return false; return false;
} }
MOZ_ASSERT(root->listp == nullptr); MOZ_ASSERT(root->listp == nullptr);
root->listp = &self->shape_; root->listp = &obj->shape_;
self->shape_ = root; obj->shape_ = root;
MOZ_ASSERT(self->inDictionaryMode()); MOZ_ASSERT(obj->inDictionaryMode());
root->base()->setSlotSpan(span); root->base()->setSlotSpan(span);
return true; return true;
@ -592,7 +590,7 @@ NativeObject::addPropertyInternal(ExclusiveContext* cx,
if (allowDictionary && if (allowDictionary &&
(!stableSlot || ShouldConvertToDictionary(obj))) (!stableSlot || ShouldConvertToDictionary(obj)))
{ {
if (!obj->toDictionaryMode(cx)) if (!toDictionaryMode(cx, obj))
return nullptr; return nullptr;
table = obj->lastProperty()->maybeTable(keep); table = obj->lastProperty()->maybeTable(keep);
entry = &table->search<MaybeAdding::Adding>(id, keep); entry = &table->search<MaybeAdding::Adding>(id, keep);
@ -834,7 +832,7 @@ NativeObject::putProperty(ExclusiveContext* cx, HandleNativeObject obj, HandleId
* addPropertyInternal because a failure under add would lose data. * addPropertyInternal because a failure under add would lose data.
*/ */
if (shape != obj->lastProperty() && !obj->inDictionaryMode()) { if (shape != obj->lastProperty() && !obj->inDictionaryMode()) {
if (!obj->toDictionaryMode(cx)) if (!toDictionaryMode(cx, obj))
return nullptr; return nullptr;
ShapeTable* table = obj->lastProperty()->maybeTable(keep); ShapeTable* table = obj->lastProperty()->maybeTable(keep);
MOZ_ASSERT(table); MOZ_ASSERT(table);
@ -988,7 +986,7 @@ NativeObject::removeProperty(ExclusiveContext* cx, HandleNativeObject obj, jsid
* be removed, switch to dictionary mode. * be removed, switch to dictionary mode.
*/ */
if (!obj->inDictionaryMode() && (shape != obj->lastProperty() || !obj->canRemoveLastProperty())) { if (!obj->inDictionaryMode() && (shape != obj->lastProperty() || !obj->canRemoveLastProperty())) {
if (!obj->toDictionaryMode(cx)) if (!toDictionaryMode(cx, obj))
return false; return false;
ShapeTable* table = obj->lastProperty()->maybeTable(keep); ShapeTable* table = obj->lastProperty()->maybeTable(keep);
MOZ_ASSERT(table); MOZ_ASSERT(table);
@ -1150,7 +1148,7 @@ NativeObject::replaceWithNewEquivalentShape(ExclusiveContext* cx, HandleNativeOb
if (!obj->inDictionaryMode()) { if (!obj->inDictionaryMode()) {
RootedShape newRoot(cx, newShape); RootedShape newRoot(cx, newShape);
if (!obj->toDictionaryMode(cx)) if (!toDictionaryMode(cx, obj))
return nullptr; return nullptr;
oldShape = obj->lastProperty(); oldShape = obj->lastProperty();
newShape = newRoot; newShape = newRoot;