From e5673a8e6885907b43418ec57070422a1c51c461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Mon, 27 May 2024 10:10:30 +0200 Subject: [PATCH] Add JS_ToBigUint64 Fixes: https://github.com/quickjs-ng/quickjs/issues/376 --- quickjs.c | 5 +++++ quickjs.h | 1 + 2 files changed, 6 insertions(+) diff --git a/quickjs.c b/quickjs.c index 085037e8..946819ce 100644 --- a/quickjs.c +++ b/quickjs.c @@ -12026,6 +12026,11 @@ int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValue val) return JS_ToBigInt64Free(ctx, pres, js_dup(val)); } +int JS_ToBigUint64(JSContext *ctx, uint64_t *pres, JSValue val) +{ + return JS_ToBigInt64Free(ctx, (int64_t *)pres, js_dup(val)); +} + static JSValue JS_NewBigInt(JSContext *ctx) { JSBigInt *p; diff --git a/quickjs.h b/quickjs.h index d44ebbc9..a79a688d 100644 --- a/quickjs.h +++ b/quickjs.h @@ -638,6 +638,7 @@ JS_EXTERN int JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValue val); JS_EXTERN int JS_ToFloat64(JSContext *ctx, double *pres, JSValue val); /* return an exception if 'val' is a Number */ JS_EXTERN int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValue val); +JS_EXTERN int JS_ToBigUint64(JSContext *ctx, uint64_t *pres, JSValue val); /* same as JS_ToInt64() but allow BigInt */ JS_EXTERN int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValue val);