Bug 1404107 - Refactor: Move some reparenting complexity into XPConnect. r=mrbkap,r=bz

--HG--
extra : rebase_source : 817ef532b2fe67bc901339aa19d84bf571adfc71
This commit is contained in:
Jason Orendorff 2017-10-05 11:49:43 -05:00
Родитель 516635f978
Коммит 65e620a4eb
5 изменённых файлов: 26 добавлений и 32 удалений

Просмотреть файл

@ -2259,11 +2259,6 @@ ReparentWrapper(JSContext* aCx, JS::Handle<JSObject*> aObjArg, ErrorResult& aErr
propertyHolder = nullptr;
}
// Grab a reference to the chain of objects that carry aObj's Xray expando
// properties (from all compartments). Transplanting will blow this away;
// we'll restore it manually afterwards.
JS::Rooted<JSObject*> expandoChain(aCx, xpc::XrayUtils::GetExpandoChain(aObj));
// We've set up |newobj|, so we make it own the native by setting its reserved
// slot and nulling out the reserved slot of |obj|.
//
@ -2274,19 +2269,11 @@ ReparentWrapper(JSContext* aCx, JS::Handle<JSObject*> aObjArg, ErrorResult& aErr
js::GetReservedSlot(aObj, DOM_OBJECT_SLOT));
js::SetReservedSlot(aObj, DOM_OBJECT_SLOT, JS::PrivateValue(nullptr));
aObj = xpc::TransplantObject(aCx, aObj, newobj);
aObj = xpc::TransplantObjectRetainingXrayExpandos(aCx, aObj, newobj);
if (!aObj) {
MOZ_CRASH();
}
// Copy Xray expando properties to the new wrapper.
if (!xpc::XrayUtils::CloneExpandoChain(aCx, aObj, expandoChain)) {
// Failure here means some expandos were not copied over. The object graph
// and the Xray machinery are left in a consistent state, but mysteriously
// losing these expandos is too weird to allow.
MOZ_CRASH();
}
nsWrapperCache* cache = nullptr;
CallQueryInterface(native, &cache);
bool preserving = cache->PreservingWrapper();

Просмотреть файл

@ -77,6 +77,9 @@ private:
JSObject*
TransplantObject(JSContext* cx, JS::HandleObject origobj, JS::HandleObject target);
JSObject*
TransplantObjectRetainingXrayExpandos(JSContext* cx, JS::HandleObject origobj, JS::HandleObject target);
bool IsContentXBLCompartment(JSCompartment* compartment);
bool IsContentXBLScope(JS::Realm* realm);
bool IsInContentXBLScope(JSObject* obj);

Просмотреть файл

@ -682,6 +682,28 @@ TransplantObject(JSContext* cx, JS::HandleObject origobj, JS::HandleObject targe
return newIdentity;
}
JSObject*
TransplantObjectRetainingXrayExpandos(JSContext* cx, JS::HandleObject origobj,
JS::HandleObject target)
{
// Save the chain of objects that carry origobj's Xray expando properties
// (from all compartments). TransplantObject will blow this away; we'll
// restore it manually afterwards.
RootedObject expandoChain(cx, GetXrayTraits(origobj)->getExpandoChain(origobj));
RootedObject newIdentity(cx, TransplantObject(cx, origobj, target));
// Copy Xray expando properties to the new wrapper.
if (!GetXrayTraits(newIdentity)->cloneExpandoChain(cx, newIdentity, expandoChain)) {
// Failure here means some expandos were not copied over. The object graph
// and the Xray machinery are left in a consistent state, but mysteriously
// losing these expandos is too weird to allow.
MOZ_CRASH();
}
return newIdentity;
}
nsIGlobalObject*
NativeGlobal(JSObject* obj)
{

Просмотреть файл

@ -1299,18 +1299,6 @@ XrayTraits::getExpandoClass(JSContext* cx, HandleObject target) const
return &DefaultXrayExpandoObjectClass;
}
namespace XrayUtils {
JSObject* GetExpandoChain(HandleObject target)
{
return GetXrayTraits(target)->getExpandoChain(target);
}
bool CloneExpandoChain(JSContext* cx, HandleObject dst, HandleObject srcChain)
{
return GetXrayTraits(dst)->cloneExpandoChain(cx, dst, srcChain);
}
} // namespace XrayUtils
static JSObject*
GetHolder(JSObject* obj)
{

Просмотреть файл

@ -38,12 +38,6 @@ namespace XrayUtils {
bool
IsXPCWNHolderClass(const JSClass* clasp);
JSObject*
GetExpandoChain(JS::HandleObject target);
bool
CloneExpandoChain(JSContext* cx, JS::HandleObject dst, JS::HandleObject srcChain);
bool
IsTransparent(JSContext* cx, JS::HandleObject wrapper, JS::HandleId id);