[njs] Modules: introduced setReturnValue() method.
Dmitry Volyntsev
xeioex at nginx.com
Fri Oct 8 13:42:08 UTC 2021
details: https://hg.nginx.org/njs/rev/fb3e13959b71
branches:
changeset: 1717:fb3e13959b71
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri Oct 08 13:41:01 2021 +0000
description:
Modules: introduced setReturnValue() method.
diffstat:
nginx/ngx_http_js_module.c | 36 ++++++++++++++++++++++++++++++++++++
nginx/ngx_stream_js_module.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 0 deletions(-)
diffs (120 lines):
diff -r 5e3973c2216d -r fb3e13959b71 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c Fri Oct 08 13:41:00 2021 +0000
+++ b/nginx/ngx_http_js_module.c Fri Oct 08 13:41:01 2021 +0000
@@ -143,6 +143,8 @@ static njs_int_t ngx_http_js_ext_send(nj
njs_uint_t nargs, njs_index_t unused);
static njs_int_t ngx_http_js_ext_send_buffer(njs_vm_t *vm, njs_value_t *args,
njs_uint_t nargs, njs_index_t unused);
+static njs_int_t ngx_http_js_ext_set_return_value(njs_vm_t *vm,
+ njs_value_t *args, njs_uint_t nargs, njs_index_t unused);
static njs_int_t ngx_http_js_ext_done(njs_vm_t *vm, njs_value_t *args,
njs_uint_t nargs, njs_index_t unused);
static njs_int_t ngx_http_js_ext_finish(njs_vm_t *vm, njs_value_t *args,
@@ -656,6 +658,17 @@ static njs_external_t ngx_http_js_ext_r
{
.flags = NJS_EXTERN_METHOD,
+ .name.string = njs_str("setReturnValue"),
+ .writable = 1,
+ .configurable = 1,
+ .enumerable = 1,
+ .u.method = {
+ .native = ngx_http_js_ext_set_return_value,
+ }
+ },
+
+ {
+ .flags = NJS_EXTERN_METHOD,
.name.string = njs_str("done"),
.writable = 1,
.configurable = 1,
@@ -2154,6 +2167,29 @@ ngx_http_js_ext_send_buffer(njs_vm_t *vm
static njs_int_t
+ngx_http_js_ext_set_return_value(njs_vm_t *vm, njs_value_t *args,
+ njs_uint_t nargs, njs_index_t unused)
+{
+ ngx_http_js_ctx_t *ctx;
+ ngx_http_request_t *r;
+
+ r = njs_vm_external(vm, ngx_http_js_request_proto_id,
+ njs_argument(args, 0));
+ if (r == NULL) {
+ njs_vm_error(vm, "\"this\" is not an external");
+ return NJS_ERROR;
+ }
+
+ ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
+
+ njs_value_assign(&ctx->retval, njs_arg(args, nargs, 1));
+ njs_value_undefined_set(njs_vm_retval(vm));
+
+ return NJS_OK;
+}
+
+
+static njs_int_t
ngx_http_js_ext_done(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
{
diff -r 5e3973c2216d -r fb3e13959b71 nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c Fri Oct 08 13:41:00 2021 +0000
+++ b/nginx/ngx_stream_js_module.c Fri Oct 08 13:41:01 2021 +0000
@@ -110,6 +110,8 @@ static njs_int_t ngx_stream_js_ext_off(n
njs_uint_t nargs, njs_index_t unused);
static njs_int_t ngx_stream_js_ext_send(njs_vm_t *vm, njs_value_t *args,
njs_uint_t nargs, njs_index_t unused);
+static njs_int_t ngx_stream_js_ext_set_return_value(njs_vm_t *vm,
+ njs_value_t *args, njs_uint_t nargs, njs_index_t unused);
static njs_int_t ngx_stream_js_ext_variables(njs_vm_t *vm,
njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
@@ -450,6 +452,17 @@ static njs_external_t ngx_stream_js_ext
}
},
+ {
+ .flags = NJS_EXTERN_METHOD,
+ .name.string = njs_str("setReturnValue"),
+ .writable = 1,
+ .configurable = 1,
+ .enumerable = 1,
+ .u.method = {
+ .native = ngx_stream_js_ext_set_return_value,
+ }
+ },
+
};
@@ -1249,6 +1262,29 @@ ngx_stream_js_ext_send(njs_vm_t *vm, njs
static njs_int_t
+ngx_stream_js_ext_set_return_value(njs_vm_t *vm, njs_value_t *args,
+ njs_uint_t nargs, njs_index_t unused)
+{
+ ngx_stream_js_ctx_t *ctx;
+ ngx_stream_session_t *s;
+
+ s = njs_vm_external(vm, ngx_stream_js_session_proto_id,
+ njs_argument(args, 0));
+ if (s == NULL) {
+ njs_vm_error(vm, "\"this\" is not an external");
+ return NJS_ERROR;
+ }
+
+ ctx = ngx_stream_get_module_ctx(s, ngx_stream_js_module);
+
+ njs_value_assign(&ctx->retval, njs_arg(args, nargs, 1));
+ njs_value_undefined_set(njs_vm_retval(vm));
+
+ return NJS_OK;
+}
+
+
+static njs_int_t
ngx_stream_js_ext_variables(njs_vm_t *vm, njs_object_prop_t *prop,
njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
{
More information about the nginx-devel
mailing list