Skip to content

Commit

Permalink
quickjs: add APIs to facilitate polymorphism
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Nov 10, 2023
1 parent 88ac91e commit c6d9ebc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions deps/quickjs/include/quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ JSValue __js_printf_like(2, 3) JS_ThrowReferenceError(JSContext *ctx, const char
JSValue __js_printf_like(2, 3) JS_ThrowRangeError(JSContext *ctx, const char *fmt, ...);
JSValue __js_printf_like(2, 3) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...);
JSValue JS_ThrowOutOfMemory(JSContext *ctx);
JSValue JS_ThrowTypeErrorInvalidClass(JSContext *ctx, JSClassID class_id);

void __JS_FreeValue(JSContext *ctx, JSValue v);
static inline void JS_FreeValue(JSContext *ctx, JSValue v)
Expand Down Expand Up @@ -805,6 +806,7 @@ int JS_DefinePropertyGetSet(JSContext *ctx, JSValueConst this_obj,
void JS_SetOpaque(JSValue obj, void *opaque);
void *JS_GetOpaque(JSValueConst obj, JSClassID class_id);
void *JS_GetOpaque2(JSContext *ctx, JSValueConst obj, JSClassID class_id);
void *JS_GetAnyOpaque(JSValueConst obj, JSClassID *class_id);

/* 'buf' must be zero terminated i.e. buf[buf_len] = '\0'. */
JSValue JS_ParseJSON(JSContext *ctx, const char *buf, size_t buf_len,
Expand Down
14 changes: 13 additions & 1 deletion deps/quickjs/src/quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6779,7 +6779,7 @@ static JSValue JS_ThrowReferenceErrorUninitialized2(JSContext *ctx,
return JS_ThrowReferenceErrorUninitialized(ctx, atom);
}

static JSValue JS_ThrowTypeErrorInvalidClass(JSContext *ctx, int class_id)
JSValue JS_ThrowTypeErrorInvalidClass(JSContext *ctx, JSClassID class_id)
{
JSRuntime *rt = ctx->rt;
JSAtom name;
Expand Down Expand Up @@ -9831,6 +9831,18 @@ void *JS_GetOpaque2(JSContext *ctx, JSValueConst obj, JSClassID class_id)
return p;
}

void *JS_GetAnyOpaque(JSValueConst obj, JSClassID *class_id)
{
JSObject *p;
if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) {
*class_id = 0;
return NULL;
}
p = JS_VALUE_GET_OBJ(obj);
*class_id = p->class_id;
return p->u.opaque;
}

#define HINT_STRING 0
#define HINT_NUMBER 1
#define HINT_NONE 2
Expand Down

0 comments on commit c6d9ebc

Please sign in to comment.