details: https://hg.nginx.org/njs/rev/9e327cd3a33e
branches:
changeset: 1197:9e327cd3a33e
user: Dmitry Volyntsev
date: Wed Oct 23 14:42:38 2019 +0300
description:
Refactoring iteration over external objects.
Previously, two callbacks were required to support
array-like iteration for external objects (foreach, next).
Instead using only one callback (keys) to simplify.
diffstat:
nginx/ngx_http_js_module.c | 242 ++
nginx/ngx_stream_js_module.c | 13 --
src/njs.h|8 +-
src/njs_extern.c |3 +-
src/njs_extern.h |3 +-
src/njs_json.c |8 +-
src/njs_shell.c |6 -
src/njs_value.c | 42 +++
src/njs_vmcode.c | 94 +---
src/test/njs_unit_test.c | 61 --
10 files changed, 187 insertions(+), 293 deletions(-)
diffs (truncated from 1094 to 1000 lines):
diff -r 5e136f9a5954 -r 9e327cd3a33e nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.cWed Oct 23 14:42:38 2019 +0300
+++ b/nginx/ngx_http_js_module.cWed Oct 23 14:42:38 2019 +0300
@@ -36,12 +36,6 @@ typedef struct {
typedef struct {
-ngx_list_part_t *part;
-ngx_uint_t item;
-} ngx_http_js_table_entry_t;
-
-
-typedef struct {
ngx_http_request_t *request;
njs_vm_event_t vm_event;
void*unused;
@@ -62,10 +56,8 @@ static void ngx_http_js_cleanup_vm(void
static njs_int_t ngx_http_js_ext_get_string(njs_vm_t *vm, njs_value_t *value,
void *obj, uintptr_t data);
-static njs_int_t ngx_http_js_ext_foreach_header(njs_vm_t *vm, void *obj,
-void *next, uintptr_t data);
-static njs_int_t ngx_http_js_ext_next_header(njs_vm_t *vm, njs_value_t *value,
-void *obj, void *next);
+static njs_int_t ngx_http_js_ext_keys_header(njs_vm_t *vm, void *obj,
+njs_value_t *keys, uintptr_t data);
static ngx_table_elt_t *ngx_http_js_get_header(ngx_list_part_t *part,
u_char *data, size_t len);
static njs_int_t ngx_http_js_ext_get_header_out(njs_vm_t *vm,
@@ -74,8 +66,8 @@ static njs_int_t ngx_http_js_ext_set_hea
uintptr_t data, njs_str_t *value);
static njs_int_t ngx_http_js_ext_delete_header_out(njs_vm_t *vm, void *obj,
uintptr_t data, njs_bool_t delete);
-static njs_int_t ngx_http_js_ext_foreach_header_out(njs_vm_t *vm, void *obj,
-void *next); /*FIXME*/
+static njs_int_t ngx_http_js_ext_keys_header_out(njs_vm_t *vm, void *obj,
+njs_value_t *keys); /*FIXME*/
static njs_int_t ngx_http_js_ext_get_status(njs_vm_t *vm, njs_value_t *value,
void *obj, uintptr_t data);
static njs_int_t ngx_http_js_ext_set_status(njs_vm_t *vm, void *obj,
@@ -108,14 +100,12 @@ static njs_int_t ngx_http_js_ext_get_req
njs_value_t *value, void *obj, uintptr_t data);
static njs_int_t ngx_http_js_ext_get_header_in(njs_vm_t *vm, njs_value_t
*value,
void *obj, uintptr_t data);
-static njs_int_t ngx_http_js_ext_foreach_header_in(njs_vm_t *vm, void *obj,
-void *next); /*FIXME*/
+static njs_int_t ngx_http_js_ext_keys_header_in(njs_vm_t *vm, void *obj,
+njs_value_t *keys); /*FIXME*/
static njs_int_t ngx_http_js_ext_get_arg(njs_vm_t *vm, njs_value_t *value,
void *obj, uintptr_t data);
-static njs_int_t ngx_http_js_ext_foreach_arg(njs_vm_t *vm, void *obj,
-void *next);
-static njs_int_t ngx_http_js_ext_next_arg(njs_vm_t *vm, njs_value_t *value,
-void *obj, void *next);
+static njs_int_t ngx_http_js_ext_keys_arg(njs_vm_t *vm, void *obj,
+njs_value_t *keys);
static njs_int_t ngx_http_js_ext_get_variable(njs_vm_t *vm, njs_value_t *value,
void *obj, uintptr_t data);
static njs_int_t ngx_http_js_ext_set_variable(njs_vm_t *vm, void *obj,
@@ -229,7 +219,6 @@ static njs_external_t ngx_http_js_ext_r
NULL,
NULL,
NULL,
- NULL,
offsetof(ngx_http_request_t, uri) },
{ njs_str("method"),
@@ -241,7 +230,6 @@ static njs_external_t ngx_http_js_ext_r
NULL,
NULL,
NULL,
- NULL,
offsetof(ngx_http_request_t, method_name) },
{ njs_str("httpVersion"),
@@ -253,7 +241,6 @@ static njs_external_t ngx_http_js_ext_r
NULL,
NULL,
NULL,
- NULL,
0 },
{ njs_str("remoteAddress"),
@@ -265,7 +252,6 @@ static njs_external_t ngx_http_js_ext_r
NULL,
NULL,
NULL,
- NULL,
0 },
{ njs_str("parent"),
@@ -277,7 +263,6 @@ static njs_external_t ngx_http_js_ext_r
NULL,
NULL,
NULL,
- NULL,
0 },
{ njs_str("requestBody"),
@@ -289,7 +274,6 @@ static njs_external_t ngx_http_js_ext_r
NULL,
NULL,
NULL,
- NULL,
0 },
{ njs_str("responseBody"),
@@ -301,7 +285,6 @@ static njs_external_t ngx_http_js_ext_r
NULL,
NULL,
NULL,
- NULL,
0 },
{ njs_str("headersIn"),
@@ -311,8 +294,7 @@ static njs_external_t ngx_http_js_ext_r