From 93a10f9e2f4e3480a9b89eb820c92b6c5b68dc24 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Wed, 19 Jul 2023 02:17:04 -0500 Subject: Issue #1240 - Part 5a - BigInt to Number conversion. https://bugzilla.mozilla.org/show_bug.cgi?id=1466893 --- js/src/jsnum.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'js/src/jsnum.h') diff --git a/js/src/jsnum.h b/js/src/jsnum.h index f169a9c38d..295d237c22 100644 --- a/js/src/jsnum.h +++ b/js/src/jsnum.h @@ -362,6 +362,20 @@ ToNumber(ExclusiveContext* cx, HandleValue v, double* out) return ToNumberSlow(cx, v, out); } +bool +ToNumericSlow(ExclusiveContext* cx, JS::MutableHandleValue vp); + +// BigInt proposal section 3.1.6 +MOZ_ALWAYS_INLINE MOZ_MUST_USE bool +ToNumeric(ExclusiveContext* cx, JS::MutableHandleValue vp) +{ + if (vp.isNumber()) + return true; + if (vp.isBigInt()) + return true; + return ToNumericSlow(cx, vp); +} + void FIX_FPU(); } /* namespace js */ -- cgit v1.2.3 From a816a6b6de15a851554790ff7b84a4669959327e Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Wed, 19 Jul 2023 03:00:43 -0500 Subject: Issue #1240 - Part 5c -Implement ToInt32OrBigInt operation. https://bugzilla.mozilla.org/show_bug.cgi?id=1490387 --- js/src/jsnum.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'js/src/jsnum.h') 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 */ -- cgit v1.2.3 From 2b198142f021e33ca5a6bef52abc04b95042fb33 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Wed, 19 Jul 2023 16:36:58 -0500 Subject: Issue #1240 - Part 6b - Use ToIndex when constructing TypedArray with length argument. https://bugzilla.mozilla.org/show_bug.cgi?id=1317383 Part 2. --- js/src/jsnum.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'js/src/jsnum.h') diff --git a/js/src/jsnum.h b/js/src/jsnum.h index 9866a91eeb..bd53fdc1a0 100644 --- a/js/src/jsnum.h +++ b/js/src/jsnum.h @@ -308,6 +308,15 @@ MOZ_MUST_USE bool ToLengthClamped(T* cx, HandleValue v, uint32_t* out, bool* ove */ MOZ_MUST_USE bool ToIntegerIndex(JSContext* cx, JS::HandleValue v, uint64_t* index); +/* ES2017 draft 7.1.17 ToIndex + * + * Return true and set |*index| to the integer value if |v| is a valid + * integer index value. Otherwise report a RangeError and return false. + * + * The returned index will always be in the range 0 <= *index <= 2^53-1. + */ +MOZ_MUST_USE bool ToIndex(JSContext* cx, JS::HandleValue v, uint64_t* index); + MOZ_MUST_USE inline bool SafeAdd(int32_t one, int32_t two, int32_t* res) { -- cgit v1.2.3 From 1edc4e41d3d4fd1f3bd9886cba0c0e38b24c194b Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Tue, 25 Jul 2023 01:41:42 -0500 Subject: Issue #2026 - Part 2a - Support BigInt in NumberFormat and toLocaleString. https://bugzilla.mozilla.org/show_bug.cgi?id=1543677 --- js/src/jsnum.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'js/src/jsnum.h') diff --git a/js/src/jsnum.h b/js/src/jsnum.h index bd53fdc1a0..ee07d0a35d 100644 --- a/js/src/jsnum.h +++ b/js/src/jsnum.h @@ -378,10 +378,9 @@ ToNumericSlow(ExclusiveContext* cx, JS::MutableHandleValue vp); MOZ_ALWAYS_INLINE MOZ_MUST_USE bool ToNumeric(ExclusiveContext* cx, JS::MutableHandleValue vp) { - if (vp.isNumber()) - return true; - if (vp.isBigInt()) + if (vp.isNumeric()) { return true; + } return ToNumericSlow(cx, vp); } -- cgit v1.2.3