Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for QuickJS-NG library. #844

Merged
merged 5 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ jobs:
cd quickjs
CFLAGS=$CC_OPT LDFLAGS=$LD_OPT $MAKE_UTILITY -j$(nproc) libquickjs.a

- name: Check out and build quickjs-ng
run: |
git clone https://github.com/quickjs-ng/quickjs quickjs-ng
cd quickjs-ng
git checkout v0.8.0
CFLAGS="$CC_OPT -fPIC" LDFLAGS=$LD_OPT cmake -B build
cmake --build build --target qjs -j $(nproc)

- name: Configure and make njs
run: |
./configure \
Expand Down Expand Up @@ -88,6 +96,20 @@ jobs:
$MAKE_UTILITY test
$MAKE_UTILITY clean

- name: Configure and make njs with quickjs-ng
run: |
./configure \
--with-quickjs \
--cc-opt="$CC_OPT -Iquickjs-ng" \
--ld-opt="$LD_OPT -Lquickjs-ng/build" \
|| cat build/autoconf.err
$MAKE_UTILITY -j$(nproc)

- name: Test njs with quickjs-ng
run: |
$MAKE_UTILITY test
$MAKE_UTILITY clean

- name: Configure and build nginx and njs modules
run: |
cd nginx-source
Expand Down Expand Up @@ -168,3 +190,62 @@ jobs:
TEST_NGINX_VERBOSE: 1
ASAN_OPTIONS: "detect_odr_violation=0:report_globals=0:fast_unwind_on_malloc=0"
LSAN_OPTIONS: "suppressions=${{ github.workspace }}/lsan_suppressions.txt"

- name: Configure and build nginx and njs modules with quickjs-ng, asan, static modules
run: |
cd nginx-source
$NGINX_CONFIGURE_CMD --with-cc-opt="$CC_OPT -I${{ github.workspace }}/quickjs-ng -fsanitize=address -DNJS_DEBUG_MEMORY -DNGX_DEBUG_PALLOC -DNGX_DEBUG_MALLOC" --with-ld-opt="$LD_OPT -L${{ github.workspace }}/quickjs-ng/build -fsanitize=address" --add-module=../nginx || cat objs/autoconf.err
$MAKE_UTILITY -j$(nproc)

- name: Test njs modules, quickjs-ng, static modules
run: |
ulimit -c unlimited
prove -v -j$(nproc) -Inginx-tests/lib --state=save nginx/t . || prove -v -Inginx-tests/lib --state=failed
env:
TEST_NGINX_BINARY: "${{ github.workspace }}/nginx-source/objs/nginx"
TEST_NGINX_VERBOSE: 1
ASAN_OPTIONS: "detect_odr_violation=0:report_globals=0"
LSAN_OPTIONS: "suppressions=${{ github.workspace }}/lsan_suppressions.txt"

- name: Test njs modules (js_engine qjs), quickjs-ng, static modules
run: |
ulimit -c unlimited
prove -v -j$(nproc) -Inginx-tests/lib --state=save nginx/t . || prove -v -Inginx-tests/lib --state=failed
env:
TEST_NGINX_BINARY: "${{ github.workspace }}/nginx-source/objs/nginx"
TEST_NGINX_GLOBALS_HTTP: "js_engine qjs;"
TEST_NGINX_GLOBALS_STREAM: "js_engine qjs;"
TEST_NGINX_VERBOSE: 1
ASAN_OPTIONS: "detect_odr_violation=0:report_globals=0"
LSAN_OPTIONS: "suppressions=${{ github.workspace }}/lsan_suppressions.txt"

- name: Configure and build nginx and njs modules with quickjs-ng, asan, dynamic modules
run: |
cd nginx-source
$NGINX_CONFIGURE_CMD --with-debug --with-cc-opt="$CC_OPT -I${{ github.workspace }}/quickjs-ng -fsanitize=address -DNJS_DEBUG_MEMORY -DNGX_DEBUG_PALLOC -DNGX_DEBUG_MALLOC" --with-ld-opt="$LD_OPT -L${{ github.workspace }}/quickjs-ng/build -fsanitize=address" --add-dynamic-module=../nginx || cat objs/autoconf.err
$MAKE_UTILITY -j$(nproc) modules
$MAKE_UTILITY -j$(nproc)

