applied bug1363963.diff

This commit is contained in:
2018-07-12 13:38:26 +08:00
parent d8eb9802e4
commit 3732e21fcd
2 changed files with 19 additions and 10 deletions
+18 -9
View File
@@ -884,7 +884,7 @@ XrayTraits::expandoObjectMatchesConsumer(JSContext* cx,
}
bool
XrayTraits::getExpandoObjectInternal(JSContext* cx, HandleObject target,
XrayTraits::getExpandoObjectInternal(JSContext* cx, JSObject* expandoChain,
nsIPrincipal* origin,
JSObject* exclusiveGlobalArg,
MutableHandleObject expandoObject)
@@ -895,12 +895,12 @@ XrayTraits::getExpandoObjectInternal(JSContext* cx, HandleObject target,
// The expando object lives in the compartment of the target, so all our
// work needs to happen there.
RootedObject exclusiveGlobal(cx, exclusiveGlobalArg);
JSAutoCompartment ac(cx, target);
RootedObject head(cx, expandoChain);
JSAutoCompartment ac(cx, head);
if (!JS_WrapObject(cx, &exclusiveGlobal))
return false;
// Iterate through the chain, looking for a same-origin object.
RootedObject head(cx, getExpandoChain(target));
while (head) {
if (expandoObjectMatchesConsumer(cx, head, origin, exclusiveGlobal)) {
expandoObject.set(head);
@@ -917,9 +917,15 @@ bool
XrayTraits::getExpandoObject(JSContext* cx, HandleObject target, HandleObject consumer,
MutableHandleObject expandoObject)
{
// Return early if no expando object has ever been attached, which is
// usually the case.
JSObject* chain = getExpandoChain(target);
if (!chain)
return true;
JSObject* consumerGlobal = js::GetGlobalForObjectCrossCompartment(consumer);
bool isSandbox = !strcmp(js::GetObjectJSClass(consumerGlobal)->name, "Sandbox");
return getExpandoObjectInternal(cx, target, ObjectPrincipal(consumer),
return getExpandoObjectInternal(cx, chain, ObjectPrincipal(consumer),
isSandbox ? consumerGlobal : nullptr,
expandoObject);
}
@@ -935,11 +941,14 @@ XrayTraits::attachExpandoObject(JSContext* cx, HandleObject target,
// No duplicates allowed.
#ifdef DEBUG
{
RootedObject existingExpandoObject(cx);
if (getExpandoObjectInternal(cx, target, origin, exclusiveGlobal, &existingExpandoObject))
MOZ_ASSERT(!existingExpandoObject);
else
JS_ClearPendingException(cx);
JSObject* chain = getExpandoChain(target);
if (chain) {
RootedObject existingExpandoObject(cx);
if (getExpandoObjectInternal(cx, chain, origin, exclusiveGlobal, &existingExpandoObject))
MOZ_ASSERT(!existingExpandoObject);
else
JS_ClearPendingException(cx);
}
}
#endif
+1 -1
View File
@@ -97,7 +97,7 @@ private:
bool expandoObjectMatchesConsumer(JSContext* cx, JS::HandleObject expandoObject,
nsIPrincipal* consumerOrigin,
JS::HandleObject exclusiveGlobal);
bool getExpandoObjectInternal(JSContext* cx, JS::HandleObject target,
bool getExpandoObjectInternal(JSContext* cx, JSObject* expandoChain,
nsIPrincipal* origin, JSObject* exclusiveGlobal,
JS::MutableHandleObject expandoObject);
JSObject* attachExpandoObject(JSContext* cx, JS::HandleObject target,