mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1140670 part 3. Add an assertParentIs() for asserting the parent is something specific and use it in various places to eliminate getParent() calls. r=waldo
This commit is contained in:
parent
f306089853
commit
40b610d00a
@ -1927,7 +1927,8 @@ JS_NewObject(JSContext *cx, const JSClass *jsclasp)
|
||||
MOZ_ASSERT(!(clasp->flags & JSCLASS_IS_GLOBAL));
|
||||
|
||||
JSObject *obj = NewObjectWithClassProto(cx, clasp, NullPtr(), NullPtr());
|
||||
MOZ_ASSERT_IF(obj, obj->getParent());
|
||||
if (obj)
|
||||
obj->assertParentIs(cx->global());
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -3219,8 +3219,9 @@ CreateArrayPrototype(JSContext *cx, JSProtoKey key)
|
||||
if (!NewObjectMetadata(cx, &metadata))
|
||||
return nullptr;
|
||||
|
||||
proto->assertParentIs(cx->global());
|
||||
RootedShape shape(cx, EmptyShape::getInitialShape(cx, &ArrayObject::class_, TaggedProto(proto),
|
||||
proto->getParent(), metadata,
|
||||
cx->global(), metadata,
|
||||
gc::FINALIZE_OBJECT0));
|
||||
if (!shape)
|
||||
return nullptr;
|
||||
|
@ -427,17 +427,18 @@ JSCompartment::wrap(JSContext *cx, MutableHandleObject obj, HandleObject existin
|
||||
if (WrapperMap::Ptr p = crossCompartmentWrappers.lookup(CrossCompartmentKey(key))) {
|
||||
obj.set(&p->value().get().toObject());
|
||||
MOZ_ASSERT(obj->is<CrossCompartmentWrapperObject>());
|
||||
MOZ_ASSERT(obj->getParent() == global);
|
||||
obj->assertParentIs(global);
|
||||
return true;
|
||||
}
|
||||
|
||||
RootedObject existing(cx, existingArg);
|
||||
if (existing) {
|
||||
// existing is known to be a proxy, so we know its parent global.
|
||||
existing->assertParentIs(global);
|
||||
// Is it possible to reuse |existing|?
|
||||
if (!existing->getTaggedProto().isLazy() ||
|
||||
// Note: Class asserted above, so all that's left to check is callability
|
||||
existing->isCallable() ||
|
||||
existing->getParent() != global ||
|
||||
obj->isCallable())
|
||||
{
|
||||
existing = nullptr;
|
||||
|
@ -2028,7 +2028,7 @@ js::NewFunctionWithProto(ExclusiveContext *cx, HandleObject funobjArg, Native na
|
||||
RootedObject funobj(cx, funobjArg);
|
||||
if (funobj) {
|
||||
MOZ_ASSERT(funobj->is<JSFunction>());
|
||||
MOZ_ASSERT(funobj->getParent() == parent);
|
||||
funobj->assertParentIs(parent);
|
||||
MOZ_ASSERT_IF(native, funobj->isSingleton());
|
||||
} else {
|
||||
// Don't mark asm.js module functions as singleton since they are
|
||||
|
@ -1801,8 +1801,9 @@ js::DeepCloneObjectLiteral(JSContext *cx, HandleNativeObject obj, NewObjectKind
|
||||
if (!group)
|
||||
return nullptr;
|
||||
RootedObject proto(cx, group->proto().toObject());
|
||||
RootedObject parent(cx, obj->getParent());
|
||||
clone = NewNativeObjectWithGivenProto(cx, &PlainObject::class_, proto, parent, kind,
|
||||
obj->assertParentIs(cx->global());
|
||||
clone = NewNativeObjectWithGivenProto(cx, &PlainObject::class_, proto,
|
||||
NullPtr(), kind,
|
||||
newKind);
|
||||
}
|
||||
|
||||
@ -1869,8 +1870,8 @@ InitializePropertiesFromCompatibleNativeObject(JSContext *cx,
|
||||
{
|
||||
assertSameCompartment(cx, src, dst);
|
||||
MOZ_ASSERT(src->getClass() == dst->getClass());
|
||||
MOZ_ASSERT(src->getParent() == dst->getParent());
|
||||
MOZ_ASSERT(dst->getParent() == cx->global());
|
||||
src->assertParentIs(cx->global());
|
||||
dst->assertParentIs(cx->global());
|
||||
MOZ_ASSERT(src->getProto() == dst->getProto());
|
||||
MOZ_ASSERT(dst->lastProperty()->getObjectFlags() == 0);
|
||||
MOZ_ASSERT(!src->getMetadata());
|
||||
@ -2415,7 +2416,7 @@ DefineStandardSlot(JSContext *cx, HandleObject obj, JSProtoKey key, JSAtom *atom
|
||||
static void
|
||||
SetClassObject(JSObject *obj, JSProtoKey key, JSObject *cobj, JSObject *proto)
|
||||
{
|
||||
MOZ_ASSERT(!obj->getParent());
|
||||
obj->assertParentIs(nullptr);
|
||||
if (!obj->is<GlobalObject>())
|
||||
return;
|
||||
|
||||
@ -2426,7 +2427,7 @@ SetClassObject(JSObject *obj, JSProtoKey key, JSObject *cobj, JSObject *proto)
|
||||
static void
|
||||
ClearClassObject(JSObject *obj, JSProtoKey key)
|
||||
{
|
||||
MOZ_ASSERT(!obj->getParent());
|
||||
obj->assertParentIs(nullptr);
|
||||
if (!obj->is<GlobalObject>())
|
||||
return;
|
||||
|
||||
|
@ -426,6 +426,10 @@ class JSObject : public js::gc::Cell
|
||||
|
||||
/* Access the parent link of an object. */
|
||||
JSObject *getParent() const;
|
||||
/* A way to assert something about the parent of an object */
|
||||
MOZ_ALWAYS_INLINE void assertParentIs(JSObject *parent) const {
|
||||
MOZ_ASSERT(getParent() == parent);
|
||||
}
|
||||
static bool setParent(JSContext *cx, js::HandleObject obj, js::HandleObject newParent);
|
||||
|
||||
/*
|
||||
|
@ -324,11 +324,6 @@ JSObject::getMetadata() const
|
||||
inline js::GlobalObject &
|
||||
JSObject::global() const
|
||||
{
|
||||
#ifdef DEBUG
|
||||
JSObject *obj = const_cast<JSObject *>(this);
|
||||
while (JSObject *parent = obj->getParent())
|
||||
obj = parent;
|
||||
#endif
|
||||
/*
|
||||
* The global is read-barriered so that it is kept live by access through
|
||||
* the JSCompartment. When accessed through a JSObject, however, the global
|
||||
|
@ -752,7 +752,7 @@ void
|
||||
ProxyObject::renew(JSContext *cx, const BaseProxyHandler *handler, Value priv)
|
||||
{
|
||||
MOZ_ASSERT_IF(IsCrossCompartmentWrapper(this), IsDeadProxyObject(this));
|
||||
MOZ_ASSERT(getParent() == cx->global());
|
||||
assertParentIs(cx->global());
|
||||
MOZ_ASSERT(getClass() == &ProxyObject::class_);
|
||||
MOZ_ASSERT(!getClass()->ext.innerObject);
|
||||
MOZ_ASSERT(hasLazyPrototype());
|
||||
|
@ -173,8 +173,9 @@ ArgumentsObject::create(JSContext *cx, HandleScript script, HandleFunction calle
|
||||
if (!NewObjectMetadata(cx, &metadata))
|
||||
return nullptr;
|
||||
|
||||
proto->assertParentIs(cx->global());
|
||||
RootedShape shape(cx, EmptyShape::getInitialShape(cx, clasp, TaggedProto(proto),
|
||||
proto->getParent(), metadata, FINALIZE_KIND,
|
||||
cx->global(), metadata, FINALIZE_KIND,
|
||||
BaseShape::INDEXED));
|
||||
if (!shape)
|
||||
return nullptr;
|
||||
|
@ -66,8 +66,8 @@ RegExpObjectBuilder::getOrCreateClone(HandleObjectGroup group)
|
||||
{
|
||||
MOZ_ASSERT(!reobj_);
|
||||
MOZ_ASSERT(group->clasp() == &RegExpObject::class_);
|
||||
|
||||
RootedObject parent(cx, group->proto().toObject()->getParent());
|
||||
group->proto().toObject()->assertParentIs(&group->proto().toObject()->global());
|
||||
RootedObject parent(cx, &group->proto().toObject()->global());
|
||||
|
||||
// Note: RegExp objects are always allocated in the tenured heap. This is
|
||||
// not strictly required, but simplifies embedding them in jitcode.
|
||||
@ -113,7 +113,8 @@ RegExpObjectBuilder::clone(Handle<RegExpObject *> other)
|
||||
* the clone -- if the |RegExpStatics| provides more flags we'll
|
||||
* need a different |RegExpShared|.
|
||||
*/
|
||||
RegExpStatics *res = other->getProto()->getParent()->as<GlobalObject>().getRegExpStatics(cx);
|
||||
other->getProto()->assertParentIs(&other->getProto()->global());
|
||||
RegExpStatics *res = other->getProto()->global().getRegExpStatics(cx);
|
||||
if (!res)
|
||||
return nullptr;
|
||||
|
||||
|
@ -3487,8 +3487,10 @@ ChangeObjectFixedSlotCount(JSContext *cx, PlainObject *obj, gc::AllocKind allocK
|
||||
{
|
||||
MOZ_ASSERT(OnlyHasDataProperties(obj->lastProperty()));
|
||||
|
||||
obj->assertParentIs(cx->global());
|
||||
Shape *newShape = ReshapeForParentAndAllocKind(cx, obj->lastProperty(),
|
||||
obj->getTaggedProto(), obj->getParent(),
|
||||
obj->getTaggedProto(),
|
||||
cx->global(),
|
||||
allocKind);
|
||||
if (!newShape)
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user