- name: Test njs modules, quickjs-ng, dynamic modules
run: |
ulimit -c unlimited
prove -v -j$(nproc) -Inginx-tests/lib --state=save nginx/t . || prove -v -Inginx-tests/lib --state=failed
env:
TEST_NGINX_BINARY: "${{ github.workspace }}/nginx-source/objs/nginx"
TEST_NGINX_GLOBALS: "load_module ${{ github.workspace }}/nginx-source/objs/ngx_stream_js_module.so; load_module ${{ github.workspace }}/nginx-source/objs/ngx_http_js_module.so;"
TEST_NGINX_VERBOSE: 1
ASAN_OPTIONS: "detect_odr_violation=0:report_globals=0:fast_unwind_on_malloc=0"
LSAN_OPTIONS: "suppressions=${{ github.workspace }}/lsan_suppressions.txt"

- name: Test njs modules (js_engine qjs), quickjs-ng, dynamic modules
run: |
ulimit -c unlimited
prove -v -j$(nproc) -Inginx-tests/lib --state=save nginx/t . || prove -v -Inginx-tests/lib --state=failed
env:
TEST_NGINX_BINARY: "${{ github.workspace }}/nginx-source/objs/nginx"
TEST_NGINX_GLOBALS: "load_module ${{ github.workspace }}/nginx-source/objs/ngx_stream_js_module.so; load_module ${{ github.workspace }}/nginx-source/objs/ngx_http_js_module.so;"
TEST_NGINX_GLOBALS_HTTP: "js_engine qjs;"
TEST_NGINX_GLOBALS_STREAM: "js_engine qjs;"
TEST_NGINX_VERBOSE: 1
ASAN_OPTIONS: "detect_odr_violation=0:report_globals=0:fast_unwind_on_malloc=0"
LSAN_OPTIONS: "suppressions=${{ github.workspace }}/lsan_suppressions.txt"
72 changes: 67 additions & 5 deletions auto/quickjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,19 @@ if [ $NJS_TRY_QUICKJS = YES ]; then
. auto/feature
fi

if [ $njs_found = no ]; then
njs_feature="QuickJS-NG library -lqjs"
njs_feature_incs=""
njs_feature_libs="-lqjs -lm -ldl -lpthread"

. auto/feature
fi


if [ $njs_found = yes ]; then

njs_feature="QuickJS JS_GetClassID()"
njs_feature_name=NJS_HAVE_QUICKJS_GET_CLASS_ID
njs_feature_test="#if defined(__GNUC__) && (__GNUC__ >= 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored \"-Wcast-function-type\"
Expand All @@ -64,7 +74,7 @@ if [ $NJS_TRY_QUICKJS = YES ]; then
#include <quickjs.h>

int main() {
(void) JS_GetClassID;
(void) JS_GetClassID(JS_UNDEFINED);
return 0;
}"

Expand All @@ -78,6 +88,7 @@ if [ $NJS_TRY_QUICKJS = YES ]; then
fi

njs_feature="QuickJS JS_NewTypedArray()"
njs_feature_name=NJS_HAVE_QUICKJS_NEW_TYPED_ARRAY
njs_feature_test="#if defined(__GNUC__) && (__GNUC__ >= 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored \"-Wcast-function-type\"
Expand All @@ -86,15 +97,66 @@ if [ $NJS_TRY_QUICKJS = YES ]; then
#include <quickjs.h>

int main() {
(void) JS_NewTypedArray;
JSValue ta, argv;
JSRuntime *rt;
JSContext *ctx;

rt = JS_NewRuntime();
ctx = JS_NewContext(rt);
argv = JS_NewInt64(ctx, 1);
ta = JS_NewTypedArray(ctx, 1, &argv,
JS_TYPED_ARRAY_UINT8);
JS_FreeValue(ctx, ta);
JS_FreeContext(ctx);
JS_FreeRuntime(rt);
return 0;
}"

. auto/feature

if [ $njs_found = yes ]; then
njs_define=NJS_HAVE_QUICKJS_NEW_TYPED_ARRAY . auto/define
fi
njs_feature="QuickJS JS_IsSameValue()"
njs_feature_name=NJS_HAVE_QUICKJS_IS_SAME_VALUE
njs_feature_test="#if defined(__GNUC__) && (__GNUC__ >= 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored \"-Wcast-function-type\"
#endif

#include <quickjs.h>

int main() {
JSRuntime *rt;
JSContext *ctx;

rt = JS_NewRuntime();
ctx = JS_NewContext(rt);
(void) JS_IsSameValue(ctx, JS_UNDEFINED, JS_UNDEFINED);
JS_FreeContext(ctx);
JS_FreeRuntime(rt);
return 0;
}"

