bug 1490387 - Part 2: Implement ToInt32OrBigInt operation. r=jandem

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Robin Templeton 2018-09-18 03:55:45 +00:00
parent 5501a97e65
commit 15d0c6d1af
2 changed files with 35 additions and 0 deletions

View File

@ -1929,6 +1929,29 @@ js::ToInt32Slow(JSContext* cx, const HandleValue v, int32_t* out)
return true;
}
bool
js::ToInt32OrBigIntSlow(JSContext* cx, MutableHandleValue vp)
{
MOZ_ASSERT(!vp.isInt32());
if (vp.isDouble()) {
vp.setInt32(ToInt32(vp.toDouble()));
return true;
}
if (!ToNumeric(cx, vp)) {
return false;
}
#ifdef ENABLE_BIGINT
if (vp.isBigInt()) {
return true;
}
#endif
vp.setInt32(ToInt32(vp.toNumber()));
return true;
}
JS_PUBLIC_API(bool)
js::ToUint32Slow(JSContext* cx, const HandleValue v, uint32_t* out)
{

View File

@ -236,6 +236,18 @@ ToNumeric(JSContext* cx, JS::MutableHandleValue vp)
return ToNumericSlow(cx, vp);
}
bool
ToInt32OrBigIntSlow(JSContext* cx, JS::MutableHandleValue vp);
MOZ_ALWAYS_INLINE MOZ_MUST_USE bool
ToInt32OrBigInt(JSContext* cx, JS::MutableHandleValue vp)
{
if (vp.isInt32()) {
return true;
}
return ToInt32OrBigIntSlow(cx, vp);
}
MOZ_MUST_USE bool
num_parseInt(JSContext* cx, unsigned argc, Value* vp);