mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
Bug 1197973 - Use MOZ_MUST_USE in AutoJSAPI. r=bz.
This commit is contained in:
parent
69d24ba219
commit
2ebfc5116b
@ -14236,7 +14236,10 @@ nsDocShell::SetOriginAttributesBeforeLoading(JS::Handle<JS::Value> aOriginAttrib
|
||||
}
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init(&aOriginAttributes.toObject());
|
||||
if (!jsapi.Init(&aOriginAttributes.toObject())) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
if (NS_WARN_IF(!cx)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -225,11 +225,11 @@ public:
|
||||
// If aGlobalObject represents a web-visible global, errors reported by this
|
||||
// AutoJSAPI as it comes off the stack will fire the relevant error events and
|
||||
// show up in the corresponding web console.
|
||||
bool Init(nsIGlobalObject* aGlobalObject);
|
||||
MOZ_MUST_USE bool Init(nsIGlobalObject* aGlobalObject);
|
||||
|
||||
// This is a helper that grabs the native global associated with aObject and
|
||||
// invokes the above Init() with that.
|
||||
bool Init(JSObject* aObject);
|
||||
MOZ_MUST_USE bool Init(JSObject* aObject);
|
||||
|
||||
// Unsurprisingly, this uses aCx and enters the compartment of aGlobalObject.
|
||||
// If aGlobalObject or its associated JS global are null then it returns
|
||||
@ -239,15 +239,15 @@ public:
|
||||
// If aGlobalObject represents a web-visible global, errors reported by this
|
||||
// AutoJSAPI as it comes off the stack will fire the relevant error events and
|
||||
// show up in the corresponding web console.
|
||||
bool Init(nsIGlobalObject* aGlobalObject, JSContext* aCx);
|
||||
MOZ_MUST_USE bool Init(nsIGlobalObject* aGlobalObject, JSContext* aCx);
|
||||
|
||||
// Convenience functions to take an nsPIDOMWindow* or nsGlobalWindow*,
|
||||
// when it is more easily available than an nsIGlobalObject.
|
||||
bool Init(nsPIDOMWindowInner* aWindow);
|
||||
bool Init(nsPIDOMWindowInner* aWindow, JSContext* aCx);
|
||||
MOZ_MUST_USE bool Init(nsPIDOMWindowInner* aWindow);
|
||||
MOZ_MUST_USE bool Init(nsPIDOMWindowInner* aWindow, JSContext* aCx);
|
||||
|
||||
bool Init(nsGlobalWindow* aWindow);
|
||||
bool Init(nsGlobalWindow* aWindow, JSContext* aCx);
|
||||
MOZ_MUST_USE bool Init(nsGlobalWindow* aWindow);
|
||||
MOZ_MUST_USE bool Init(nsGlobalWindow* aWindow, JSContext* aCx);
|
||||
|
||||
JSContext* cx() const {
|
||||
MOZ_ASSERT(mCx, "Must call Init before using an AutoJSAPI");
|
||||
@ -273,7 +273,7 @@ public:
|
||||
//
|
||||
// Note that this fails if and only if we OOM while wrapping the exception
|
||||
// into the current compartment.
|
||||
bool StealException(JS::MutableHandle<JS::Value> aVal);
|
||||
MOZ_MUST_USE bool StealException(JS::MutableHandle<JS::Value> aVal);
|
||||
|
||||
// Peek the current exception from the JS engine, without stealing it.
|
||||
// Callers must ensure that HasException() is true, and that cx() is in a
|
||||
@ -281,7 +281,7 @@ public:
|
||||
//
|
||||
// Note that this fails if and only if we OOM while wrapping the exception
|
||||
// into the current compartment.
|
||||
bool PeekException(JS::MutableHandle<JS::Value> aVal);
|
||||
MOZ_MUST_USE bool PeekException(JS::MutableHandle<JS::Value> aVal);
|
||||
|
||||
void ClearException() {
|
||||
MOZ_ASSERT(IsStackTop());
|
||||
|
@ -327,7 +327,9 @@ nsresult
|
||||
nsDOMClassInfo::DefineStaticJSVals()
|
||||
{
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init(xpc::UnprivilegedJunkScope());
|
||||
if (!jsapi.Init(xpc::UnprivilegedJunkScope())) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
JSContext* cx = jsapi.cx();
|
||||
|
||||
#define SET_JSID_TO_STRING(_id, _cx, _str) \
|
||||
|
@ -169,9 +169,12 @@ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput,
|
||||
nsContentUtils::IsCallerChrome());
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init(aGlobal);
|
||||
JSContext* cx = jsapi.cx();
|
||||
if (!jsapi.Init(aGlobal)) {
|
||||
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JSObject*> jsGlobal(cx, aGlobal->GetGlobalJSObject());
|
||||
GlobalObject global(cx, jsGlobal);
|
||||
|
||||
@ -1095,9 +1098,12 @@ FetchBody<Derived>::ContinueConsumeBody(nsresult aStatus, uint32_t aResultLength
|
||||
MOZ_ASSERT(aResult);
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init(DerivedClass()->GetParentObject());
|
||||
JSContext* cx = jsapi.cx();
|
||||
if (!jsapi.Init(DerivedClass()->GetParentObject())) {
|
||||
localPromise->MaybeReject(NS_ERROR_UNEXPECTED);
|
||||
return;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
ErrorResult error;
|
||||
|
||||
switch (mConsumeType) {
|
||||
|
@ -261,7 +261,10 @@ nsBrowserElement::Download(const nsAString& aUrl,
|
||||
nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryInterface(mBrowserElementAPI);
|
||||
MOZ_ASSERT(wrappedObj, "Failed to get wrapped JS from XPCOM component.");
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init(wrappedObj->GetJSObject());
|
||||
if (!jsapi.Init(wrappedObj->GetJSObject())) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> options(cx);
|
||||
aRv.MightThrowJSException();
|
||||
@ -714,7 +717,10 @@ nsBrowserElement::ExecuteScript(const nsAString& aScript,
|
||||
nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryInterface(mBrowserElementAPI);
|
||||
MOZ_ASSERT(wrappedObj, "Failed to get wrapped JS from XPCOM component.");
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init(wrappedObj->GetJSObject());
|
||||
if (!jsapi.Init(wrappedObj->GetJSObject())) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> options(cx);
|
||||
aRv.MightThrowJSException();
|
||||
|
@ -1904,8 +1904,11 @@ public:
|
||||
!JS_DefineElement(cx, values, index, value, JSPROP_ENUMERATE)) {
|
||||
MOZ_ASSERT(JS_IsExceptionPending(cx));
|
||||
JS::Rooted<JS::Value> exn(cx);
|
||||
jsapi.StealException(&exn);
|
||||
mPromise->MaybeReject(cx, exn);
|
||||
if (!jsapi.StealException(&exn)) {
|
||||
mPromise->MaybeReject(NS_ERROR_OUT_OF_MEMORY);
|
||||
} else {
|
||||
mPromise->MaybeReject(cx, exn);
|
||||
}
|
||||
}
|
||||
|
||||
--mCountdown;
|
||||
|
@ -43,7 +43,8 @@ WrapperAnswer::fail(AutoJSAPI& jsapi, ReturnStatus* rs)
|
||||
if (!jsapi.HasException())
|
||||
return true;
|
||||
|
||||
jsapi.StealException(&exn);
|
||||
if (!jsapi.StealException(&exn))
|
||||
return true;
|
||||
|
||||
if (JS_IsStopIteration(exn)) {
|
||||
*rs = ReturnStatus(ReturnStopIteration());
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/UniquePtrExtensions.h"
|
||||
#include "mozilla/unused.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::scache;
|
||||
@ -883,7 +884,8 @@ mozJSComponentLoader::ObjectForLocation(ComponentLoaderInfo& aInfo,
|
||||
// exception on this context.
|
||||
if (!script && !function && aPropagateExceptions &&
|
||||
jsapi.HasException()) {
|
||||
jsapi.StealException(aException);
|
||||
if (!jsapi.StealException(aException))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
@ -948,7 +950,9 @@ mozJSComponentLoader::ObjectForLocation(ComponentLoaderInfo& aInfo,
|
||||
|
||||
if (!ok) {
|
||||
if (aPropagateExceptions && aes.HasException()) {
|
||||
aes.StealException(aException);
|
||||
// Ignore return value because we're returning an error code
|
||||
// anyway.
|
||||
Unused << aes.StealException(aException);
|
||||
}
|
||||
aObject.set(nullptr);
|
||||
aTableScript.set(nullptr);
|
||||
|
@ -1786,7 +1786,9 @@ xpc::EvalInSandbox(JSContext* cx, HandleObject sandboxArg, const nsAString& sour
|
||||
|
||||
// If the sandbox threw an exception, grab it off the context.
|
||||
if (aes.HasException()) {
|
||||
aes.StealException(&exn);
|
||||
if (!aes.StealException(&exn)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1273,7 +1273,8 @@ SetAddonInterposition(const nsACString& addonIdStr, nsIAddonInterposition* inter
|
||||
// We enter the junk scope just to allocate a string, which actually will go
|
||||
// in the system zone.
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init(xpc::PrivilegedJunkScope());
|
||||
if (!jsapi.Init(xpc::PrivilegedJunkScope()))
|
||||
return false;
|
||||
addonId = NewAddonId(jsapi.cx(), addonIdStr);
|
||||
if (!addonId)
|
||||
return false;
|
||||
@ -1287,7 +1288,8 @@ AllowCPOWsInAddon(const nsACString& addonIdStr, bool allow)
|
||||
// We enter the junk scope just to allocate a string, which actually will go
|
||||
// in the system zone.
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init(xpc::PrivilegedJunkScope());
|
||||
if (!jsapi.Init(xpc::PrivilegedJunkScope()))
|
||||
return false;
|
||||
addonId = NewAddonId(jsapi.cx(), addonIdStr);
|
||||
if (!addonId)
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user