. auto/feature

njs_feature="QuickJS version"
njs_feature_name=NJS_QUICKJS_VERSION
njs_feature_run=value
njs_feature_test="#if defined(__GNUC__) && (__GNUC__ >= 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored \"-Wcast-function-type\"
#endif

#include <quickjs.h>

int main() {
#if defined(QJS_VERSION_MAJOR)
printf(\"\\\"%s\\\"\", JS_GetVersion());
#else
printf(\"\\\"Unknown\\\"\");
#endif
return 0;
}"

. auto/feature

NJS_HAVE_QUICKJS=YES
NJS_QUICKJS_LIB="$njs_feature_libs"
Expand Down
22 changes: 11 additions & 11 deletions external/qjs_fs_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ qjs_fs_access(JSContext *cx, JSValueConst this_val, int argc,
return JS_EXCEPTION;
}

if (JS_SameValue(cx, mode, callback)) {
if (qjs_is_same_value(cx, mode, callback)) {
mode = JS_UNDEFINED;
}
}
Expand Down Expand Up @@ -586,7 +586,7 @@ qjs_fs_mkdir(JSContext *cx, JSValueConst this_val, int argc,
return JS_EXCEPTION;
}

if (JS_SameValue(cx, options, callback)) {
if (qjs_is_same_value(cx, options, callback)) {
options = JS_UNDEFINED;
}
}
Expand Down Expand Up @@ -894,7 +894,7 @@ qjs_fs_read_file(JSContext *cx, JSValueConst this_val, int argc,
return JS_EXCEPTION;
}

if (JS_SameValue(cx, options, callback)) {
if (qjs_is_same_value(cx, options, callback)) {
options = JS_UNDEFINED;
}
}
Expand Down Expand Up @@ -955,7 +955,7 @@ qjs_fs_read_file(JSContext *cx, JSValueConst this_val, int argc,
str.length = sb.st_size;

v = qjs_fs_fd_read(cx, fd, &str);
if (!JS_SameValue(cx, v, JS_TRUE)) {
if (!qjs_is_same_value(cx, v, JS_TRUE)) {
if (JS_IsException(v)) {
result = JS_EXCEPTION;

Expand Down Expand Up @@ -1012,7 +1012,7 @@ qjs_fs_readlink(JSContext *cx, JSValueConst this_val, int argc,
return JS_EXCEPTION;
}

if (JS_SameValue(cx, options, callback)) {
if (qjs_is_same_value(cx, options, callback)) {
options = JS_UNDEFINED;
}
}
Expand Down Expand Up @@ -1150,7 +1150,7 @@ qjs_fs_readdir(JSContext *cx, JSValueConst this_val, int argc,
return JS_EXCEPTION;
}

if (JS_SameValue(cx, options, callback)) {
if (qjs_is_same_value(cx, options, callback)) {
options = JS_UNDEFINED;
}
}
Expand Down Expand Up @@ -1309,7 +1309,7 @@ qjs_fs_realpath(JSContext *cx, JSValueConst this_val, int argc,
return JS_EXCEPTION;
}

if (JS_SameValue(cx, options, callback)) {
if (qjs_is_same_value(cx, options, callback)) {
options = JS_UNDEFINED;
}
}
Expand Down Expand Up @@ -1655,7 +1655,7 @@ qjs_fs_rmdir(JSContext *cx, JSValueConst this_val, int argc,
return JS_EXCEPTION;
}

if (JS_SameValue(cx, options, callback)) {
if (qjs_is_same_value(cx, options, callback)) {
options = JS_UNDEFINED;
}
}
Expand Down Expand Up @@ -1817,7 +1817,7 @@ qjs_fs_stat(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv,
return JS_EXCEPTION;
}

if (JS_SameValue(cx, options, callback)) {
if (qjs_is_same_value(cx, options, callback)) {
options = JS_UNDEFINED;
}
}
Expand Down Expand Up @@ -1916,7 +1916,7 @@ qjs_fs_symlink(JSContext *cx, JSValueConst this_val, int argc,
return JS_EXCEPTION;
}

if (JS_SameValue(cx, type, callback)) {
if (qjs_is_same_value(cx, type, callback)) {
type = JS_UNDEFINED;
}
}
Expand Down Expand Up @@ -2168,7 +2168,7 @@ qjs_fs_write_file(JSContext *cx, JSValueConst this_val, int argc,
return JS_EXCEPTION;
}

if (JS_SameValue(cx, options, callback)) {
if (qjs_is_same_value(cx, options, callback)) {
options = JS_UNDEFINED;
}
}
Expand Down
36 changes: 31 additions & 5 deletions nginx/config
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ if [ $NJS_QUICKJS != NO ]; then
ngx_feature_test="JSRuntime *rt;

rt = JS_NewRuntime();
(void) JS_GetClassID;
JS_FreeRuntime(rt);
return 0;"
. auto/feature
Expand All @@ -66,17 +65,44 @@ if [ $NJS_QUICKJS != NO ]; then
. auto/feature
fi

if [ $ngx_found = no ]; then
ngx_feature="QuickJS-NG library -lqjs"
ngx_feature_path=""
ngx_feature_libs="-lqjs -lm -ldl -lpthread"

. auto/feature
fi

if [ $ngx_found = yes ]; then

ngx_feature="QuickJS JS_GetClassID()"
ngx_feature_name=NJS_HAVE_QUICKJS_GET_CLASS_ID
ngx_feature_run=no
ngx_feature_test="(void) JS_GetClassID(JS_UNDEFINED);"

. auto/feature

if [ $ngx_found = no ]; then
echo
echo $0: error: QuickJS library found, but JS_GetClassID\(\) is missing.
echo
exit 1;
fi

ngx_feature="QuickJS JS_NewTypedArray()"
ngx_feature_test="(void) JS_NewTypedArray;
ngx_feature_name=NJS_HAVE_QUICKJS_NEW_TYPED_ARRAY
ngx_feature_test="JSValue argv;
(void) JS_NewTypedArray(NULL, 1, &argv,
JS_TYPED_ARRAY_UINT8);
return 0;"

. auto/feature

if [ $ngx_found = yes ]; then
have=NJS_HAVE_QUICKJS_NEW_TYPED_ARRAY . auto/have
fi
ngx_feature="QuickJS JS_IsSameValue()"
ngx_feature_name=NJS_HAVE_QUICKJS_IS_SAME_VALUE
ngx_feature_test="(void) JS_IsSameValue(NULL, JS_UNDEFINED, JS_UNDEFINED);"

. auto/feature

NJS_HAVE_QUICKJS=YES
NJS_QUICKJS_LIB="$ngx_feature_libs"
Expand Down
4 changes: 2 additions & 2 deletions nginx/config.make
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ $ngx_addon_dir/../build/libnjs.a: $NGX_MAKEFILE
cd $ngx_addon_dir/.. \\
&& if [ -f build/Makefile ]; then \$(MAKE) clean; fi \\
&& CFLAGS="\$(CFLAGS)" CC="\$(CC)" ./configure --no-openssl \\
--no-libxml2 --no-zlib --no-pcre --no-quickjs \\
--no-libxml2 --no-zlib --no-pcre --no-quickjs --ld-opt="$NGX_LD_OPT" \\
&& \$(MAKE) libnjs

$ngx_addon_dir/../build/libqjs.a: $NGX_MAKEFILE
cd $ngx_addon_dir/.. \\
&& if [ -f build/Makefile ]; then \$(MAKE) clean; fi \\
&& CFLAGS="\$(CFLAGS)" CC="\$(CC)" ./configure --no-openssl \\
--no-libxml2 --no-zlib --no-pcre \\
--no-libxml2 --no-zlib --no-pcre --ld-opt="$NGX_LD_OPT" \\
&& \$(MAKE) libnjs libqjs

END
2 changes: 1 addition & 1 deletion nginx/ngx_http_js_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -4848,7 +4848,7 @@ ngx_http_qjs_ext_args(JSContext *cx, JSValueConst this_val)
return JS_EXCEPTION;
}

val = qjs_string_create(cx, v + 1, p - v - 1);
val = qjs_string_create(cx, v + 1, (p == v) ? 0 : p - v - 1);
if (JS_IsException(val)) {
chain.free(cx, decoded.start);
JS_FreeAtom(cx, key);
Expand Down
4 changes: 2 additions & 2 deletions src/njs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

#include <njs_auto_config.h>

#define NJS_VERSION "0.8.9"
#define NJS_VERSION_NUMBER 0x000809
#define NJS_VERSION "0.8.10"
#define NJS_VERSION_NUMBER 0x00080a


#include <string.h>
Expand Down
Loading