From f9d45f22dbf8dc39104010f6e03da98e435512d2 Mon Sep 17 00:00:00 2001 From: Ben Kuper Date: Tue, 25 Feb 2025 19:12:23 +0100 Subject: [PATCH 1/2] Better type support in QuickJSToJuce --- .../choc/javascript/choc_javascript_QuickJS.h | 10 ++++++++-- .../detail/juce_QuickJSHelpers.h | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/modules/juce_javascript/choc/javascript/choc_javascript_QuickJS.h b/modules/juce_javascript/choc/javascript/choc_javascript_QuickJS.h index 99101236f12a..16ad9aa406c5 100644 --- a/modules/juce_javascript/choc/javascript/choc_javascript_QuickJS.h +++ b/modules/juce_javascript/choc/javascript/choc_javascript_QuickJS.h @@ -8912,7 +8912,13 @@ static inline JS_BOOL JS_IsNumber(JSValueConst v) return tag == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag); } -static inline JS_BOOL JS_IsBigInt(JSContext *ctx, JSValueConst v) +static inline JS_BOOL JS_IsInteger(JSValueConst v) +{ + int tag = JS_VALUE_GET_TAG(v); + return tag == JS_TAG_INT; +} + +static inline JS_BOOL JS_IsBigInt(JSValueConst v) { int tag = JS_VALUE_GET_TAG(v); return tag == JS_TAG_BIG_INT; @@ -20782,7 +20788,7 @@ inline int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val) inline int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val) { - if (JS_IsBigInt(ctx, val)) + if (JS_IsBigInt(val)) return JS_ToBigInt64(ctx, pres, val); else return JS_ToInt64(ctx, pres, val); diff --git a/modules/juce_javascript/detail/juce_QuickJSHelpers.h b/modules/juce_javascript/detail/juce_QuickJSHelpers.h index d8226eb3b0d3..27ff9d4a2ef7 100644 --- a/modules/juce_javascript/detail/juce_QuickJSHelpers.h +++ b/modules/juce_javascript/detail/juce_QuickJSHelpers.h @@ -249,9 +249,22 @@ static var tryQuickJSToJuce (const qjs::QuickJSContext::ValuePtr& ptr, if (JS_IsNumber (ptr.value)) { - double d = 0; - JS_ToFloat64 (ptr.context, std::addressof (d), ptr.value); - return d; + if(JS_IsBigInt(ptr.value)) + { + int64_t i = 0; + JS_ToBigInt64 (ptr.context, std::addressof (i), ptr.value); + return i; + }if(JS_IsInteger(ptr.value)) + { + int32_t i = 0; + JS_ToInt32 (ptr.context, std::addressof (i), ptr.value); + return i; + } + { + double d = 0; + JS_ToFloat64 (ptr.context, std::addressof (d), ptr.value); + return d; + } } if (JS_IsBool (ptr.value)) From 9550c870a21efdde72ac3abdccfe9de638614f08 Mon Sep 17 00:00:00 2001 From: Ben Kuper Date: Tue, 25 Feb 2025 19:37:20 +0100 Subject: [PATCH 2/2] fix linux compil, var ambiguity --- modules/juce_javascript/detail/juce_QuickJSHelpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/juce_javascript/detail/juce_QuickJSHelpers.h b/modules/juce_javascript/detail/juce_QuickJSHelpers.h index 27ff9d4a2ef7..dff3e8a4b4ee 100644 --- a/modules/juce_javascript/detail/juce_QuickJSHelpers.h +++ b/modules/juce_javascript/detail/juce_QuickJSHelpers.h @@ -253,7 +253,7 @@ static var tryQuickJSToJuce (const qjs::QuickJSContext::ValuePtr& ptr, { int64_t i = 0; JS_ToBigInt64 (ptr.context, std::addressof (i), ptr.value); - return i; + return var((juce::int64)i); }if(JS_IsInteger(ptr.value)) { int32_t i = 0;