Skip to content

Commit d2bca87

Browse files
authored
Make quickjs.h -Wall -Wextra -pedantic clean (#628)
Fixes: #585
1 parent 89883ae commit d2bca87

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

Makefile

+9-3
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,14 @@ distclean:
8383
stats: $(QJS)
8484
$(QJS) -qd
8585

86-
# implicitly .PHONY because it doesn't generate output
87-
cxxtest: CXXFLAGS+=-std=c++11 -fsyntax-only -Wall -Wextra -Werror -Wno-unused-parameter
86+
# effectively .PHONY because it doesn't generate output
87+
ctest: CFLAGS=-std=c11 -fsyntax-only -Wall -Wextra -Werror -pedantic
88+
ctest: ctest.c quickjs.h
89+
$(CC) $(CFLAGS) -DJS_NAN_BOXING=0 $<
90+
$(CC) $(CFLAGS) -DJS_NAN_BOXING=1 $<
91+
92+
# effectively .PHONY because it doesn't generate output
93+
cxxtest: CXXFLAGS=-std=c++11 -fsyntax-only -Wall -Wextra -Werror -pedantic
8894
cxxtest: cxxtest.cc quickjs.h
8995
$(CXX) $(CXXFLAGS) -DJS_NAN_BOXING=0 $<
9096
$(CXX) $(CXXFLAGS) -DJS_NAN_BOXING=1 $<
@@ -116,4 +122,4 @@ unicode_gen: $(BUILD_DIR)
116122
libunicode-table.h: unicode_gen
117123
$(BUILD_DIR)/unicode_gen unicode $@
118124

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

ctest.c

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// note: file is not actually compiled, only checked for C syntax errors
2+
#include "quickjs.h"
3+
4+
int main(void)
5+
{
6+
JSRuntime *rt = JS_NewRuntime();
7+
JSContext *ctx = JS_NewContext(rt);
8+
JS_FreeValue(ctx, JS_NAN);
9+
JS_FreeValue(ctx, JS_UNDEFINED);
10+
JS_FreeValue(ctx, JS_NewFloat64(ctx, 42));
11+
// not a legal way of using JS_MKPTR but this is here
12+
// to have the compiler syntax-check its definition
13+
JS_FreeValue(ctx, JS_MKPTR(JS_TAG_UNINITIALIZED, 0));
14+
JS_FreeContext(ctx);
15+
JS_FreeRuntime(rt);
16+
return 0;
17+
}

cxxtest.cc

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,2 @@
11
// note: file is not actually compiled, only checked for C++ syntax errors
2-
#include "quickjs.h"
3-
4-
int main(void)
5-
{
6-
JSRuntime *rt = JS_NewRuntime();
7-
JSContext *ctx = JS_NewContext(rt);
8-
JS_FreeValue(ctx, JS_NAN);
9-
JS_FreeValue(ctx, JS_UNDEFINED);
10-
JS_FreeValue(ctx, JS_NewFloat64(ctx, 42));
11-
// not a legal way of using JS_MKPTR but this is here
12-
// to have the compiler syntax-check its definition
13-
JS_FreeValue(ctx, JS_MKPTR(JS_TAG_UNINITIALIZED, 0));
14-
JS_FreeContext(ctx);
15-
JS_FreeRuntime(rt);
16-
return 0;
17-
}
2+
#include "ctest.c"

quickjs.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -514,21 +514,25 @@ JS_EXTERN int JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id);
514514

515515
static js_force_inline JSValue JS_NewBool(JSContext *ctx, JS_BOOL val)
516516
{
517+
(void)&ctx;
517518
return JS_MKVAL(JS_TAG_BOOL, (val != 0));
518519
}
519520

520521
static js_force_inline JSValue JS_NewInt32(JSContext *ctx, int32_t val)
521522
{
523+
(void)&ctx;
522524
return JS_MKVAL(JS_TAG_INT, val);
523525
}
524526

525527
static js_force_inline JSValue JS_NewFloat64(JSContext *ctx, double val)
526528
{
529+
(void)&ctx;
527530
return __JS_NewFloat64(val);
528531
}
529532

530533
static js_force_inline JSValue JS_NewCatchOffset(JSContext *ctx, int32_t val)
531534
{
535+
(void)&ctx;
532536
return JS_MKVAL(JS_TAG_CATCH_OFFSET, val);
533537
}
534538

@@ -566,8 +570,8 @@ static inline JS_BOOL JS_IsNumber(JSValue v)
566570

567571
static inline JS_BOOL JS_IsBigInt(JSContext *ctx, JSValue v)
568572
{
569-
int tag = JS_VALUE_GET_TAG(v);
570-
return tag == JS_TAG_BIG_INT;
573+
(void)&ctx;
574+
return JS_VALUE_GET_TAG(v) == JS_TAG_BIG_INT;
571575
}
572576

573577
static inline JS_BOOL JS_IsBool(JSValue v)

0 commit comments

Comments
 (0)