Skip to content
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
56 changes: 45 additions & 11 deletions nginx/ngx_http_js_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,16 @@ static njs_external_t ngx_http_js_ext_request[] = {
}
},

{
.flags = NJS_EXTERN_OBJECT,
.name.string = njs_str("var"),
.u.object = {
.writable = 1,
.prop_handler = ngx_http_js_ext_variables,
.magic32 = NGX_JS_STRING,
}
},

{
.flags = NJS_EXTERN_OBJECT,
.name.string = njs_str("variables"),
Expand Down Expand Up @@ -1034,6 +1044,16 @@ static njs_external_t ngx_http_js_ext_periodic_session[] = {
}
},

{
.flags = NJS_EXTERN_OBJECT,
.name.string = njs_str("var"),
.u.object = {
.writable = 1,
.prop_handler = ngx_http_js_periodic_session_variables,
.magic32 = NGX_JS_STRING,
}
},

{
.flags = NJS_EXTERN_OBJECT,
.name.string = njs_str("variables"),
Expand Down Expand Up @@ -1155,6 +1175,8 @@ static const JSCFunctionListEntry ngx_http_qjs_ext_request[] = {
JS_CFUNC_DEF("subrequest", 3, ngx_http_qjs_ext_subrequest),
JS_CGETSET_MAGIC_DEF("uri", ngx_http_qjs_ext_string, NULL,
offsetof(ngx_http_request_t, uri)),
JS_CGETSET_MAGIC_DEF("var", ngx_http_qjs_ext_variables,
NULL, NGX_JS_STRING),
JS_CGETSET_MAGIC_DEF("variables", ngx_http_qjs_ext_variables,
NULL, NGX_JS_STRING),
JS_CFUNC_MAGIC_DEF("warn", 1, ngx_http_qjs_ext_log, NGX_LOG_WARN),
Expand All @@ -1166,6 +1188,8 @@ static const JSCFunctionListEntry ngx_http_qjs_ext_periodic[] = {
JS_PROP_CONFIGURABLE),
JS_CGETSET_MAGIC_DEF("rawVariables", ngx_http_qjs_ext_periodic_variables,
NULL, NGX_JS_BUFFER),
JS_CGETSET_MAGIC_DEF("var", ngx_http_qjs_ext_periodic_variables,
NULL, NGX_JS_STRING),
JS_CGETSET_MAGIC_DEF("variables", ngx_http_qjs_ext_periodic_variables,
NULL, NGX_JS_STRING),
};
Expand Down Expand Up @@ -1620,8 +1644,9 @@ ngx_http_js_variable_set(ngx_http_request_t *r, ngx_http_variable_value_t *v,

if (rc == NGX_DECLINED) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"no \"js_import\" directives found for \"js_set\" handler"
" \"%V\" in the current scope", fname);
"no \"js_import\" or inline expression found"
" for \"js_set\" handler \"%V\" at %s:%ui",
fname, vdata->file_name, vdata->line);
v->not_found = 1;
return NGX_OK;
}
Expand Down Expand Up @@ -1708,6 +1733,7 @@ ngx_http_js_init_vm(ngx_http_request_t *r, njs_int_t proto_id)
}

ngx_js_ctx_init((ngx_js_ctx_t *) ctx, r->connection->log);
ctx->conf = (ngx_js_loc_conf_t *) jlcf;

ngx_http_set_ctx(r, ctx, ngx_http_js_module);
}
Expand Down Expand Up @@ -8016,9 +8042,12 @@ ngx_http_js_periodic(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
static char *
ngx_http_js_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_str_t *value;
ngx_js_set_t *data, *prev;
ngx_http_variable_t *v;
ngx_str_t *value;
ngx_js_set_t *data, *prev;
ngx_http_variable_t *v;
ngx_http_js_loc_conf_t *jlcf;

static ngx_uint_t ngx_http_js_inline_index;

value = cf->args->elts;

Expand All @@ -8041,20 +8070,25 @@ ngx_http_js_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}

data->fname = value[2];
data->flags = 0;
data->file_name = cf->conf_file->file.name.data;
data->line = cf->conf_file->line;
jlcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_js_module);

if (ngx_js_set_init(cf, &jlcf->inlines, &ngx_http_js_inline_index,
&value[2], "r", data)
!= NGX_OK)
{
return NGX_CONF_ERROR;
}

if (v->get_handler == ngx_http_js_variable_set) {
prev = (ngx_js_set_t *) v->data;

if (data->fname.len != prev->fname.len
|| ngx_strncmp(data->fname.data, prev->fname.data, data->fname.len) != 0)
|| ngx_strncmp(data->fname.data, prev->fname.data,
data->fname.len) != 0)
{
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"variable \"%V\" is redeclared with "
"different function name", &value[1]);
"different handler", &value[1]);
return NGX_CONF_ERROR;
}
}
Expand Down
Loading