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

Add JS_GetVersion() #296

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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ CFLAGS+=-fwrapv # ensure that signed overflows behave as expected
ifdef CONFIG_WERROR
CFLAGS+=-Werror
endif
DEFINES:=-D_GNU_SOURCE -DCONFIG_VERSION=\"$(shell cat VERSION)\"
DEFINES:=-D_GNU_SOURCE -DCONFIG_VERSION=\"$(shell grep JS_VERSION_STR quickjs.h | sed -e 's#.*"\(.*\)".*#\1#')\"
ifdef CONFIG_BIGNUM
DEFINES+=-DCONFIG_BIGNUM
endif
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

15 changes: 15 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,21 @@ static const JSClassExoticMethods js_proxy_exotic_methods;
static const JSClassExoticMethods js_module_ns_exotic_methods;
static JSClassID js_class_id_alloc = JS_CLASS_INIT_COUNT;

const char* JS_GetVersion(void)
{
#define JS_STRINGIFY_(x) #x
#define JS_STRINGIFY(x) JS_STRINGIFY_(x)

return JS_VERSION_STR
#ifdef JS_VERSION_SUFFIX
"-" JS_STRINGIFY(JS_VERSION_SUFFIX)
#endif
;

#undef JS_STRINGIFY
#undef JS_STRINGIFY_
}

static void js_trigger_gc(JSRuntime *rt, size_t size)
{
BOOL force_gc;
Expand Down
9 changes: 9 additions & 0 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
extern "C" {
#endif

#define JS_MKVERSION(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
#define JS_VERSION JS_MKVERSION(0, 5, 0)
#define JS_VERSION_STR "0.5.0"
#define JS_VERSION_MAJOR(v) (((v) >> 16))
#define JS_VERSION_MINOR(v) (((v) >> 8) & 0xff)
#define JS_VERSION_PATCH(v) ((v) & 0xff)

const char *JS_GetVersion(void);

#if defined(__GNUC__) || defined(__clang__)
#define js_likely(x) __builtin_expect(!!(x), 1)
#define js_unlikely(x) __builtin_expect(!!(x), 0)
Expand Down
Loading