Commit acca5aaa authored by Steve Fink's avatar Steve Fink
Browse files

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

Differential Revision: https://phabricator.services.mozilla.com/D100966
parent f2e0b70c
......@@ -4191,9 +4191,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);
......
......@@ -44,20 +44,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();
}
......
......@@ -77,13 +77,13 @@ static JSLinearString* GetNameIfLatin1(jsid id) {
return nullptr;
}
static JSObject* GetService(JSContext* cx, const xpcom::JSServiceEntry& service,
ErrorResult& aRv) {
static bool GetServiceImpl(JSContext* cx, const xpcom::JSServiceEntry& service,
JS::MutableHandleObject aObj, ErrorResult& aRv) {
nsresult rv;
nsCOMPtr<nsISupports> inst = service.Module().GetService(&rv);
if (!inst) {
aRv.Throw(rv);
return nullptr;
return false;
}
auto ifaces = service.Interfaces();
......@@ -94,7 +94,8 @@ static JSObject* GetService(JSContext* cx, const xpcom::JSServiceEntry& service,
// its own wrapping, and there's nothing to do. In the latter case, we want
// to unwrap the underlying JS object.
if (nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS = do_QueryInterface(inst)) {
return wrappedJS->GetJSObject();
aObj.set(wrappedJS->GetJSObject());
return !!aObj;
}
}
......@@ -106,7 +107,7 @@ static JSObject* GetService(JSContext* cx, const xpcom::JSServiceEntry& service,
/* allowNativeWrapper */ true,
&rv)) {
aRv.Throw(rv);
return nullptr;
return false;
}
if (ifaces.Length() > 1) {
......@@ -119,7 +120,17 @@ static JSObject* GetService(JSContext* cx, const xpcom::JSServiceEntry& service,
}
}
return &val.toObject();
aObj.set(&val.toObject());
return true;
}
static JSObject* GetService(JSContext* cx, const xpcom::JSServiceEntry& service,
ErrorResult& aRv) {
JS::RootedObject obj(cx);
if (!GetServiceImpl(cx, service, &obj, aRv)) {
return nullptr;
}
return obj;
}
static bool Services_Resolve(JSContext* cx, HandleObject obj, HandleId id,
......
......@@ -57,10 +57,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();
}
}
......@@ -84,10 +85,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();
}
......
Supports Markdown
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