Bug 1131877 - Part 3: Handlify TaggedProto NewObject functions; r=sfink

This commit is contained in:
Terrence Cole 2015-02-13 09:36:40 -08:00
parent e998846140
commit 7e0c081e5f
4 changed files with 32 additions and 21 deletions

View File

@ -1230,7 +1230,7 @@ NewObjectCache::fillProto(EntryIndex entry, const Class *clasp, js::TaggedProto
JSObject *
js::NewObjectWithGivenTaggedProto(ExclusiveContext *cxArg, const Class *clasp,
TaggedProto protoArg, HandleObject parentArg,
Handle<TaggedProto> proto, HandleObject parentArg,
gc::AllocKind allocKind, NewObjectKind newKind)
{
if (CanBeFinalizedInBackground(allocKind, clasp))
@ -1241,22 +1241,20 @@ js::NewObjectWithGivenTaggedProto(ExclusiveContext *cxArg, const Class *clasp,
if (JSContext *cx = cxArg->maybeJSContext()) {
JSRuntime *rt = cx->runtime();
NewObjectCache &cache = rt->newObjectCache;
if (protoArg.isObject() &&
if (proto.isObject() &&
newKind == GenericObject &&
clasp->isNative() &&
!cx->compartment()->hasObjectMetadataCallback() &&
(!parentArg || parentArg == protoArg.toObject()->getParent()) &&
!protoArg.toObject()->is<GlobalObject>())
(!parentArg || parentArg == proto.toObject()->getParent()) &&
!proto.toObject()->is<GlobalObject>())
{
if (cache.lookupProto(clasp, protoArg.toObject(), allocKind, &entry)) {
if (cache.lookupProto(clasp, proto.toObject(), allocKind, &entry)) {
JSObject *obj = cache.newObjectFromHit<NoGC>(cx, entry, GetInitialHeap(newKind, clasp));
if (obj) {
return obj;
} else {
Rooted<TaggedProto> proto(cxArg, protoArg);
obj = cache.newObjectFromHit<CanGC>(cx, entry, GetInitialHeap(newKind, clasp));
MOZ_ASSERT(!obj);
protoArg = proto;
}
} else {
gcNumber = rt->gc.gcNumber();
@ -1264,9 +1262,6 @@ js::NewObjectWithGivenTaggedProto(ExclusiveContext *cxArg, const Class *clasp,
}
}
Rooted<TaggedProto> proto(cxArg, protoArg);
RootedObject parent(cxArg, parentArg);
ObjectGroup *group = ObjectGroup::defaultNewGroup(cxArg, clasp, proto, nullptr);
if (!group)
return nullptr;
@ -1275,6 +1270,7 @@ js::NewObjectWithGivenTaggedProto(ExclusiveContext *cxArg, const Class *clasp,
* Default parent to the parent of the prototype, which was set from
* the parent of the prototype's constructor.
*/
RootedObject parent(cxArg, parentArg);
if (!parent && proto.isObject())
parent = proto.toObject()->getParent();
@ -1394,7 +1390,7 @@ js::NewObjectWithClassProtoCommon(ExclusiveContext *cxArg, const Class *clasp,
gc::AllocKind allocKind, NewObjectKind newKind)
{
if (protoArg) {
return NewObjectWithGivenTaggedProto(cxArg, clasp, TaggedProto(protoArg), maybeParent,
return NewObjectWithGivenTaggedProto(cxArg, clasp, AsTaggedProto(protoArg), maybeParent,
allocKind, newKind);
}
@ -1594,8 +1590,9 @@ CreateThisForFunctionWithGroup(JSContext *cx, HandleObjectGroup group, JSObject
gc::AllocKind allocKind = NewObjectGCKind(&PlainObject::class_);
if (newKind == SingletonObject) {
Rooted<TaggedProto> protoRoot(cx, group->proto());
RootedObject parentRoot(cx, parent);
return NewObjectWithGivenTaggedProto(cx, &PlainObject::class_, group->proto(), parentRoot,
return NewObjectWithGivenTaggedProto(cx, &PlainObject::class_, protoRoot, parentRoot,
allocKind, newKind);
}
return NewObjectWithGroup<PlainObject>(cx, group, parent, allocKind, newKind);

View File

@ -474,11 +474,11 @@ class AutoPropDescVector : public AutoVectorRooter<PropDesc>
* default to the prototype's global if the prototype is non-null.
*/
JSObject *
NewObjectWithGivenTaggedProto(ExclusiveContext *cx, const Class *clasp, TaggedProto proto,
NewObjectWithGivenTaggedProto(ExclusiveContext *cx, const Class *clasp, Handle<TaggedProto> proto,
HandleObject parent, gc::AllocKind allocKind, NewObjectKind newKind);
inline JSObject *
NewObjectWithGivenTaggedProto(ExclusiveContext *cx, const Class *clasp, TaggedProto proto,
NewObjectWithGivenTaggedProto(ExclusiveContext *cx, const Class *clasp, Handle<TaggedProto> proto,
HandleObject parent, NewObjectKind newKind = GenericObject)
{
gc::AllocKind allocKind = gc::GetGCObjectKind(clasp);
@ -487,7 +487,7 @@ NewObjectWithGivenTaggedProto(ExclusiveContext *cx, const Class *clasp, TaggedPr
template <typename T>
inline T *
NewObjectWithGivenTaggedProto(ExclusiveContext *cx, TaggedProto proto, HandleObject parent,
NewObjectWithGivenTaggedProto(ExclusiveContext *cx, Handle<TaggedProto> proto, HandleObject parent,
NewObjectKind newKind = GenericObject)
{
JSObject *obj = NewObjectWithGivenTaggedProto(cx, &T::class_, proto, parent, newKind);
@ -498,14 +498,15 @@ inline JSObject *
NewObjectWithGivenProto(ExclusiveContext *cx, const Class *clasp, HandleObject proto,
HandleObject parent, gc::AllocKind allocKind, NewObjectKind newKind)
{
return NewObjectWithGivenTaggedProto(cx, clasp, TaggedProto(proto), parent, allocKind, newKind);
return NewObjectWithGivenTaggedProto(cx, clasp, AsTaggedProto(proto), parent, allocKind,
newKind);
}
inline JSObject *
NewObjectWithGivenProto(ExclusiveContext *cx, const Class *clasp, HandleObject proto,
HandleObject parent, NewObjectKind newKind = GenericObject)
{
return NewObjectWithGivenTaggedProto(cx, clasp, TaggedProto(proto), parent, newKind);
return NewObjectWithGivenTaggedProto(cx, clasp, AsTaggedProto(proto), parent, newKind);
}
template <typename T>
@ -513,7 +514,7 @@ inline T *
NewObjectWithGivenProto(ExclusiveContext *cx, HandleObject proto, HandleObject parent,
NewObjectKind newKind = GenericObject)
{
return NewObjectWithGivenTaggedProto<T>(cx, TaggedProto(proto), parent, newKind);
return NewObjectWithGivenTaggedProto<T>(cx, AsTaggedProto(proto), parent, newKind);
}
template <typename T>
@ -521,7 +522,7 @@ inline T *
NewObjectWithGivenProto(ExclusiveContext *cx, HandleObject proto, HandleObject parent,
gc::AllocKind allocKind, NewObjectKind newKind = GenericObject)
{
JSObject *obj = NewObjectWithGivenTaggedProto(cx, &T::class_, TaggedProto(proto), parent,
JSObject *obj = NewObjectWithGivenTaggedProto(cx, &T::class_, AsTaggedProto(proto), parent,
allocKind, newKind);
return obj ? &obj->as<T>() : nullptr;
}

View File

@ -346,7 +346,7 @@ CopyInitializerObject(JSContext *cx, HandlePlainObject baseobj, NewObjectKind ne
inline NativeObject *
NewNativeObjectWithGivenTaggedProto(ExclusiveContext *cx, const Class *clasp,
TaggedProto proto, HandleObject parent,
Handle<TaggedProto> proto, HandleObject parent,
gc::AllocKind allocKind, NewObjectKind newKind)
{
return MaybeNativeObject(NewObjectWithGivenTaggedProto(cx, clasp, proto, parent, allocKind,
@ -355,7 +355,7 @@ NewNativeObjectWithGivenTaggedProto(ExclusiveContext *cx, const Class *clasp,
inline NativeObject *
NewNativeObjectWithGivenTaggedProto(ExclusiveContext *cx, const Class *clasp,
TaggedProto proto, HandleObject parent,
Handle<TaggedProto> proto, HandleObject parent,
NewObjectKind newKind = GenericObject)
{
return MaybeNativeObject(NewObjectWithGivenTaggedProto(cx, clasp, proto, parent, newKind));

View File

@ -113,6 +113,19 @@ class RootedBase<TaggedProto> : public TaggedProtoOperations<Rooted<TaggedProto>
}
};
// Since JSObject pointers are either nullptr or a valid object and since the
// object layout of TaggedProto is identical to a bare object pointer, we can
// safely treat a pointer to an already-rooted object (e.g. HandleObject) as a
// pointer to a TaggedProto.
inline Handle<TaggedProto>
AsTaggedProto(HandleObject obj)
{
static_assert(sizeof(JSObject*) == sizeof(TaggedProto),
"TaggedProto must be binary compatible with JSObject");
return Handle<TaggedProto>::fromMarkedLocation(
reinterpret_cast<TaggedProto const*>(obj.address()));
}
/*
* Lazy object groups overview.
*