summaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
authorBrian Smith <brian@dbsoft.org>2023-07-19 03:00:43 -0500
committerBrian Smith <brian@dbsoft.org>2023-07-19 03:00:43 -0500
commita816a6b6de15a851554790ff7b84a4669959327e (patch)
treef3e66be6eb1dfa61ce794f661718dc2de8c0a66e /js/src
parent37e02a4bd459f4c6def492230a9b50cf4c3fdf4a (diff)
downloaduxp-a816a6b6de15a851554790ff7b84a4669959327e.tar.gz
Issue #1240 - Part 5c -Implement ToInt32OrBigInt operation.
https://bugzilla.mozilla.org/show_bug.cgi?id=1490387
Diffstat (limited to 'js/src')
-rw-r--r--js/src/jsnum.cpp21
-rw-r--r--js/src/jsnum.h12
2 files changed, 33 insertions, 0 deletions
diff --git a/js/src/jsnum.cpp b/js/src/jsnum.cpp
index c64a1149f0..b778c8d739 100644
--- a/js/src/jsnum.cpp
+++ b/js/src/jsnum.cpp
@@ -1614,6 +1614,27 @@ 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;
+ }
+
+ if (vp.isBigInt()) {
+ return true;
+ }
+
+ vp.setInt32(ToInt32(vp.toNumber()));
+ return true;
+}
+
JS_PUBLIC_API(bool)
js::ToUint32Slow(JSContext* cx, const HandleValue v, uint32_t* out)
{
diff --git a/js/src/jsnum.h b/js/src/jsnum.h
index 295d237c22..9866a91eeb 100644
--- a/js/src/jsnum.h
+++ b/js/src/jsnum.h
@@ -376,6 +376,18 @@ ToNumeric(ExclusiveContext* 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);
+}
+
void FIX_FPU();
} /* namespace js */