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
This commit is contained in:
Andrew McCreight 2017-02-14 16:17:02 -08:00
Родитель 5514aa1c8b
Коммит fe0bcc3a40
5 изменённых файлов: 6 добавлений и 7 удалений

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

@ -163,7 +163,7 @@ WindowNamedPropertiesHandler::defineProperty(JSContext* aCx,
{
ErrorResult rv;
rv.ThrowTypeError<MSG_DEFINEPROPERTY_ON_GSP>();
rv.MaybeSetPendingException(aCx);
MOZ_ALWAYS_TRUE(rv.MaybeSetPendingException(aCx));
return false;
}

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

@ -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,

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

@ -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();

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

@ -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<bool> throwResult = aArgument.MaybeSetPendingException(aCx);
MOZ_ASSERT(throwResult);
DebugOnly<bool> 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;
}

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

@ -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 };