Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose JS_ToBoolean(), JS_ToNumber(), JS_ToObject(), and JS_SetUncatchableError() #824

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,6 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
static BOOL js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2);
static BOOL js_same_value(JSContext *ctx, JSValue op1, JSValue op2);
static BOOL js_same_value_zero(JSContext *ctx, JSValue op1, JSValue op2);
static JSValue JS_ToObject(JSContext *ctx, JSValue val);
static JSValue JS_ToObjectFree(JSContext *ctx, JSValue val);
static JSProperty *add_property(JSContext *ctx,
JSObject *p, JSAtom prop, int prop_flags);
Expand Down Expand Up @@ -1276,7 +1275,6 @@ static JSValue js_promise_then(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv);
static BOOL js_string_eq(const JSString *p1, const JSString *p2);
static int js_string_compare(const JSString *p1, const JSString *p2);
static JSValue JS_ToNumber(JSContext *ctx, JSValue val);
static int JS_SetPropertyValue(JSContext *ctx, JSValue this_obj,
JSValue prop, JSValue val, int flags);
static int JS_NumberIsInteger(JSContext *ctx, JSValue val);
Expand Down Expand Up @@ -1322,7 +1320,6 @@ static JSValue js_module_ns_autoinit(JSContext *ctx, JSObject *p, JSAtom atom,
void *opaque);
static JSValue JS_InstantiateFunctionListItem2(JSContext *ctx, JSObject *p,
JSAtom atom, void *opaque);
void JS_SetUncatchableError(JSContext *ctx, JSValue val, BOOL flag);

static JSValue js_new_callsite(JSContext *ctx, JSCallSiteData *csd);
static void js_new_callsite_data(JSContext *ctx, JSCallSiteData *csd, JSStackFrame *sf);
Expand Down Expand Up @@ -10763,7 +10760,7 @@ int JS_ToFloat64(JSContext *ctx, double *pres, JSValue val)
return JS_ToFloat64Free(ctx, pres, js_dup(val));
}

static JSValue JS_ToNumber(JSContext *ctx, JSValue val)
JSValue JS_ToNumber(JSContext *ctx, JSValue val)
{
return JS_ToNumberFree(ctx, js_dup(val));
}
Expand Down Expand Up @@ -36242,7 +36239,7 @@ static JSValue js_global_queueMicrotask(JSContext *ctx, JSValue this_val,

/* Object class */

static JSValue JS_ToObject(JSContext *ctx, JSValue val)
JSValue JS_ToObject(JSContext *ctx, JSValue val)
{
int tag = JS_VALUE_GET_NORM_TAG(val);
JSValue obj;
Expand Down
7 changes: 7 additions & 0 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ JS_EXTERN JSValue JS_Throw(JSContext *ctx, JSValue obj);
JS_EXTERN JSValue JS_GetException(JSContext *ctx);
JS_EXTERN JS_BOOL JS_HasException(JSContext *ctx);
JS_EXTERN JS_BOOL JS_IsError(JSContext *ctx, JSValue val);
JS_EXTERN void JS_SetUncatchableError(JSContext *ctx, JSValue val, JS_BOOL flag);
kasperisager marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't PR right away because that conflicts with #821 but IMO flag is too cryptic and should have been called something like is_uncatchable, or have been left out and been replaced with:

JS_EXTERN void JS_SetUncatchableError(JSContext *ctx, JSValue val);
JS_EXTERN void JS_ClearUncatchableError(JSContext *ctx, JSValue val);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do, I'll rebase no problem. Sorry I pulled trigger too quickly 😄

JS_EXTERN JS_BOOL JS_IsUncatchableError(JSContext* ctx, JSValue val);
JS_EXTERN void JS_ResetUncatchableError(JSContext *ctx);
JS_EXTERN JSValue JS_NewError(JSContext *ctx);
Expand All @@ -631,6 +632,11 @@ JS_EXTERN void JS_FreeValueRT(JSRuntime *rt, JSValue v);
JS_EXTERN JSValue JS_DupValue(JSContext *ctx, JSValue v);
JS_EXTERN JSValue JS_DupValueRT(JSRuntime *rt, JSValue v);
JS_EXTERN int JS_ToBool(JSContext *ctx, JSValue val); /* return -1 for JS_EXCEPTION */
static inline JSValue JS_ToBoolean(JSContext *ctx, JSValueConst val)
kasperisager marked this conversation as resolved.
Show resolved Hide resolved
{
return JS_NewBool(ctx, JS_ToBool(ctx, val));
}
JS_EXTERN JSValue JS_ToNumber(JSContext *ctx, JSValueConst val);
kasperisager marked this conversation as resolved.
Show resolved Hide resolved
JS_EXTERN int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValue val);
static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValue val)
{
Expand Down Expand Up @@ -667,6 +673,7 @@ JS_EXTERN JSValue JS_NewObjectProtoClass(JSContext *ctx, JSValue proto, JSClassI
JS_EXTERN JSValue JS_NewObjectClass(JSContext *ctx, int class_id);
JS_EXTERN JSValue JS_NewObjectProto(JSContext *ctx, JSValue proto);
JS_EXTERN JSValue JS_NewObject(JSContext *ctx);
JS_EXTERN JSValue JS_ToObject(JSContext *ctx, JSValueConst val);
kasperisager marked this conversation as resolved.
Show resolved Hide resolved

JS_EXTERN JS_BOOL JS_IsFunction(JSContext* ctx, JSValue val);
JS_EXTERN JS_BOOL JS_IsConstructor(JSContext* ctx, JSValue val);
Expand Down