Skip to content
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
22 changes: 14 additions & 8 deletions .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: check-pr
on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
build:
runs-on: [ ubuntu-24.04 ]
Expand All @@ -29,7 +33,7 @@ jobs:
sudo apt-get install \
libssl-dev zlib1g-dev libpcre2-dev libxslt1-dev libgeoip-dev \
libgd-dev libxml2-dev libedit-dev libperl-dev libtest-harness-perl \
libgd-perl libgeoip-dev expect
libgd-perl libgeoip-dev expect meson ninja-build

- name: Install x86 build dependencies
run: |
Expand All @@ -55,9 +59,11 @@ jobs:
run: |
git clone https://github.com/quickjs-ng/quickjs quickjs-ng
cd quickjs-ng
git checkout v0.9.0
CFLAGS="$CC_OPT -fPIC" LDFLAGS=$LD_OPT cmake -B build
cmake --build build --target qjs -j $(nproc)
git checkout v0.11.0
CFLAGS="$CC_OPT -fPIC" LDFLAGS=$LD_OPT meson setup build --prefix=$HOME/.local --libdir=lib
meson compile -C build
meson install -C build
echo "PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV

- name: Configure and make njs
run: |
Expand Down Expand Up @@ -103,8 +109,8 @@ jobs:
run: |
./configure \
--with-quickjs \
--cc-opt="$CC_OPT -Iquickjs-ng" \
--ld-opt="$LD_OPT -Lquickjs-ng/build" \
--cc-opt="$CC_OPT" \
--ld-opt="$LD_OPT" \
|| cat build/autoconf.err
$MAKE_UTILITY -j$(nproc)

Expand Down Expand Up @@ -214,7 +220,7 @@ jobs:
- 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
$NGINX_CONFIGURE_CMD --with-cc-opt="$CC_OPT -fsanitize=address -DNJS_DEBUG_MEMORY -DNGX_DEBUG_PALLOC -DNGX_DEBUG_MALLOC" --with-ld-opt="$LD_OPT -fsanitize=address" --add-module=../nginx || cat objs/autoconf.err
$MAKE_UTILITY -j$(nproc)

- name: Test njs modules, quickjs-ng, static modules
Expand Down Expand Up @@ -242,7 +248,7 @@ jobs:
- 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
$NGINX_CONFIGURE_CMD --with-debug --with-cc-opt="$CC_OPT -fsanitize=address -DNJS_DEBUG_MEMORY -DNGX_DEBUG_PALLOC -DNGX_DEBUG_MALLOC" --with-ld-opt="$LD_OPT -fsanitize=address" --add-dynamic-module=../nginx || cat objs/autoconf.err
$MAKE_UTILITY -j$(nproc) modules
$MAKE_UTILITY -j$(nproc)

Expand Down
33 changes: 33 additions & 0 deletions auto/quickjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ if [ $NJS_TRY_QUICKJS = YES ]; then
. auto/feature
fi

if [ $njs_found = no ]; then
if command -v pkg-config >/dev/null 2>&1 && pkg-config --exists quickjs-ng; then

# pkg-config

njs_feature="QuickJS-NG library via pkg-config"

njs_feature_incs="$NJS_QUICKJS_DEFAULT_INCS"
njs_feature_incs="$njs_feature_incs $(pkg-config quickjs-ng --cflags-only-I | sed -e 's/-I//g')"
njs_feature_libs=$(pkg-config quickjs-ng --libs)

. auto/feature
fi
fi

if [ $njs_found = no ]; then
njs_feature="QuickJS-NG library -lqjs"
njs_feature_incs="$NJS_QUICKJS_DEFAULT_INCS"
Expand Down Expand Up @@ -136,6 +151,24 @@ if [ $NJS_TRY_QUICKJS = YES ]; then

. auto/feature

njs_feature="QuickJS JS_IsError()"
njs_feature_name=NJS_HAVE_QUICKJS_IS_ERROR_SINGLE_ARG
njs_feature_test="#include <quickjs_compat.h>

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

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

. auto/feature

njs_feature="QuickJS JS_AddIntrinsicBigInt()"
njs_feature_name=NJS_HAVE_QUICKJS_ADD_INTRINSIC_BIG_INT
njs_feature_test="#include <quickjs_compat.h>
Expand Down
2 changes: 1 addition & 1 deletion external/njs_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,7 @@ njs_qjs_dump_error2(JSContext *ctx, JSValueConst exception)
_Bool is_error;
JSValue val;

is_error = JS_IsError(ctx, exception);
is_error = qjs_is_error(ctx, exception);

njs_qjs_dump_obj(ctx, stderr, exception, "Thrown:\n", "");

Expand Down
6 changes: 3 additions & 3 deletions external/qjs_fs_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2696,23 +2696,23 @@ qjs_fs_result(JSContext *cx, JSValue result, int calltype, JSValue callback)

switch (calltype) {
case QJS_FS_DIRECT:
if (JS_IsError(cx, result)) {
if (qjs_is_error(cx, result)) {
JS_Throw(cx, result);
return JS_EXCEPTION;
}

return result;

case QJS_FS_PROMISE:
if (JS_IsError(cx, result)) {
if (qjs_is_error(cx, result)) {
JS_Throw(cx, result);
return qjs_promise_result(cx, JS_EXCEPTION);
}

return qjs_promise_result(cx, result);

case QJS_FS_CALLBACK:
if (JS_IsError(cx, result)) {
if (qjs_is_error(cx, result)) {
arguments[0] = result;
arguments[1] = JS_UNDEFINED;

Expand Down
30 changes: 15 additions & 15 deletions nginx/config
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ if [ $NJS_QUICKJS != NO ]; then
. auto/feature
fi

if [ $ngx_found = no ]; then
if command -v pkg-config >/dev/null 2>&1 && pkg-config --exists quickjs-ng; then

# pkg-config

ngx_feature="QuickJS-NG library via pkg-config"

ngx_feature_path="$NJS_QUICKJS_DEFAULT_INCS"
ngx_feature_path="$ngx_feature_path $(pkg-config quickjs-ng --cflags-only-I | sed -e 's/-I//g')"
ngx_feature_libs=$(pkg-config quickjs-ng --libs)

. auto/feature
fi
fi

if [ $ngx_found = no ]; then
ngx_feature="QuickJS-NG library -lqjs"
ngx_feature_path="$NJS_QUICKJS_DEFAULT_INCS"
Expand All @@ -87,21 +102,6 @@ if [ $NJS_QUICKJS != NO ]; then
exit 1;
fi

ngx_feature="QuickJS 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

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"
NJS_QUICKJS_INC=`echo "$ngx_feature_path" | sed -e "s|^$NJS_QUICKJS_DEFAULT_INCS||"`
Expand Down
6 changes: 6 additions & 0 deletions src/qjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ static inline JS_BOOL JS_IsNullOrUndefined(JSValueConst v)
#define qjs_is_array(cx, a) JS_IsArray(cx, a)
#endif

#ifdef NJS_HAVE_QUICKJS_IS_ERROR_SINGLE_ARG
#define qjs_is_error(cx, a) JS_IsError(a)
#else
#define qjs_is_error(cx, a) JS_IsError(cx, a)
#endif

extern qjs_module_t *qjs_modules[];

#endif /* _QJS_H_INCLUDED_ */