mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-31 03:27:31 +09:00
1320408 - Part 24: Change NativeObject::{fillInAfterSwap,replaceWithNewEquivalentShape,generateOwnShape,shadowingShapeChange} to static method.
This commit is contained in:
parent
8a42a64748
commit
83fb6841af
4 changed files with 61 additions and 55 deletions
|
|
@ -1430,40 +1430,41 @@ js::XDRObjectLiteral(XDRState<XDR_ENCODE>* xdr, MutableHandleObject obj);
|
||||||
template bool
|
template bool
|
||||||
js::XDRObjectLiteral(XDRState<XDR_DECODE>* xdr, MutableHandleObject obj);
|
js::XDRObjectLiteral(XDRState<XDR_DECODE>* xdr, MutableHandleObject obj);
|
||||||
|
|
||||||
bool
|
/* static */ bool
|
||||||
NativeObject::fillInAfterSwap(JSContext* cx, const Vector<Value>& values, void* priv)
|
NativeObject::fillInAfterSwap(JSContext* cx, HandleNativeObject obj,
|
||||||
|
const Vector<Value>& values, void* priv)
|
||||||
{
|
{
|
||||||
// This object has just been swapped with some other object, and its shape
|
// This object has just been swapped with some other object, and its shape
|
||||||
// no longer reflects its allocated size. Correct this information and
|
// no longer reflects its allocated size. Correct this information and
|
||||||
// fill the slots in with the specified values.
|
// fill the slots in with the specified values.
|
||||||
MOZ_ASSERT(slotSpan() == values.length());
|
MOZ_ASSERT(obj->slotSpan() == values.length());
|
||||||
|
|
||||||
// Make sure the shape's numFixedSlots() is correct.
|
// Make sure the shape's numFixedSlots() is correct.
|
||||||
size_t nfixed = gc::GetGCKindSlots(asTenured().getAllocKind(), getClass());
|
size_t nfixed = gc::GetGCKindSlots(obj->asTenured().getAllocKind(), obj->getClass());
|
||||||
if (nfixed != shape_->numFixedSlots()) {
|
if (nfixed != obj->shape_->numFixedSlots()) {
|
||||||
if (!generateOwnShape(cx))
|
if (!NativeObject::generateOwnShape(cx, obj))
|
||||||
return false;
|
return false;
|
||||||
shape_->setNumFixedSlots(nfixed);
|
obj->shape_->setNumFixedSlots(nfixed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPrivate())
|
if (obj->hasPrivate())
|
||||||
setPrivate(priv);
|
obj->setPrivate(priv);
|
||||||
else
|
else
|
||||||
MOZ_ASSERT(!priv);
|
MOZ_ASSERT(!priv);
|
||||||
|
|
||||||
if (slots_) {
|
if (obj->slots_) {
|
||||||
js_free(slots_);
|
js_free(obj->slots_);
|
||||||
slots_ = nullptr;
|
obj->slots_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size_t ndynamic = dynamicSlotsCount(nfixed, values.length(), getClass())) {
|
if (size_t ndynamic = dynamicSlotsCount(nfixed, values.length(), obj->getClass())) {
|
||||||
slots_ = cx->zone()->pod_malloc<HeapSlot>(ndynamic);
|
obj->slots_ = cx->zone()->pod_malloc<HeapSlot>(ndynamic);
|
||||||
if (!slots_)
|
if (!obj->slots_)
|
||||||
return false;
|
return false;
|
||||||
Debug_SetSlotRangeToCrashOnTouch(slots_, ndynamic);
|
Debug_SetSlotRangeToCrashOnTouch(obj->slots_, ndynamic);
|
||||||
}
|
}
|
||||||
|
|
||||||
initSlotRange(0, values.begin(), values.length());
|
obj->initSlotRange(0, values.begin(), values.length());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1573,10 +1574,14 @@ JSObject::swap(JSContext* cx, HandleObject a, HandleObject b)
|
||||||
a->fixDictionaryShapeAfterSwap();
|
a->fixDictionaryShapeAfterSwap();
|
||||||
b->fixDictionaryShapeAfterSwap();
|
b->fixDictionaryShapeAfterSwap();
|
||||||
|
|
||||||
if (na && !b->as<NativeObject>().fillInAfterSwap(cx, avals, apriv))
|
if (na) {
|
||||||
oomUnsafe.crash("fillInAfterSwap");
|
if (!NativeObject::fillInAfterSwap(cx, b.as<NativeObject>(), avals, apriv))
|
||||||
if (nb && !a->as<NativeObject>().fillInAfterSwap(cx, bvals, bpriv))
|
oomUnsafe.crash("fillInAfterSwap");
|
||||||
oomUnsafe.crash("fillInAfterSwap");
|
}
|
||||||
|
if (nb) {
|
||||||
|
if (!NativeObject::fillInAfterSwap(cx, a.as<NativeObject>(), bvals, bpriv))
|
||||||
|
oomUnsafe.crash("fillInAfterSwap");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swapping the contents of two objects invalidates type sets which contain
|
// Swapping the contents of two objects invalidates type sets which contain
|
||||||
|
|
@ -1839,7 +1844,7 @@ js::SetClassAndProto(JSContext* cx, HandleObject obj,
|
||||||
// We always generate a new shape if the object is a singleton,
|
// We always generate a new shape if the object is a singleton,
|
||||||
// regardless of the uncacheable-proto flag. ICs may rely on
|
// regardless of the uncacheable-proto flag. ICs may rely on
|
||||||
// this.
|
// this.
|
||||||
if (!oldproto->as<NativeObject>().generateOwnShape(cx))
|
if (!NativeObject::generateOwnShape(cx, oldproto.as<NativeObject>()))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (!JSObject::setUncacheableProto(cx, oldproto))
|
if (!JSObject::setUncacheableProto(cx, oldproto))
|
||||||
|
|
|
||||||
|
|
@ -1117,7 +1117,7 @@ PurgeProtoChain(ExclusiveContext* cx, JSObject* objArg, HandleId id)
|
||||||
|
|
||||||
shape = obj->as<NativeObject>().lookup(cx, id);
|
shape = obj->as<NativeObject>().lookup(cx, id);
|
||||||
if (shape)
|
if (shape)
|
||||||
return obj->as<NativeObject>().shadowingShapeChange(cx, *shape);
|
return NativeObject::shadowingShapeChange(cx, obj.as<NativeObject>(), *shape);
|
||||||
|
|
||||||
obj = obj->staticPrototype();
|
obj = obj->staticPrototype();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -491,8 +491,8 @@ class NativeObject : public ShapedObject
|
||||||
void checkShapeConsistency() { }
|
void checkShapeConsistency() { }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Shape*
|
static Shape*
|
||||||
replaceWithNewEquivalentShape(ExclusiveContext* cx,
|
replaceWithNewEquivalentShape(ExclusiveContext* cx, HandleNativeObject obj,
|
||||||
Shape* existingShape, Shape* newShape = nullptr,
|
Shape* existingShape, Shape* newShape = nullptr,
|
||||||
bool accessorShape = false);
|
bool accessorShape = false);
|
||||||
|
|
||||||
|
|
@ -609,11 +609,14 @@ class NativeObject : public ShapedObject
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool generateOwnShape(ExclusiveContext* cx, Shape* newShape = nullptr) {
|
static MOZ_MUST_USE bool generateOwnShape(ExclusiveContext* cx, HandleNativeObject obj,
|
||||||
return replaceWithNewEquivalentShape(cx, lastProperty(), newShape);
|
Shape* newShape = nullptr)
|
||||||
|
{
|
||||||
|
return replaceWithNewEquivalentShape(cx, obj, obj->lastProperty(), newShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shadowingShapeChange(ExclusiveContext* cx, const Shape& shape);
|
static MOZ_MUST_USE bool shadowingShapeChange(ExclusiveContext* cx, HandleNativeObject obj,
|
||||||
|
const Shape& shape);
|
||||||
static bool clearFlag(ExclusiveContext* cx, HandleNativeObject obj, BaseShape::Flag flag);
|
static bool clearFlag(ExclusiveContext* cx, HandleNativeObject obj, BaseShape::Flag flag);
|
||||||
|
|
||||||
// The maximum number of slots in an object.
|
// The maximum number of slots in an object.
|
||||||
|
|
@ -783,7 +786,8 @@ class NativeObject : public ShapedObject
|
||||||
unsigned flags, ShapeTable::Entry* entry, bool allowDictionary,
|
unsigned flags, ShapeTable::Entry* entry, bool allowDictionary,
|
||||||
const AutoKeepShapeTables& keep);
|
const AutoKeepShapeTables& keep);
|
||||||
|
|
||||||
bool fillInAfterSwap(JSContext* cx, const Vector<Value>& values, void* priv);
|
static MOZ_MUST_USE bool fillInAfterSwap(JSContext* cx, HandleNativeObject obj,
|
||||||
|
const Vector<Value>& values, void* priv);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Return true if this object has been converted from shared-immutable
|
// Return true if this object has been converted from shared-immutable
|
||||||
|
|
|
||||||
|
|
@ -853,10 +853,11 @@ NativeObject::putProperty(ExclusiveContext* cx, HandleNativeObject obj, HandleId
|
||||||
*/
|
*/
|
||||||
bool updateLast = (shape == obj->lastProperty());
|
bool updateLast = (shape == obj->lastProperty());
|
||||||
bool accessorShape = getter || setter || (attrs & (JSPROP_GETTER | JSPROP_SETTER));
|
bool accessorShape = getter || setter || (attrs & (JSPROP_GETTER | JSPROP_SETTER));
|
||||||
shape = obj->replaceWithNewEquivalentShape(cx, shape, nullptr, accessorShape);
|
shape = NativeObject::replaceWithNewEquivalentShape(cx, obj, shape, nullptr,
|
||||||
|
accessorShape);
|
||||||
if (!shape)
|
if (!shape)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (!updateLast && !obj->generateOwnShape(cx))
|
if (!updateLast && !NativeObject::generateOwnShape(cx, obj))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -1071,7 +1072,7 @@ NativeObject::removeProperty(ExclusiveContext* cx, HandleNativeObject obj, jsid
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate a new shape for the object, infallibly. */
|
/* Generate a new shape for the object, infallibly. */
|
||||||
JS_ALWAYS_TRUE(obj->generateOwnShape(cx, spare));
|
JS_ALWAYS_TRUE(NativeObject::generateOwnShape(cx, obj, 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();
|
||||||
|
|
@ -1139,28 +1140,23 @@ NativeObject::rollbackProperties(ExclusiveContext* cx, HandleNativeObject obj, u
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shape*
|
/* static */ Shape*
|
||||||
NativeObject::replaceWithNewEquivalentShape(ExclusiveContext* cx, Shape* oldShape, Shape* newShape,
|
NativeObject::replaceWithNewEquivalentShape(ExclusiveContext* cx, HandleNativeObject obj,
|
||||||
bool accessorShape)
|
Shape* oldShape, Shape* newShape, bool accessorShape)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(cx->isInsideCurrentZone(oldShape));
|
MOZ_ASSERT(cx->isInsideCurrentZone(oldShape));
|
||||||
MOZ_ASSERT_IF(oldShape != lastProperty(),
|
MOZ_ASSERT_IF(oldShape != obj->lastProperty(),
|
||||||
inDictionaryMode() && lookup(cx, oldShape->propidRef()) == oldShape);
|
obj->inDictionaryMode() && obj->lookup(cx, oldShape->propidRef()) == oldShape);
|
||||||
|
|
||||||
NativeObject* self = this;
|
if (!obj->inDictionaryMode()) {
|
||||||
|
|
||||||
if (!inDictionaryMode()) {
|
|
||||||
RootedNativeObject selfRoot(cx, self);
|
|
||||||
RootedShape newRoot(cx, newShape);
|
RootedShape newRoot(cx, newShape);
|
||||||
if (!toDictionaryMode(cx))
|
if (!obj->toDictionaryMode(cx))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
oldShape = selfRoot->lastProperty();
|
oldShape = obj->lastProperty();
|
||||||
self = selfRoot;
|
|
||||||
newShape = newRoot;
|
newShape = newRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!newShape) {
|
if (!newShape) {
|
||||||
RootedNativeObject selfRoot(cx, self);
|
|
||||||
RootedShape oldRoot(cx, oldShape);
|
RootedShape oldRoot(cx, oldShape);
|
||||||
newShape = (oldShape->isAccessorShape() || accessorShape)
|
newShape = (oldShape->isAccessorShape() || accessorShape)
|
||||||
? Allocate<AccessorShape>(cx)
|
? Allocate<AccessorShape>(cx)
|
||||||
|
|
@ -1168,12 +1164,11 @@ NativeObject::replaceWithNewEquivalentShape(ExclusiveContext* cx, Shape* oldShap
|
||||||
if (!newShape)
|
if (!newShape)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
new (newShape) Shape(oldRoot->base()->unowned(), 0);
|
new (newShape) Shape(oldRoot->base()->unowned(), 0);
|
||||||
self = selfRoot;
|
|
||||||
oldShape = oldRoot;
|
oldShape = oldRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoCheckCannotGC nogc;
|
AutoCheckCannotGC nogc;
|
||||||
ShapeTable* table = self->lastProperty()->ensureTableForDictionary(cx, nogc);
|
ShapeTable* table = obj->lastProperty()->ensureTableForDictionary(cx, nogc);
|
||||||
if (!table)
|
if (!table)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
|
@ -1186,12 +1181,12 @@ NativeObject::replaceWithNewEquivalentShape(ExclusiveContext* cx, Shape* oldShap
|
||||||
* enumeration order (see bug 601399).
|
* enumeration order (see bug 601399).
|
||||||
*/
|
*/
|
||||||
StackShape nshape(oldShape);
|
StackShape nshape(oldShape);
|
||||||
newShape->initDictionaryShape(nshape, self->numFixedSlots(), oldShape->listp);
|
newShape->initDictionaryShape(nshape, obj->numFixedSlots(), oldShape->listp);
|
||||||
|
|
||||||
MOZ_ASSERT(newShape->parent == oldShape);
|
MOZ_ASSERT(newShape->parent == oldShape);
|
||||||
oldShape->removeFromDictionary(self);
|
oldShape->removeFromDictionary(obj);
|
||||||
|
|
||||||
if (newShape == self->lastProperty())
|
if (newShape == obj->lastProperty())
|
||||||
oldShape->handoffTableTo(newShape);
|
oldShape->handoffTableTo(newShape);
|
||||||
|
|
||||||
if (entry)
|
if (entry)
|
||||||
|
|
@ -1199,10 +1194,10 @@ NativeObject::replaceWithNewEquivalentShape(ExclusiveContext* cx, Shape* oldShap
|
||||||
return newShape;
|
return newShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
/* static */ bool
|
||||||
NativeObject::shadowingShapeChange(ExclusiveContext* cx, const Shape& shape)
|
NativeObject::shadowingShapeChange(ExclusiveContext* cx, HandleNativeObject obj, const Shape& shape)
|
||||||
{
|
{
|
||||||
return generateOwnShape(cx);
|
return generateOwnShape(cx, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ bool
|
/* static */ bool
|
||||||
|
|
@ -1217,8 +1212,10 @@ JSObject::setFlags(ExclusiveContext* cx, HandleObject obj, BaseShape::Flag flags
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj->isNative() && obj->as<NativeObject>().inDictionaryMode()) {
|
if (obj->isNative() && obj->as<NativeObject>().inDictionaryMode()) {
|
||||||
if (generateShape == GENERATE_SHAPE && !obj->as<NativeObject>().generateOwnShape(cx))
|
if (generateShape == GENERATE_SHAPE) {
|
||||||
return false;
|
if (!NativeObject::generateOwnShape(cx, obj.as<NativeObject>()))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
StackBaseShape base(obj->as<NativeObject>().lastProperty());
|
StackBaseShape base(obj->as<NativeObject>().lastProperty());
|
||||||
base.flags |= flags;
|
base.flags |= flags;
|
||||||
UnownedBaseShape* nbase = BaseShape::getUnowned(cx, base);
|
UnownedBaseShape* nbase = BaseShape::getUnowned(cx, base);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue