Skip to content

Commit

Permalink
Add JS_ToBigUint64
Browse files Browse the repository at this point in the history
Fixes: #376
  • Loading branch information
saghul committed May 27, 2024
1 parent 569f51f commit 8d46deb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -12009,6 +12009,20 @@ 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)
{
bf_t a_s, *a;

a = JS_ToBigIntFree(ctx, &a_s, js_dup(val));
if (!a) {
*pres = 0;
return -1;
}
bf_get_uint64(pres, a);
JS_FreeBigInt(ctx, a, &a_s);
return 0;
}

static JSValue JS_NewBigInt(JSContext *ctx)
{
JSBigInt *p;
Expand Down
1 change: 1 addition & 0 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,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);

Expand Down

0 comments on commit 8d46deb

Please sign in to comment.