Skip to content

qjs fetch. #864

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions nginx/config
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ NJS_ENGINE_LIB="$ngx_addon_dir/../build/libnjs.a"
if [ "$NJS_HAVE_QUICKJS" = "YES" ]; then
NJS_ENGINE_DEP="$ngx_addon_dir/../build/libqjs.a"
NJS_ENGINE_LIB="$ngx_addon_dir/../build/libnjs.a $ngx_addon_dir/../build/libqjs.a"
QJS_SRCS="$QJS_SRCS $ngx_addon_dir/ngx_qjs_fetch.c"
fi

if [ $HTTP != NO ]; then
Expand Down
1 change: 1 addition & 0 deletions nginx/ngx_http_js_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ static JSClassDef ngx_http_qjs_headers_out_class = {
qjs_module_t *njs_http_qjs_addon_modules[] = {
&ngx_qjs_ngx_module,
&ngx_qjs_ngx_shared_dict_module,
&ngx_qjs_ngx_fetch_module,
/*
* Shared addons should be in the same order and the same positions
* in all nginx modules.
Expand Down
26 changes: 26 additions & 0 deletions nginx/ngx_js.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ static const JSCFunctionListEntry ngx_qjs_ext_ngx[] = {
JS_CGETSET_MAGIC_DEF("ERR", ngx_qjs_ext_constant_integer, NULL,
NGX_LOG_ERR),
JS_CGETSET_DEF("error_log_path", ngx_qjs_ext_error_log_path, NULL),
JS_CFUNC_DEF("fetch", 2, ngx_qjs_ext_fetch),
JS_CGETSET_MAGIC_DEF("INFO", ngx_qjs_ext_constant_integer, NULL,
NGX_LOG_INFO),
JS_CFUNC_MAGIC_DEF("log", 1, ngx_qjs_ext_log, 0),
Expand Down Expand Up @@ -2184,6 +2185,31 @@ ngx_qjs_core_init(JSContext *cx, const char *name)
return m;
}


int
ngx_qjs_array_length(JSContext *cx, uint32_t *plen, JSValueConst arr)
{
int ret;
JSValue value;
uint32_t len;

value = JS_GetPropertyStr(cx, arr, "length");
if (JS_IsException(value)) {
return -1;
}

ret = JS_ToUint32(cx, &len, value);
JS_FreeValue(cx, value);

if (ret) {
return -1;
}

*plen = len;

return 0;
}

#endif


Expand Down
8 changes: 8 additions & 0 deletions nginx/ngx_js.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
#define NGX_QJS_CLASS_ID_SHARED (NGX_QJS_CLASS_ID_OFFSET + 11)
#define NGX_QJS_CLASS_ID_SHARED_DICT (NGX_QJS_CLASS_ID_OFFSET + 12)
#define NGX_QJS_CLASS_ID_SHARED_DICT_ERROR (NGX_QJS_CLASS_ID_OFFSET + 13)
#define NGX_QJS_CLASS_ID_FETCH_HEADERS (NGX_QJS_CLASS_ID_OFFSET + 14)
#define NGX_QJS_CLASS_ID_FETCH_REQUEST (NGX_QJS_CLASS_ID_OFFSET + 15)
#define NGX_QJS_CLASS_ID_FETCH_RESPONSE (NGX_QJS_CLASS_ID_OFFSET + 16)


typedef struct ngx_js_loc_conf_s ngx_js_loc_conf_t;
Expand Down Expand Up @@ -345,6 +348,10 @@ ngx_int_t ngx_qjs_call(JSContext *cx, JSValue function, JSValue *argv,
ngx_int_t ngx_qjs_exception(JSContext *cx, ngx_str_t *s);
ngx_int_t ngx_qjs_integer(JSContext *cx, JSValueConst val, ngx_int_t *n);
ngx_int_t ngx_qjs_string(JSContext *cx, JSValueConst val, ngx_str_t *str);
int ngx_qjs_array_length(JSContext *cx, uint32_t *plen, JSValueConst arr);

JSValue ngx_qjs_ext_fetch(JSContext *cx, JSValueConst this_val, int argc,
JSValueConst *argv);

#define ngx_qjs_prop(cx, type, start, len) \
((type == NGX_JS_STRING) ? qjs_string_create(cx, start, len) \
Expand Down Expand Up @@ -381,6 +388,7 @@ extern qjs_module_t qjs_webcrypto_module;
extern qjs_module_t qjs_zlib_module;
extern qjs_module_t ngx_qjs_ngx_module;
extern qjs_module_t ngx_qjs_ngx_shared_dict_module;
extern qjs_module_t ngx_qjs_ngx_fetch_module;

#endif

Expand Down
Loading
Loading