Skip to content

Add method to GetClassID #275

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

Merged
merged 2 commits into from
Feb 20, 2024
Merged
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
9 changes: 9 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3344,6 +3344,15 @@ JSClassID JS_NewClassID(JSRuntime *rt, JSClassID *pclass_id)
return class_id;
}

JSClassID JS_GetClassID(JSValue v)
{
JSObject *p;
if (JS_VALUE_GET_TAG(v) != JS_TAG_OBJECT)
return JS_INVALID_CLASS_ID;
p = JS_VALUE_GET_OBJ(v);
return p->class_id;
}

BOOL JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id)
{
return (class_id < rt->class_count &&
Expand Down
3 changes: 3 additions & 0 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,10 @@ typedef struct JSClassDef {
JSClassExoticMethods *exotic;
} JSClassDef;

#define JS_INVALID_CLASS_ID 0
JS_EXTERN JSClassID JS_NewClassID(JSRuntime *rt, JSClassID *pclass_id);
/* Returns the class ID if `v` is an object, otherwise returns JS_INVALID_CLASS_ID. */
JS_EXTERN JSClassID JS_GetClassID(JSValue v);
JS_EXTERN int JS_NewClass(JSRuntime *rt, JSClassID class_id, const JSClassDef *class_def);
JS_EXTERN int JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id);

Expand Down