Bug 1548908: Verify during JS_Init that the hardware NaN is sane r=jwalden

Differential Revision: https://phabricator.services.mozilla.com/D33504

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Iain Ireland 2019-06-11 00:23:41 +00:00
parent 98788f0b1c
commit fcf0aa7f56

View File

@ -62,6 +62,19 @@ static void CheckMessageParameterCounts() {
}
#endif /* DEBUG */
static void CheckCanonicalNaN() {
// Assert that the NaN generated by hardware operations is
// compatible with the canonical NaN we use for JS::Value. This is
// true for all of our supported platforms. If this assertion fails,
// you may need to modify JS::detail::DoubleValueAdjust for your
// platform.
double infinity = mozilla::PositiveInfinity<double>();
double hardwareNaN = infinity - infinity;
uint64_t bits = mozilla::BitwiseCast<uint64_t>(hardwareNaN);
bits &= ~mozilla::FloatingPoint<double>::kSignBit;
MOZ_RELEASE_ASSERT(bits == JS::detail::CanonicalizedNaNBits);
}
#define RETURN_IF_FAIL(code) \
do { \
if (!code) return #code " failed"; \
@ -97,6 +110,7 @@ JS_PUBLIC_API const char* JS::detail::InitWithFailureDiagnostic(
#ifdef DEBUG
CheckMessageParameterCounts();
#endif
CheckCanonicalNaN();
RETURN_IF_FAIL(js::TlsContext.init());