Skip to content

Commit

Permalink
QuickJS: added zlib module.
Browse files Browse the repository at this point in the history
  • Loading branch information
xeioex committed May 2, 2024
1 parent a8c22f1 commit bb3dcf2
Show file tree
Hide file tree
Showing 17 changed files with 2,322 additions and 322 deletions.
1 change: 1 addition & 0 deletions auto/init
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ NJS_CFLAGS=${NJS_CFLAGS=}
NJS_BUILD_DIR=${NJS_BUILD_DIR:-build}

NJS_LIB_MODULES=
QJS_LIB_MODULES=

NJS_LIBRT=

Expand Down
42 changes: 37 additions & 5 deletions auto/make
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ njs_modules_c=$NJS_BUILD_DIR/njs_modules.c

NJS_LIB_SRCS="$NJS_LIB_SRCS $njs_modules_c"

njs_incs=`echo $NJS_LIB_INCS \
| sed -e "s# *\([^ ]*\)#$njs_regex_cont-I\1#g"`
njs_objs=`echo $NJS_LIB_SRCS \
| sed -e "s# *\([^ ]*\.\)c#$NJS_BUILD_DIR/\1o$njs_regex_cont#g"`

cat << END > $njs_modules_c

#include <njs_main.h>
Expand All @@ -45,6 +40,43 @@ cat << END >> $njs_modules_c

END

if [ $NJS_HAVE_QUICKJS = YES ]; then

qjs_modules_c=$NJS_BUILD_DIR/qjs_modules.c

NJS_LIB_SRCS="$NJS_LIB_SRCS $qjs_modules_c"

cat << END > $qjs_modules_c

#include <qjs.h>

END

for mod in $QJS_LIB_MODULES
do
echo "extern qjs_module_t $mod;" >> $qjs_modules_c
done

echo >> $qjs_modules_c
echo 'qjs_module_t *qjs_modules[] = {' >> $qjs_modules_c

for mod in $QJS_LIB_MODULES
do
echo " &$mod," >> $qjs_modules_c
done

cat << END >> $qjs_modules_c
NULL
};

END
fi

njs_incs=`echo $NJS_LIB_INCS \
| sed -e "s# *\([^ ]*\)#$njs_regex_cont-I\1#g"`
njs_objs=`echo $NJS_LIB_SRCS \
| sed -e "s# *\([^ ]*\.\)c#$NJS_BUILD_DIR/\1o$njs_regex_cont#g"`

cat << END > $NJS_MAKEFILE

# This file is auto-generated by configure
Expand Down
6 changes: 6 additions & 0 deletions auto/qjs_module
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (C) Dmitry Volyntsev
# Copyright (C) F5, Inc

QJS_LIB_MODULES="$QJS_LIB_MODULES $njs_module_name"
NJS_LIB_SRCS="$NJS_LIB_SRCS $njs_module_srcs"
NJS_LIB_INCS="$NJS_LIB_INCS $njs_module_incs"
20 changes: 20 additions & 0 deletions auto/qjs_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) Dmitry Volyntsev
# Copyright (C) F5, Inc

if [ $NJS_HAVE_QUICKJS = YES ]; then

njs_module_name=qjs_buffer_module
njs_module_incs=
njs_module_srcs=src/qjs_buffer.c

. auto/qjs_module

if [ $NJS_ZLIB = YES -a $NJS_HAVE_ZLIB = YES ]; then
njs_module_name=qjs_zlib_module
njs_module_incs=
njs_module_srcs=external/qjs_zlib_module.c

. auto/qjs_module
fi

fi
21 changes: 21 additions & 0 deletions auto/quickjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if [ $NJS_TRY_QUICKJS = YES ]; then
JSRuntime *rt;

rt = JS_NewRuntime();
(void) JS_GetClassID;
JS_FreeRuntime(rt);
return 0;
}"
Expand Down Expand Up @@ -54,6 +55,26 @@ if [ $NJS_TRY_QUICKJS = YES ]; then
fi

if [ $njs_found = yes ]; then

njs_feature="QuickJS JS_NewTypedArray()"
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() {
(void) JS_NewTypedArray;
return 0;
}"

. auto/feature

if [ $njs_found = yes ]; then
njs_define=NJS_HAVE_QUICKJS_NEW_TYPED_ARRAY . auto/define
fi

NJS_HAVE_QUICKJS=YES
NJS_QUICKJS_LIB="$njs_feature_libs"
NJS_LIB_INCS="$NJS_LIB_INCS $njs_feature_incs"
Expand Down
4 changes: 4 additions & 0 deletions auto/sources
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ if [ "$NJS_HAVE_LIBBFD" = "YES" -a "$NJS_HAVE_DL_ITERATE_PHDR" = "YES" ]; then
NJS_LIB_SRCS="$NJS_LIB_SRCS src/njs_addr2line.c"
fi

if [ "$NJS_HAVE_QUICKJS" = "YES" ]; then
NJS_LIB_SRCS="$NJS_LIB_SRCS src/qjs.c"
fi

NJS_TS_SRCS=$(find ts/ -name "*.d.ts" -o -name "*.json")

NJS_TEST_TS_SRCS=$(find test/ts/ -name "*.ts" -o -name "*.json")
3 changes: 2 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ NJS_AUTOCONF_ERR=$NJS_BUILD_DIR/autoconf.err
NJS_AUTO_CONFIG_H=$NJS_BUILD_DIR/njs_auto_config.h
NJS_MAKEFILE=$NJS_BUILD_DIR/Makefile

NJS_LIB_INCS="src $NJS_BUILD_DIR"
NJS_LIB_INCS="src external $NJS_BUILD_DIR"

test -d $NJS_BUILD_DIR || mkdir $NJS_BUILD_DIR

Expand Down Expand Up @@ -59,6 +59,7 @@ NJS_LIB_AUX_LIBS=

. auto/sources
. auto/modules
. auto/qjs_modules
. auto/make
. auto/expect
. auto/summary
15 changes: 2 additions & 13 deletions external/njs_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,7 @@
#include <njs_rbtree.h>

#if (NJS_HAVE_QUICKJS)
#if defined(__GNUC__) && (__GNUC__ >= 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
#endif

#include <quickjs.h>

#if defined(__GNUC__) && (__GNUC__ >= 8)
#pragma GCC diagnostic pop
#endif
#define NJS_QUICKJS_VERSION "Unknown version"
#include <pthread.h>
#include <qjs.h>
#endif

#if (!defined NJS_FUZZER_TARGET && defined NJS_HAVE_READLINE)
Expand Down Expand Up @@ -2822,7 +2811,7 @@ njs_engine_qjs_init(njs_engine_t *engine, njs_opts_t *opts)
return NJS_ERROR;
}

engine->u.qjs.ctx = JS_NewContext(engine->u.qjs.rt);
engine->u.qjs.ctx = qjs_new_context(engine->u.qjs.rt);
if (engine->u.qjs.ctx == NULL) {
njs_stderror("JS_NewContext() failed\n");
return NJS_ERROR;
Expand Down
Loading

0 comments on commit bb3dcf2

Please sign in to comment.