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(), and JS_ToObject() #339

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 2 additions & 4 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,6 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
static BOOL js_strict_eq(JSContext *ctx, JSValueConst op1, JSValueConst op2);
static BOOL js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst op2);
static BOOL js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValueConst op2);
static JSValue JS_ToObject(JSContext *ctx, JSValueConst 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 @@ -1236,7 +1235,6 @@ static JSValue js_promise_then(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv);
static int js_string_compare(JSContext *ctx,
const JSString *p1, const JSString *p2);
static JSValue JS_ToNumber(JSContext *ctx, JSValueConst val);
static int JS_SetPropertyValue(JSContext *ctx, JSValueConst this_obj,
JSValue prop, JSValue val, int flags);
static int JS_NumberIsInteger(JSContext *ctx, JSValueConst val);
Expand Down Expand Up @@ -10620,7 +10618,7 @@ int JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val)
return JS_ToFloat64Free(ctx, pres, JS_DupValue(ctx, val));
}

static JSValue JS_ToNumber(JSContext *ctx, JSValueConst val)
JSValue JS_ToNumber(JSContext *ctx, JSValueConst val)
{
return JS_ToNumberFree(ctx, JS_DupValue(ctx, val));
}
Expand Down Expand Up @@ -37129,7 +37127,7 @@ static JSValue js_global_isFinite(JSContext *ctx, JSValueConst this_val,

/* Object class */

static JSValue JS_ToObject(JSContext *ctx, JSValueConst val)
JSValue JS_ToObject(JSContext *ctx, JSValueConst val)
{
int tag = JS_VALUE_GET_NORM_TAG(val);
JSValue obj;
Expand Down
6 changes: 6 additions & 0 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,11 @@ JS_BOOL JS_SameValue(JSContext *ctx, JSValueConst op1, JSValueConst op2);
JS_BOOL JS_SameValueZero(JSContext *ctx, JSValueConst op1, JSValueConst op2);

int JS_ToBool(JSContext *ctx, JSValueConst val); /* return -1 for JS_EXCEPTION */
static inline JSValue JS_ToBoolean(JSContext *ctx, JSValueConst val)
{
return JS_NewBool(ctx, JS_ToBool(ctx, val));
}
JSValue JS_ToNumber(JSContext *ctx, JSValueConst val);
int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val);
static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValueConst val)
{
Expand Down Expand Up @@ -722,6 +727,7 @@ JSValue JS_NewObjectProtoClass(JSContext *ctx, JSValueConst proto, JSClassID cla
JSValue JS_NewObjectClass(JSContext *ctx, int class_id);
JSValue JS_NewObjectProto(JSContext *ctx, JSValueConst proto);
JSValue JS_NewObject(JSContext *ctx);
JSValue JS_ToObject(JSContext *ctx, JSValueConst val);

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