]> git.kaiwu.me - njs.git/commit
Modules: added jsVarNames() method.
authorDmitry Volyntsev <xeioex@nginx.com>
Sat, 16 May 2026 22:14:37 +0000 (15:14 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Mon, 18 May 2026 17:45:51 +0000 (10:45 -0700)
commitf9ff315e6ad3cafdaaae3847fde79115f7a1143f
tree878583987c85e1a20de90d722a5987eacf927258
parent7d1706c20a71d3e864d61b74f9aa2448d265cce6
Modules: added jsVarNames() method.

The method returns names of variables declared with js_var.  An optional
string argument filters returned names by prefix.

This lets JavaScript code discover a configuration-defined variable schema
without duplicating every variable name in the script.  For example:

    js_var $extract_name;
    js_var $extract_arguments_workspace;

    function handler(r) {
        r.jsVarNames("extract_").forEach(function(name) {
            r.variables[name] = extract(name.slice(8));
        });
    }

The same API is available as s.jsVarNames() in stream.  Variables created by
js_set or by the core modules are not returned.
nginx/ngx_http_js_module.c
nginx/ngx_stream_js_module.c
nginx/t/js_var_names.t [new file with mode: 0644]
nginx/t/stream_js_var_names.t [new file with mode: 0644]