Skip to content

Commit e62fd75

Browse files
committed
Add compile-time refcount bug hunt build mode
Reintroduce JSValueConst and add a JS_CHECK_JSVALUE build mode that catches reference counting bugs by making JSValue and JSValueConst different types. The *vast* majority of this commit is rote work to make our own sources compile cleanly in said mode. Refs: #944
1 parent 857c42b commit e62fd75

File tree

9 files changed

+1808
-1707
lines changed

9 files changed

+1808
-1707
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,11 @@ jobs:
592592
- name: test
593593
run: |
594594
make test RUN262=$RUNNER_TEMP/run-test262
595+
596+
jscheck:
597+
runs-on: ubuntu-latest
598+
steps:
599+
- uses: actions/checkout@v4
600+
- name: jscheck
601+
run: |
602+
make jscheck

Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ distclean:
9090
stats: $(QJS)
9191
$(QJS) -qd
9292

93+
jscheck: CFLAGS=-I. -D_GNU_SOURCE -DJS_CHECK_JSVALUE -Wall -Werror -fsyntax-only -c -o /dev/null
94+
jscheck:
95+
$(CC) $(CFLAGS) api-test.c
96+
$(CC) $(CFLAGS) ctest.c
97+
$(CC) $(CFLAGS) fuzz.c
98+
$(CC) $(CFLAGS) gen/function_source.c
99+
$(CC) $(CFLAGS) gen/hello.c
100+
$(CC) $(CFLAGS) gen/hello_module.c
101+
$(CC) $(CFLAGS) gen/repl.c
102+
$(CC) $(CFLAGS) gen/standalone.c
103+
$(CC) $(CFLAGS) gen/test_fib.c
104+
$(CC) $(CFLAGS) qjs.c
105+
$(CC) $(CFLAGS) qjsc.c
106+
$(CC) $(CFLAGS) quickjs-libc.c
107+
$(CC) $(CFLAGS) quickjs.c
108+
$(CC) $(CFLAGS) run-test262.c
109+
93110
# effectively .PHONY because it doesn't generate output
94111
ctest: CFLAGS=-std=c11 -fsyntax-only -Wall -Wextra -Werror -pedantic
95112
ctest: ctest.c quickjs.h
@@ -126,4 +143,4 @@ unicode_gen: $(BUILD_DIR)
126143
libunicode-table.h: unicode_gen
127144
$(BUILD_DIR)/unicode_gen unicode $@
128145

129-
.PHONY: all amalgam ctest cxxtest debug fuzz install clean codegen distclean stats test test262 test262-update test262-check microbench unicode_gen $(QJS) $(QJSC)
146+
.PHONY: all amalgam ctest cxxtest debug fuzz jscheck install clean codegen distclean stats test test262 test262-update test262-check microbench unicode_gen $(QJS) $(QJSC)

api-test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ static void async_call(void)
7474
JS_FreeRuntime(rt);
7575
}
7676

77-
static JSValue save_value(JSContext *ctx, JSValue this_val, int argc, JSValue *argv)
77+
static JSValue save_value(JSContext *ctx, JSValueConst this_val,
78+
int argc, JSValueConst *argv)
7879
{
7980
assert(argc == 1);
8081
JSValue *p = (JSValue *)JS_GetContextOpaque(ctx);

qjs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ static int64_t parse_limit(const char *arg) {
199199
return (int64_t)(d * unit);
200200
}
201201

202-
static JSValue js_gc(JSContext *ctx, JSValue this_val,
203-
int argc, JSValue *argv)
202+
static JSValue js_gc(JSContext *ctx, JSValueConst this_val,
203+
int argc, JSValueConst *argv)
204204
{
205205
JS_RunGC(JS_GetRuntime(ctx));
206206
return JS_UNDEFINED;
207207
}
208208

209-
static JSValue js_navigator_get_userAgent(JSContext *ctx, JSValue this_val)
209+
static JSValue js_navigator_get_userAgent(JSContext *ctx, JSValueConst this_val)
210210
{
211211
char version[32];
212212
snprintf(version, sizeof(version), "quickjs-ng/%s", JS_GetVersion());
@@ -667,7 +667,7 @@ int main(int argc, char **argv)
667667
args[0] = JS_NewString(ctx, compile_file);
668668
args[1] = JS_NewString(ctx, out);
669669
args[2] = JS_NewString(ctx, exe != NULL ? exe : argv[0]);
670-
ret = JS_Call(ctx, func, JS_UNDEFINED, countof(args), args);
670+
ret = JS_Call(ctx, func, JS_UNDEFINED, 3, (JSValueConst *)args);
671671
JS_FreeValue(ctx, func);
672672
JS_FreeValue(ctx, args[0]);
673673
JS_FreeValue(ctx, args[1]);

0 commit comments

Comments
 (0)