summaryrefslogtreecommitdiffstats
path: root/js/src
diff options
context:
space:
mode:
Diffstat (limited to 'js/src')
-rw-r--r--js/src/jsobj.cpp49
-rw-r--r--js/src/vm/NativeObject.cpp2
-rw-r--r--js/src/vm/NativeObject.h16
-rw-r--r--js/src/vm/Shape.cpp49
4 files changed, 61 insertions, 55 deletions
diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp
index 4957b4d39..6f9596924 100644
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -1430,40 +1430,41 @@ js::XDRObjectLiteral(XDRState<XDR_ENCODE>* xdr, MutableHandleObject obj);
template bool
js::XDRObjectLiteral(XDRState<XDR_DECODE>* xdr, MutableHandleObject obj);
-bool
-NativeObject::fillInAfterSwap(JSContext* cx, const Vector<Value>& values, void* priv)
+/* static */ bool
+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
// no longer reflects its allocated size. Correct this information and
// 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.
- size_t nfixed = gc::GetGCKindSlots(asTenured().getAllocKind(), getClass());
- if (nfixed != shape_->numFixedSlots()) {
- if (!generateOwnShape(cx))
+ size_t nfixed = gc::GetGCKindSlots(obj->asTenured().getAllocKind(), obj->getClass());
+ if (nfixed != obj->shape_->numFixedSlots()) {
+ if (!NativeObject::generateOwnShape(cx, obj))
return false;
- shape_->setNumFixedSlots(nfixed);
+ obj->shape_->setNumFixedSlots(nfixed);
}
- if (hasPrivate())
- setPrivate(priv);
+ if (obj->hasPrivate())
+ obj->setPrivate(priv);
else
MOZ_ASSERT(!priv);
- if (slots_) {
- js_free(slots_);
- slots_ = nullptr;
+ if (obj->slots_) {
+ js_free(obj->slots_);
+ obj->slots_ = nullptr;
}
- if (size_t ndynamic = dynamicSlotsCount(nfixed, values.length(), getClass())) {
- slots_ = cx->zone()->pod_malloc<HeapSlot>(ndynamic);
- if (!slots_)
+ if (size_t ndynamic = dynamicSlotsCount(nfixed, values.length(), obj->getClass())) {
+ obj->slots_ = cx->zone()->pod_malloc<HeapSlot>(ndynamic);
+ if (!obj->slots_)
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;
}
@@ -1573,10 +1574,14 @@ JSObject::swap(JSContext* cx, HandleObject a, HandleObject b)
a->fixDictionaryShapeAfterSwap();
b->fixDictionaryShapeAfterSwap();
- if (na && !b->as<NativeObject>().fillInAfterSwap(cx, avals, apriv))
- oomUnsafe.crash("fillInAfterSwap");
- if (nb && !a->as<NativeObject>().fillInAfterSwap(cx, bvals, bpriv))
- oomUnsafe.crash("fillInAfterSwap");
+ if (na) {
+ if (!NativeObject::fillInAfterSwap(cx, b.as<NativeObject>(), avals, apriv))
+ 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
@@ -1839,7 +1844,7 @@ js::SetClassAndProto(JSContext* cx, HandleObject obj,
// We always generate a new shape if the object is a singleton,
// regardless of the uncacheable-proto flag. ICs may rely on
// this.
- if (!oldproto->as<NativeObject>().generateOwnShape(cx))
+ if (!NativeObject::generateOwnShape(cx, oldproto.as<NativeObject>()))
return false;
} else {
if (!JSObject::setUncacheableProto(cx, oldproto))
diff --git a/js/src/vm/NativeObject.cpp b/js/src/vm/NativeObject.cpp
index 190a19e56..da0f59fe2 100644
--- a/js/src/vm/NativeObject.cpp
+++ b/js/src/vm/NativeObject.cpp
@@ -1117,7 +1117,7 @@ PurgeProtoChain(ExclusiveContext* cx, JSObject* objArg, HandleId id)
shape = obj->as<NativeObject>().lookup(cx, id);
if (shape)
- return obj->as<NativeObject>().shadowingShapeChange(cx, *shape);
+ return NativeObject::shadowingShapeChange(cx, obj.as<NativeObject>(), *shape);
obj = obj->staticPrototype();
}
diff --git a/js/src/vm/NativeObject.h b/js/src/vm/NativeObject.h
index 9b8fe4721..656542100 100644
--- a/js/src/vm/NativeObject.h
+++ b/js/src/vm/NativeObject.h
@@ -491,8 +491,8 @@ class NativeObject : public ShapedObject
void checkShapeConsistency() { }
#endif
- Shape*
- replaceWithNewEquivalentShape(ExclusiveContext* cx,
+ static Shape*
+ replaceWithNewEquivalentShape(ExclusiveContext* cx, HandleNativeObject obj,
Shape* existingShape, Shape* newShape = nullptr,
bool accessorShape = false);
@@ -609,11 +609,14 @@ class NativeObject : public ShapedObject
}
public:
- bool generateOwnShape(ExclusiveContext* cx, Shape* newShape = nullptr) {
- return replaceWithNewEquivalentShape(cx, lastProperty(), newShape);
+ static MOZ_MUST_USE bool generateOwnShape(ExclusiveContext* cx, HandleNativeObject obj,
+ 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);
// The maximum number of slots in an object.
@@ -783,7 +786,8 @@ class NativeObject : public ShapedObject
unsigned flags, ShapeTable::Entry* entry, bool allowDictionary,
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:
// Return true if this object has been converted from shared-immutable
diff --git a/js/src/vm/Shape.cpp b/js/src/vm/Shape.cpp
index 31cfe382c..448502805 100644
--- a/js/src/vm/Shape.cpp
+++ b/js/src/vm/Shape.cpp
@@ -853,10 +853,11 @@ NativeObject::putProperty(ExclusiveContext* cx, HandleNativeObject obj, HandleId
*/
bool updateLast = (shape == obj->lastProperty());
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)
return nullptr;
- if (!updateLast && !obj->generateOwnShape(cx))
+ if (!updateLast && !NativeObject::generateOwnShape(cx, obj))
return nullptr;
/*
@@ -1071,7 +1072,7 @@ NativeObject::removeProperty(ExclusiveContext* cx, HandleNativeObject obj, jsid
}
/* 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. */
uint32_t size = table->capacity();
@@ -1139,28 +1140,23 @@ NativeObject::rollbackProperties(ExclusiveContext* cx, HandleNativeObject obj, u
return true;
}
-Shape*
-NativeObject::replaceWithNewEquivalentShape(ExclusiveContext* cx, Shape* oldShape, Shape* newShape,
- bool accessorShape)
+/* static */ Shape*
+NativeObject::replaceWithNewEquivalentShape(ExclusiveContext* cx, HandleNativeObject obj,
+ Shape* oldShape, Shape* newShape, bool accessorShape)
{
MOZ_ASSERT(cx->isInsideCurrentZone(oldShape));
- MOZ_ASSERT_IF(oldShape != lastProperty(),
- inDictionaryMode() && lookup(cx, oldShape->propidRef()) == oldShape);
-
- NativeObject* self = this;
+ MOZ_ASSERT_IF(oldShape != obj->lastProperty(),
+ obj->inDictionaryMode() && obj->lookup(cx, oldShape->propidRef()) == oldShape);
- if (!inDictionaryMode()) {
- RootedNativeObject selfRoot(cx, self);
+ if (!obj->inDictionaryMode()) {
RootedShape newRoot(cx, newShape);
- if (!toDictionaryMode(cx))
+ if (!obj->toDictionaryMode(cx))
return nullptr;
- oldShape = selfRoot->lastProperty();
- self = selfRoot;
+ oldShape = obj->lastProperty();
newShape = newRoot;
}
if (!newShape) {
- RootedNativeObject selfRoot(cx, self);
RootedShape oldRoot(cx, oldShape);
newShape = (oldShape->isAccessorShape() || accessorShape)
? Allocate<AccessorShape>(cx)
@@ -1168,12 +1164,11 @@ NativeObject::replaceWithNewEquivalentShape(ExclusiveContext* cx, Shape* oldShap
if (!newShape)
return nullptr;
new (newShape) Shape(oldRoot->base()->unowned(), 0);
- self = selfRoot;
oldShape = oldRoot;
}
AutoCheckCannotGC nogc;
- ShapeTable* table = self->lastProperty()->ensureTableForDictionary(cx, nogc);
+ ShapeTable* table = obj->lastProperty()->ensureTableForDictionary(cx, nogc);
if (!table)
return nullptr;
@@ -1186,12 +1181,12 @@ NativeObject::replaceWithNewEquivalentShape(ExclusiveContext* cx, Shape* oldShap
* enumeration order (see bug 601399).
*/
StackShape nshape(oldShape);
- newShape->initDictionaryShape(nshape, self->numFixedSlots(), oldShape->listp);
+ newShape->initDictionaryShape(nshape, obj->numFixedSlots(), oldShape->listp);
MOZ_ASSERT(newShape->parent == oldShape);
- oldShape->removeFromDictionary(self);
+ oldShape->removeFromDictionary(obj);
- if (newShape == self->lastProperty())
+ if (newShape == obj->lastProperty())
oldShape->handoffTableTo(newShape);
if (entry)
@@ -1199,10 +1194,10 @@ NativeObject::replaceWithNewEquivalentShape(ExclusiveContext* cx, Shape* oldShap
return newShape;
}
-bool
-NativeObject::shadowingShapeChange(ExclusiveContext* cx, const Shape& shape)
+/* static */ bool
+NativeObject::shadowingShapeChange(ExclusiveContext* cx, HandleNativeObject obj, const Shape& shape)
{
- return generateOwnShape(cx);
+ return generateOwnShape(cx, obj);
}
/* static */ bool
@@ -1217,8 +1212,10 @@ JSObject::setFlags(ExclusiveContext* cx, HandleObject obj, BaseShape::Flag flags
return false;
if (obj->isNative() && obj->as<NativeObject>().inDictionaryMode()) {
- if (generateShape == GENERATE_SHAPE && !obj->as<NativeObject>().generateOwnShape(cx))
- return false;
+ if (generateShape == GENERATE_SHAPE) {
+ if (!NativeObject::generateOwnShape(cx, obj.as<NativeObject>()))
+ return false;
+ }
StackBaseShape base(obj->as<NativeObject>().lastProperty());
base.flags |= flags;
UnownedBaseShape* nbase = BaseShape::getUnowned(cx, base);