Add JS_GetVersion()

This commit is contained in:
Dmitry Volyntsev 2024-05-09 18:31:53 -07:00
parent d378a9f3a5
commit e4495dbd88
4 changed files with 25 additions and 2 deletions

View File

@ -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

View File

@ -1 +0,0 @@
2024-02-14

View File

@ -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;

View File

@ -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)