Skip to content

Commit 9010aee

Browse files
committed
QuickJS: making ngx_qjs_*() functions consistent with ngx_js_*().
1 parent 18d3170 commit 9010aee

File tree

5 files changed

+91
-118
lines changed

5 files changed

+91
-118
lines changed

nginx/ngx_http_js_module.c

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5133,7 +5133,7 @@ ngx_http_qjs_ext_internal_redirect(JSContext *cx, JSValueConst this_val,
51335133
"internalRedirect cannot be called while filtering");
51345134
}
51355135

5136-
if (ngx_qjs_string(ctx->engine, argv[0], &ctx->redirect_uri) != NGX_OK) {
5136+
if (ngx_qjs_string(cx, argv[0], &ctx->redirect_uri) != NGX_OK) {
51375137
return JS_EXCEPTION;
51385138
}
51395139

@@ -5412,7 +5412,7 @@ ngx_http_qjs_ext_return(JSContext *cx, JSValueConst this_val,
54125412
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
54135413

54145414
if (status < NGX_HTTP_BAD_REQUEST || !JS_IsNullOrUndefined(argv[1])) {
5415-
if (ngx_qjs_string(ctx->engine, argv[1], &body) != NGX_OK) {
5415+
if (ngx_qjs_string(cx, argv[1], &body) != NGX_OK) {
54165416
return JS_ThrowOutOfMemory(cx);
54175417
}
54185418

@@ -5515,7 +5515,7 @@ ngx_http_qjs_ext_send(JSContext *cx, JSValueConst this_val,
55155515
ll = &out;
55165516

55175517
for (n = 0; n < (ngx_uint_t) argc; n++) {
5518-
if (ngx_qjs_string(ctx->engine, argv[n], &s) != NGX_OK) {
5518+
if (ngx_qjs_string(cx, argv[n], &s) != NGX_OK) {
55195519
return JS_ThrowTypeError(cx, "failed to convert arg");
55205520
}
55215521

@@ -5578,7 +5578,7 @@ ngx_http_qjs_ext_send_buffer(JSContext *cx, JSValueConst this_val,
55785578
return JS_ThrowTypeError(cx, "cannot send buffer while not filtering");
55795579
}
55805580

5581-
if (ngx_qjs_string(ctx->engine, argv[0], &buffer) != NGX_OK) {
5581+
if (ngx_qjs_string(cx, argv[0], &buffer) != NGX_OK) {
55825582
return JS_ThrowTypeError(cx, "failed get buffer arg");
55835583
}
55845584

@@ -5735,7 +5735,7 @@ ngx_http_qjs_subrequest_done(ngx_http_request_t *r, void *data, ngx_int_t rc)
57355735
reply = JS_DupValue(cx, ngx_qjs_arg(sctx->args[0]));
57365736
}
57375737

5738-
rc = ngx_qjs_call((ngx_js_ctx_t *) ctx, event->function, &reply, 1);
5738+
rc = ngx_qjs_call(cx, event->function, &reply, 1);
57395739

57405740
JS_FreeValue(cx, reply);
57415741
ngx_js_del_event(ctx, event);
@@ -5786,7 +5786,7 @@ ngx_http_qjs_ext_subrequest(JSContext *cx, JSValueConst this_val,
57865786
"the primary request");
57875787
}
57885788

5789-
if (ngx_qjs_string(ctx->engine, argv[0], &uri) != NGX_OK) {
5789+
if (ngx_qjs_string(cx, argv[0], &uri) != NGX_OK) {
57905790
return JS_ThrowTypeError(cx, "failed to convert uri arg");
57915791
}
57925792

@@ -5812,7 +5812,7 @@ ngx_http_qjs_ext_subrequest(JSContext *cx, JSValueConst this_val,
58125812
arg = argv[1];
58135813

58145814
if (JS_IsString(arg)) {
5815-
if (ngx_qjs_string(ctx->engine, arg, &args) != NGX_OK) {
5815+
if (ngx_qjs_string(cx, arg, &args) != NGX_OK) {
58165816
return JS_ThrowTypeError(cx, "failed to convert args");
58175817
}
58185818

@@ -5833,7 +5833,7 @@ ngx_http_qjs_ext_subrequest(JSContext *cx, JSValueConst this_val,
58335833
}
58345834

58355835
if (!JS_IsUndefined(value)) {
5836-
rc = ngx_qjs_string(ctx->engine, value, &args);
5836+
rc = ngx_qjs_string(cx, value, &args);
58375837
JS_FreeValue(cx, value);
58385838

58395839
if (rc != NGX_OK) {
@@ -5857,7 +5857,7 @@ ngx_http_qjs_ext_subrequest(JSContext *cx, JSValueConst this_val,
58575857
}
58585858

58595859
if (!JS_IsUndefined(value)) {
5860-
rc = ngx_qjs_string(ctx->engine, value, &method_name);
5860+
rc = ngx_qjs_string(cx, value, &method_name);
58615861
JS_FreeValue(cx, value);
58625862

58635863
if (rc != NGX_OK) {
@@ -5884,7 +5884,7 @@ ngx_http_qjs_ext_subrequest(JSContext *cx, JSValueConst this_val,
58845884
}
58855885

58865886
if (!JS_IsUndefined(value)) {
5887-
rc = ngx_qjs_string(ctx->engine, value, &body_arg);
5887+
rc = ngx_qjs_string(cx, value, &body_arg);
58885888
JS_FreeValue(cx, value);
58895889

58905890
if (rc != NGX_OK) {
@@ -6233,7 +6233,6 @@ ngx_http_qjs_variables_set_property(JSContext *cx, JSValueConst obj,
62336233
u_char *lowcase_key;
62346234
ngx_str_t name, s;
62356235
ngx_uint_t key;
6236-
ngx_http_js_ctx_t *ctx;
62376236
ngx_http_request_t *r;
62386237
ngx_http_variable_t *v;
62396238
ngx_http_variable_value_t *vv;
@@ -6279,9 +6278,7 @@ ngx_http_qjs_variables_set_property(JSContext *cx, JSValueConst obj,
62796278
return -1;
62806279
}
62816280

6282-
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
6283-
6284-
if (ngx_qjs_string(ctx->engine, value, &s) != NGX_OK) {
6281+
if (ngx_qjs_string(cx, value, &s) != NGX_OK) {
62856282
return -1;
62866283
}
62876284

@@ -6692,15 +6689,14 @@ ngx_http_qjs_headers_out_handler(JSContext *cx, ngx_http_request_t *r,
66926689
ngx_str_t *name, JSPropertyDescriptor *pdesc, JSValue *value,
66936690
unsigned flags)
66946691
{
6695-
u_char *p;
6696-
int64_t length;
6697-
uint32_t i;
6698-
ngx_int_t rc;
6699-
ngx_str_t s;
6700-
JSValue v;
6701-
ngx_list_part_t *part;
6702-
ngx_table_elt_t *header, *h, **ph;
6703-
ngx_http_js_ctx_t *ctx;
6692+
u_char *p;
6693+
int64_t length;
6694+
uint32_t i;
6695+
ngx_int_t rc;
6696+
ngx_str_t s;
6697+
JSValue v;
6698+
ngx_list_part_t *part;
6699+
ngx_table_elt_t *header, *h, **ph;
67046700

67056701
if (flags & NJS_HEADER_GET) {
67066702
return ngx_http_qjs_header_generic(cx, r, &r->headers_out.headers, NULL,
@@ -6758,7 +6754,6 @@ ngx_http_qjs_headers_out_handler(JSContext *cx, ngx_http_request_t *r,
67586754
}
67596755

67606756
ph = &header;
6761-
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
67626757

67636758
for (i = 0; i < (uint32_t) length; i++) {
67646759
if (JS_IsArray(cx, *value)) {
@@ -6768,7 +6763,7 @@ ngx_http_qjs_headers_out_handler(JSContext *cx, ngx_http_request_t *r,
67686763
}
67696764
}
67706765

6771-
rc = ngx_qjs_string(ctx->engine, v, &s);
6766+
rc = ngx_qjs_string(cx, v, &s);
67726767

67736768
if (JS_IsArray(cx, *value)) {
67746769
JS_FreeValue(cx, v);
@@ -6828,15 +6823,14 @@ ngx_http_qjs_headers_out_special_handler(JSContext *cx, ngx_http_request_t *r,
68286823
ngx_str_t *name, JSPropertyDescriptor *pdesc, JSValue *value,
68296824
unsigned flags, ngx_table_elt_t **hh)
68306825
{
6831-
u_char *p;
6832-
uint32_t length;
6833-
JSValue len, setval;
6834-
ngx_str_t s;
6835-
ngx_uint_t i, rc;
6836-
ngx_list_t *headers;
6837-
ngx_list_part_t *part;
6838-
ngx_table_elt_t *header, *h;
6839-
ngx_http_js_ctx_t *ctx;
6826+
u_char *p;
6827+
uint32_t length;
6828+
JSValue len, setval;
6829+
ngx_str_t s;
6830+
ngx_uint_t i, rc;
6831+
ngx_list_t *headers;
6832+
ngx_list_part_t *part;
6833+
ngx_table_elt_t *header, *h;
68406834

68416835
if (flags & NJS_HEADER_GET) {
68426836
return ngx_http_qjs_headers_out_handler(cx, r, name, pdesc, NULL,
@@ -6870,9 +6864,7 @@ ngx_http_qjs_headers_out_special_handler(JSContext *cx, ngx_http_request_t *r,
68706864
setval = JS_UNDEFINED;
68716865
}
68726866

6873-
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
6874-
6875-
rc = ngx_qjs_string(ctx->engine, setval, &s);
6867+
rc = ngx_qjs_string(cx, setval, &s);
68766868

68776869
if (value != NULL && JS_IsArray(cx, *value)) {
68786870
JS_FreeValue(cx, setval);
@@ -7054,7 +7046,6 @@ ngx_http_qjs_headers_out_content_type(JSContext *cx, ngx_http_request_t *r,
70547046
JSValue len, setval;
70557047
ngx_int_t rc;
70567048
ngx_str_t *hdr, s;
7057-
ngx_http_js_ctx_t *ctx;
70587049

70597050
if (flags & NJS_HEADER_GET) {
70607051
hdr = &r->headers_out.content_type;
@@ -7108,9 +7099,7 @@ ngx_http_qjs_headers_out_content_type(JSContext *cx, ngx_http_request_t *r,
71087099
setval = *value;
71097100
}
71107101

7111-
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
7112-
7113-
rc = ngx_qjs_string(ctx->engine, setval, &s);
7102+
rc = ngx_qjs_string(cx, setval, &s);
71147103

71157104
if (JS_IsArray(cx, *value)) {
71167105
JS_FreeValue(cx, setval);

0 commit comments

Comments
 (0)