Bug 774633 - Assert against switching origins on a compartment. r=jst

This commit is contained in:
Bobby Holley 2012-08-23 16:44:53 -07:00
Родитель 38274fd965
Коммит fb072823ff
2 изменённых файлов: 21 добавлений и 5 удалений

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

@ -1884,7 +1884,15 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
// match the new document.
// NB: We don't just call currentInner->RefreshCompartmentPrincipals() here
// because we haven't yet set its mDoc to aDocument.
JS_SetCompartmentPrincipals(js::GetObjectCompartment(currentInner->mJSObject),
JSCompartment *compartment = js::GetObjectCompartment(currentInner->mJSObject);
#ifdef DEBUG
bool sameOrigin = false;
nsIPrincipal *existing =
nsJSPrincipals::get(JS_GetCompartmentPrincipals(compartment));
aDocument->NodePrincipal()->Equals(existing, &sameOrigin);
MOZ_ASSERT(sameOrigin);
#endif
JS_SetCompartmentPrincipals(compartment,
nsJSPrincipals::get(aDocument->NodePrincipal()));
} else {
if (aState) {

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

@ -196,10 +196,20 @@ JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals
if (principals == compartment->principals)
return;
// Any compartment with the trusted principals -- and there can be
// multiple -- is a system compartment.
JSPrincipals *trusted = compartment->rt->trustedPrincipals();
bool isSystem = principals && principals == trusted;
// Clear out the old principals, if any.
if (compartment->principals) {
JS_DropPrincipals(compartment->rt, compartment->principals);
compartment->principals = NULL;
// We'd like to assert that our new principals is always same-origin
// with the old one, but JSPrincipals doesn't give us a way to do that.
// But we can at least assert that we're not switching between system
// and non-system.
JS_ASSERT(compartment->isSystemCompartment == isSystem);
}
// Set up the new principals.
@ -208,10 +218,8 @@ JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals
compartment->principals = principals;
}
// Any compartment with the trusted principals -- and there can be
// multiple -- is a system compartment.
JSPrincipals *trusted = compartment->rt->trustedPrincipals();
compartment->isSystemCompartment = principals && principals == trusted;
// Update the system flag.
compartment->isSystemCompartment = isSystem;
}
JS_FRIEND_API(JSBool)