Skip to content

Commit

Permalink
Add JS_GetVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Nov 10, 2023
1 parent 38f88c0 commit 55e845c
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 13 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ set(qjs_sources

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})
target_compile_definitions(qjs PUBLIC
QJS_VERSION_STR="${QJS_VERSION_STR}"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ STRIP=$(CROSS_PREFIX)strip
ifdef CONFIG_WERROR
CFLAGS+=-Werror
endif
DEFINES:=-D_GNU_SOURCE -DCONFIG_VERSION=\"$(shell cat VERSION)\"
DEFINES:=-D_GNU_SOURCE
ifdef CONFIG_WIN32
DEFINES+=-D__USE_MINGW_ANSI_STDIO # for standard snprintf behavior
endif
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

4 changes: 2 additions & 2 deletions qjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static const JSMallocFunctions trace_mf = {

void help(void)
{
printf("QuickJS version " CONFIG_VERSION "\n"
printf("QuickJS version %s\n"
"usage: " PROG_NAME " [options] [file [args]]\n"
"-h --help list options\n"
"-e --eval EXPR evaluate EXPR\n"
Expand All @@ -283,7 +283,7 @@ void help(void)
" --memory-limit n limit the memory usage to 'n' bytes\n"
" --stack-size n limit the stack size to 'n' bytes\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);
}

Expand Down
3 changes: 2 additions & 1 deletion qjsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static const char main_c_template2[] =

void help(void)
{
printf("QuickJS Compiler version " CONFIG_VERSION "\n"
printf("QuickJS Compiler version %s\n"
"usage: " PROG_NAME " [options] [files]\n"
"\n"
"options are:\n"
Expand All @@ -353,6 +353,7 @@ void help(void)
"-x byte swapped output\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",
JS_GetVersion(),
JS_DEFAULT_STACK_SIZE);
#ifdef CONFIG_LTO
{
Expand Down
18 changes: 15 additions & 3 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@
#include <errno.h>
#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 {
/* classid tag */ /* union usage | properties */
JS_CLASS_OBJECT = 1, /* must be first */
Expand Down Expand Up @@ -5920,9 +5933,8 @@ void JS_ComputeMemoryUsage(JSRuntime *rt, JSMemoryUsage *s)

void JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt)
{
fprintf(fp, "QuickJS memory usage -- "
CONFIG_VERSION " version, %d-bit, malloc limit: %"PRId64"\n\n",
(int)sizeof(void *) * 8, (int64_t)(ssize_t)s->malloc_limit);
fprintf(fp, "QuickJS memory usage -- %s version, %d-bit, malloc limit: %"PRId64"\n\n",
JS_GetVersion(), (int)sizeof(void *) * 8, (int64_t)(ssize_t)s->malloc_limit);
#if 1
if (rt) {
static const struct {
Expand Down
10 changes: 10 additions & 0 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,16 @@ typedef enum JSPromiseStateEnum {
JSPromiseStateEnum JS_PromiseState(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_force_inline

Expand Down
5 changes: 3 additions & 2 deletions run-test262.c
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ void run_test_dir_list(namelist_t *lp, int start_index, int stop_index)

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"
"-h help\n"
"-a run tests in strict and nostrict modes\n"
Expand All @@ -1962,7 +1962,8 @@ void help(void)
"-e file load the known errors from 'file'\n"
"-f file execute single test from 'file'\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);
}

Expand Down

0 comments on commit 55e845c

Please sign in to comment.