Commit 9b25a652 authored by Steve Fink's avatar Steve Fink
Browse files

Bug 1685420 - ~nsCOMPtr and related hazard fixes. r=mccr8, a=RyanVM

Differential Revision: https://phabricator.services.mozilla.com/D100966
parent ef2c1d45
......@@ -3885,9 +3885,10 @@ bool Document::HasPendingInitialTranslation() {
DocumentL10n* Document::GetL10n() { return mDocumentL10n; }
 
bool Document::DocumentSupportsL10n(JSContext* aCx, JSObject* aObject) {
JS::Rooted<JSObject*> object(aCx, aObject);
nsCOMPtr<nsIPrincipal> callerPrincipal =
nsContentUtils::SubjectPrincipal(aCx);
nsGlobalWindowInner* win = xpc::WindowOrNull(aObject);
nsGlobalWindowInner* win = xpc::WindowOrNull(object);
bool allowed = false;
callerPrincipal->IsL10nAllowed(win ? win->GetDocumentURI() : nullptr,
&allowed);
......
......@@ -101,20 +101,22 @@ JSObject* GetElementCallback(JSContext* aCx, JS::HandleValue aValue) {
return nullptr;
}
nsCOMPtr<Element> domElement = script->GetFetchOptions()->mElement;
if (!domElement) {
return nullptr;
}
JS::Rooted<JS::Value> elementValue(aCx);
{
nsCOMPtr<Element> domElement = script->GetFetchOptions()->mElement;
if (!domElement) {
return nullptr;
}
JSObject* globalObject =
domElement->OwnerDoc()->GetScopeObject()->GetGlobalJSObject();
JSAutoRealm ar(aCx, globalObject);
JSObject* globalObject =
domElement->OwnerDoc()->GetScopeObject()->GetGlobalJSObject();
JSAutoRealm ar(aCx, globalObject);
JS::Rooted<JS::Value> elementValue(aCx);
nsresult rv = nsContentUtils::WrapNative(aCx, domElement, &elementValue,
/* aAllowWrapping = */ true);
if (NS_FAILED(rv)) {
return nullptr;
nsresult rv = nsContentUtils::WrapNative(aCx, domElement, &elementValue,
/* aAllowWrapping = */ true);
if (NS_FAILED(rv)) {
return nullptr;
}
}
return elementValue.toObjectOrNull();
}
......
......@@ -55,10 +55,11 @@ XPCTraceableVariant::~XPCTraceableVariant() {
Value val = GetJSValPreserveColor();
MOZ_ASSERT(val.isGCThing() || val.isNull(), "Must be traceable or unlinked");
bool unroot = val.isGCThing();
mData.Cleanup();
if (!val.isNull()) {
if (unroot) {
RemoveFromRootSet();
}
}
......@@ -82,10 +83,11 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(XPCVariant)
JS::Value val = tmp->GetJSValPreserveColor();
bool unroot = val.isGCThing();
tmp->mData.Cleanup();
if (val.isGCThing()) {
if (unroot) {
XPCTraceableVariant* v = static_cast<XPCTraceableVariant*>(tmp);
v->RemoveFromRootSet();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment