From fe0bcc3a40dbbc91a26182f01791ba673ea410e8 Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Tue, 14 Feb 2017 16:17:02 -0800 Subject: [PATCH] Bug 1338272 - Require that the return value of MaybeSetPendingException is used. r=bz Most of the time, the return value of this method should be checked, because behavior should depend on whether or not an exception is thrown. However, if it is called immediately after a throw it doesn't need to be checked because it will always return true. bz said there is no public API that lets you assume there is an exception because it would be "too easy to misuse". MozReview-Commit-ID: CqyicBbcNjW --HG-- extra : rebase_source : a5b74ba88a927a90d491ceb8f0b750a67f62b0f4 --- dom/base/WindowNamedPropertiesHandler.cpp | 2 +- dom/bindings/Codegen.py | 2 +- dom/bindings/ErrorResult.h | 1 + dom/bindings/ToJSValue.cpp | 6 ++---- js/xpconnect/wrappers/AccessCheck.cpp | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dom/base/WindowNamedPropertiesHandler.cpp b/dom/base/WindowNamedPropertiesHandler.cpp index ec7b5100038e..59bb0a862960 100644 --- a/dom/base/WindowNamedPropertiesHandler.cpp +++ b/dom/base/WindowNamedPropertiesHandler.cpp @@ -163,7 +163,7 @@ WindowNamedPropertiesHandler::defineProperty(JSContext* aCx, { ErrorResult rv; rv.ThrowTypeError(); - rv.MaybeSetPendingException(aCx); + MOZ_ALWAYS_TRUE(rv.MaybeSetPendingException(aCx)); return false; } diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 64cd5623b521..ec94ecbfc4ab 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -5479,7 +5479,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, do_QueryInterface(promiseGlobal.GetAsSupports()); if (!global) { promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED); - promiseRv.MaybeSetPendingException(cx); + MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx)); $*{exceptionCode} } $${declName} = Promise::Resolve(global, cx, valueToResolve, diff --git a/dom/bindings/ErrorResult.h b/dom/bindings/ErrorResult.h index a0335166917c..e4a1f15ccd6f 100644 --- a/dom/bindings/ErrorResult.h +++ b/dom/bindings/ErrorResult.h @@ -262,6 +262,7 @@ public: // // After this call, the TErrorResult will no longer return true from Failed(), // since the exception will have moved to the JSContext. + MOZ_MUST_USE bool MaybeSetPendingException(JSContext* cx) { WouldReportJSException(); diff --git a/dom/bindings/ToJSValue.cpp b/dom/bindings/ToJSValue.cpp index a94677f27455..addf365f5f5e 100644 --- a/dom/bindings/ToJSValue.cpp +++ b/dom/bindings/ToJSValue.cpp @@ -56,10 +56,8 @@ ToJSValue(JSContext* aCx, MOZ_ASSERT(aArgument.Failed()); MOZ_ASSERT(!aArgument.IsUncatchableException(), "Doesn't make sense to convert uncatchable exception to a JS value!"); - DebugOnly throwResult = aArgument.MaybeSetPendingException(aCx); - MOZ_ASSERT(throwResult); - DebugOnly getPendingResult = JS_GetPendingException(aCx, aValue); - MOZ_ASSERT(getPendingResult); + MOZ_ALWAYS_TRUE(aArgument.MaybeSetPendingException(aCx)); + MOZ_ALWAYS_TRUE(JS_GetPendingException(aCx, aValue)); JS_ClearPendingException(aCx); return true; } diff --git a/js/xpconnect/wrappers/AccessCheck.cpp b/js/xpconnect/wrappers/AccessCheck.cpp index f294f212e932..07599ce7906a 100644 --- a/js/xpconnect/wrappers/AccessCheck.cpp +++ b/js/xpconnect/wrappers/AccessCheck.cpp @@ -320,7 +320,7 @@ AccessCheck::reportCrossOriginDenial(JSContext* cx, JS::HandleId id, } ErrorResult rv; rv.ThrowDOMException(NS_ERROR_DOM_SECURITY_ERR, message); - rv.MaybeSetPendingException(cx); + MOZ_ALWAYS_TRUE(rv.MaybeSetPendingException(cx)); } enum Access { READ = (1<<0), WRITE = (1<<1), NO_ACCESS = 0 };