Add JS_GetVersion

This commit is contained in:
Saúl Ibarra Corretgé 2023-11-10 16:35:09 +01:00
parent 38f88c0898
commit 55e845c5dd
8 changed files with 33 additions and 13 deletions

View file

@ -53,9 +53,6 @@ set(qjs_sources
list(APPEND qjs_defines _GNU_SOURCE) list(APPEND qjs_defines _GNU_SOURCE)
file(STRINGS "VERSION" QJS_VERSION_STR)
list(APPEND qjs_defines CONFIG_VERSION="${QJS_VERSION_STR}")
add_library(qjs STATIC ${qjs_sources}) add_library(qjs STATIC ${qjs_sources})
target_compile_definitions(qjs PUBLIC target_compile_definitions(qjs PUBLIC
QJS_VERSION_STR="${QJS_VERSION_STR}" QJS_VERSION_STR="${QJS_VERSION_STR}"

View file

@ -112,7 +112,7 @@ STRIP=$(CROSS_PREFIX)strip
ifdef CONFIG_WERROR ifdef CONFIG_WERROR
CFLAGS+=-Werror CFLAGS+=-Werror
endif endif
DEFINES:=-D_GNU_SOURCE -DCONFIG_VERSION=\"$(shell cat VERSION)\" DEFINES:=-D_GNU_SOURCE
ifdef CONFIG_WIN32 ifdef CONFIG_WIN32
DEFINES+=-D__USE_MINGW_ANSI_STDIO # for standard snprintf behavior DEFINES+=-D__USE_MINGW_ANSI_STDIO # for standard snprintf behavior
endif endif

View file

@ -1 +0,0 @@
2021-03-27

4
qjs.c
View file

@ -269,7 +269,7 @@ static const JSMallocFunctions trace_mf = {
void help(void) void help(void)
{ {
printf("QuickJS version " CONFIG_VERSION "\n" printf("QuickJS version %s\n"
"usage: " PROG_NAME " [options] [file [args]]\n" "usage: " PROG_NAME " [options] [file [args]]\n"
"-h --help list options\n" "-h --help list options\n"
"-e --eval EXPR evaluate EXPR\n" "-e --eval EXPR evaluate EXPR\n"
@ -283,7 +283,7 @@ void help(void)
" --memory-limit n limit the memory usage to 'n' bytes\n" " --memory-limit n limit the memory usage to 'n' bytes\n"
" --stack-size n limit the stack size to 'n' bytes\n" " --stack-size n limit the stack size to 'n' bytes\n"
" --unhandled-rejection dump unhandled promise rejections\n" " --unhandled-rejection dump unhandled promise rejections\n"
"-q --quit just instantiate the interpreter and quit\n"); "-q --quit just instantiate the interpreter and quit\n", JS_GetVersion());
exit(1); exit(1);
} }

3
qjsc.c
View file

@ -339,7 +339,7 @@ static const char main_c_template2[] =
void help(void) void help(void)
{ {
printf("QuickJS Compiler version " CONFIG_VERSION "\n" printf("QuickJS Compiler version %s\n"
"usage: " PROG_NAME " [options] [files]\n" "usage: " PROG_NAME " [options] [files]\n"
"\n" "\n"
"options are:\n" "options are:\n"
@ -353,6 +353,7 @@ void help(void)
"-x byte swapped output\n" "-x byte swapped output\n"
"-p prefix set the prefix of the generated C names\n" "-p prefix set the prefix of the generated C names\n"
"-S n set the maximum stack size to 'n' bytes (default=%d)\n", "-S n set the maximum stack size to 'n' bytes (default=%d)\n",
JS_GetVersion(),
JS_DEFAULT_STACK_SIZE); JS_DEFAULT_STACK_SIZE);
#ifdef CONFIG_LTO #ifdef CONFIG_LTO
{ {

View file

@ -107,6 +107,19 @@
#include <errno.h> #include <errno.h>
#endif #endif
#define STRINGIFY_(x) #x
#define STRINGIFY(x) STRINGIFY_(x)
#define QJS_VERSION_STRING \
STRINGIFY(QJS_VERSION_MAJOR) "." STRINGIFY(QJS_VERSION_MINOR) "." STRINGIFY(QJS_VERSION_PATCH) QJS_VERSION_SUFFIX
const char* JS_GetVersion(void) {
return QJS_VERSION_STRING;
}
#undef STRINFIGY_
#undef STRINGIFY
enum { enum {
/* classid tag */ /* union usage | properties */ /* classid tag */ /* union usage | properties */
JS_CLASS_OBJECT = 1, /* must be first */ JS_CLASS_OBJECT = 1, /* must be first */
@ -5920,9 +5933,8 @@ void JS_ComputeMemoryUsage(JSRuntime *rt, JSMemoryUsage *s)
void JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt) void JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt)
{ {
fprintf(fp, "QuickJS memory usage -- " fprintf(fp, "QuickJS memory usage -- %s version, %d-bit, malloc limit: %"PRId64"\n\n",
CONFIG_VERSION " version, %d-bit, malloc limit: %"PRId64"\n\n", JS_GetVersion(), (int)sizeof(void *) * 8, (int64_t)(ssize_t)s->malloc_limit);
(int)sizeof(void *) * 8, (int64_t)(ssize_t)s->malloc_limit);
#if 1 #if 1
if (rt) { if (rt) {
static const struct { static const struct {

View file

@ -1009,6 +1009,16 @@ typedef enum JSPromiseStateEnum {
JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValue promise); JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValue promise);
JSValue JS_PromiseResult(JSContext *ctx, JSValue promise); JSValue JS_PromiseResult(JSContext *ctx, JSValue promise);
/* Version */
#define QJS_VERSION_MAJOR 0
#define QJS_VERSION_MINOR 1
#define QJS_VERSION_PATCH 0
#define QJS_VERSION_SUFFIX ""
const char* JS_GetVersion(void);
#undef js_unlikely #undef js_unlikely
#undef js_force_inline #undef js_force_inline

View file

@ -1945,7 +1945,7 @@ void run_test_dir_list(namelist_t *lp, int start_index, int stop_index)
void help(void) void help(void)
{ {
printf("run-test262 version " CONFIG_VERSION "\n" printf("run-test262 version %s\n"
"usage: run-test262 [options] {-f file ... | [dir_list] [index range]}\n" "usage: run-test262 [options] {-f file ... | [dir_list] [index range]}\n"
"-h help\n" "-h help\n"
"-a run tests in strict and nostrict modes\n" "-a run tests in strict and nostrict modes\n"
@ -1962,7 +1962,8 @@ void help(void)
"-e file load the known errors from 'file'\n" "-e file load the known errors from 'file'\n"
"-f file execute single test from 'file'\n" "-f file execute single test from 'file'\n"
"-r file set the report file name (default=none)\n" "-r file set the report file name (default=none)\n"
"-x file exclude tests listed in 'file'\n"); "-x file exclude tests listed in 'file'\n",
JS_GetVersion());
exit(1); exit(1);
} }