Skip to content

Commit

Permalink
Shell: added QuickJS engine support.
Browse files Browse the repository at this point in the history
  • Loading branch information
xeioex committed Feb 23, 2024
1 parent 822e450 commit b5a0576
Show file tree
Hide file tree
Showing 13 changed files with 2,596 additions and 662 deletions.
22 changes: 21 additions & 1 deletion auto/expect
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,31 @@ fi
if [ $njs_found = yes -a $NJS_HAVE_READLINE = YES ]; then
cat << END >> $NJS_MAKEFILE

shell_test: njs test/shell_test.exp
shell_test_njs: njs test/shell_test.exp
PATH=$NJS_BUILD_DIR:\$(PATH) LANG=C.UTF-8 TERM=screen \
expect -f test/shell_test.exp
PATH=$NJS_BUILD_DIR:\$(PATH) LANG=C.UTF-8 TERM=screen \
expect -f test/shell_test_njs.exp
END

if [ $NJS_HAVE_QUICKJS = YES ]; then
cat << END >> $NJS_MAKEFILE

shell_test: shell_test_njs shell_test_quickjs

shell_test_quickjs: njs test/shell_test.exp
PATH=$NJS_BUILD_DIR:\$(PATH) LANG=C.UTF-8 TERM=screen NJS_ENGINE=QuickJS \
expect -f test/shell_test.exp
END

else
cat << END >> $NJS_MAKEFILE

shell_test: shell_test_njs
END

fi

else
echo " - expect tests are disabled"

Expand Down
23 changes: 21 additions & 2 deletions auto/make
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ lib_test: $NJS_BUILD_DIR/njs_auto_config.h \\
$NJS_BUILD_DIR/lvlhsh_unit_test
$NJS_BUILD_DIR/unicode_unit_test

test262: njs

test262_njs: njs
test/test262 --binary=$NJS_BUILD_DIR/njs

unit_test: $NJS_BUILD_DIR/njs_auto_config.h \\
Expand All @@ -265,6 +264,26 @@ dist:
&& echo njs-\$(NJS_VER).tar.gz done
END

if [ $NJS_HAVE_QUICKJS = YES ]; then
cat << END >> $NJS_MAKEFILE

test262: njs test262_njs test262_quickjs

test262_quickjs: njs
NJS_SKIP_LIST="test/js/promise_rejection_tracker_recursive.t.js \\
test/js/async_exception_in_await.t.js" \\
test/test262 --binary='$NJS_BUILD_DIR/njs -n QuickJS -m'
END

else
cat << END >> $NJS_MAKEFILE

test262: njs test262_njs
END

fi


njs_ts_deps=`echo $NJS_TS_SRCS \
| sed -e "s# *\([^ ][^ ]*\)#\1$njs_regex_cont#g"`

Expand Down
2 changes: 2 additions & 0 deletions auto/options
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ NJS_DEBUG_GENERATOR=NO
NJS_ADDRESS_SANITIZER=NO
NJS_ADDR2LINE=NO

NJS_QUICKJS=YES
NJS_OPENSSL=YES
NJS_LIBXML2=YES
NJS_ZLIB=YES
Expand Down Expand Up @@ -47,6 +48,7 @@ do
--debug-opcode=*) NJS_DEBUG_OPCODE="$value" ;;
--debug-generator=*) NJS_DEBUG_GENERATOR="$value" ;;

--no-quickjs) NJS_QUICKJS=NO ;;
--no-openssl) NJS_OPENSSL=NO ;;
--no-libxml2) NJS_LIBXML2=NO ;;
--no-zlib) NJS_ZLIB=NO ;;
Expand Down
55 changes: 55 additions & 0 deletions auto/quickjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

# Copyright (C) Dmitry Volyntsev
# Copyright (C) NGINX, Inc.


NJS_QUICKJS_LIB=
NJS_HAVE_QUICKJS=NO

if [ $NJS_QUICKJS = YES ]; then
njs_found=no

njs_feature="QuickJS library"
njs_feature_name=NJS_HAVE_QUICKJS
njs_feature_run=yes
njs_feature_incs=
njs_feature_libs=""
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;

rt = JS_NewRuntime();
JS_FreeRuntime(rt);
return 0;
}"
. auto/feature

if [ $njs_found = no ]; then
njs_feature="QuickJS library -lquickjs.lto"
njs_feature_incs="/usr/include/quickjs/"
njs_feature_libs="-L/usr/lib/quickjs/ -lquickjs.lto -lm -ldl -lpthread"

. auto/feature
fi

if [ $njs_found = no ]; then
njs_feature="QuickJS library -lquickjs"
njs_feature_libs="-L/usr/lib/quickjs/ -lquickjs -lm -ldl -lpthread"

. auto/feature
fi

if [ $njs_found = yes ]; then
NJS_HAVE_QUICKJS=YES
NJS_QUICKJS_LIB="$njs_feature_libs"
NJS_LIB_INCS="$NJS_LIB_INCS $njs_feature_incs"
NJS_LIB_AUX_LIBS="$NJS_LIB_AUX_LIBS $njs_feature_libs"
fi

fi
4 changes: 4 additions & 0 deletions auto/summary
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ if [ $NJS_HAVE_READLINE = YES ]; then
echo " + using readline library: $NJS_READLINE_LIB"
fi

if [ $NJS_HAVE_QUICKJS = YES ]; then
echo " + using QuickJS library: $NJS_QUICKJS_LIB"
fi

if [ $NJS_HAVE_OPENSSL = YES ]; then
echo " + using OpenSSL library: $NJS_OPENSSL_LIB"
fi
Expand Down
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ NJS_LIB_AUX_LIBS=
. auto/explicit_bzero
. auto/pcre
. auto/readline
. auto/quickjs
. auto/openssl
. auto/libxml2
. auto/zlib
Expand Down
Loading

0 comments on commit b5a0576

Please sign in to comment.