To ensure optimal use of memory, SSL contexts for ngx.fetch() are now
inherited from previous levels as long as relevant js_fetch_* directives
are not redefined.
Dmitry Volyntsev [Tue, 26 Nov 2024 05:43:44 +0000 (21:43 -0800)]
HTTP: fixed limit rated output.
Previously, when r.return(code, body) was called from a subrequest
handler with a body size larger than the sendfile_max_chunk value
connection hanging might occur.
Previously, njs_promise_resolve() might return njs_object_t instead of
njs_promise_t. Later an instance of njs_object_t was put into a
NJS_PROMISE value. Whereas njs_promise_t is always expected to be inside
of a NJS_PROMISE value.
src/qjs.c:347:19: error: variable 'signo' may be uninitialized when used
here [-Werror,-Wconditional-uninitialized]
347 | if (kill(pid, signo) < 0) {
| ^~~~~
src/qjs.c:294:31: note: initialize the variable 'signo' to silence this
warning
294 | int signo, pid;
| ^
| = 0
1 error generated.
Dmitry Volyntsev [Sat, 19 Oct 2024 01:24:49 +0000 (18:24 -0700)]
Improved error messages for module loading failures.
There are several reasons why a file cannot be opened. Without
extra information, especially in containerized environments, these
problems are difficult to debug. Adding errno status to the
error output helps identify the root cause.
Additionally, error messages are now aligned between njs and QuickJS.
Dmitry Volyntsev [Wed, 16 Oct 2024 01:28:19 +0000 (18:28 -0700)]
Implemented lazy stack symbolization.
Previously, when an exception was thrown, the exception got 'stack'
property attached which contained the backtrace information about where
the exception happened. This could be a heavy operation and it was not
always needed.
To optimize it, the process is split into 2 phases. The first phase
collects all the necessary info about the current stack. The second
phase, where the stack symbolization happens, occurs only when this
property is referenced.
Dmitry Volyntsev [Sat, 12 Oct 2024 00:23:42 +0000 (17:23 -0700)]
Modules: removed extra VMs creation when it is not needed.
Previously, a new VM instance was created for every location. This is
not needed and consumes a lot of memory for large configurations.
Instead, if no new js_import is introduced on the location level server
level VM should be used.
Dmitry Volyntsev [Thu, 10 Oct 2024 00:32:11 +0000 (17:32 -0700)]
Fixed heap-buffer-overflow in Buffer.prototype.indexOf().
Previously, when `from` argument was provided heap-buffer-overflow might
happen due to lack of boundary check. `to = njs_min(to, length)`
statement was also removed because it has no effect, `to` is
equal to `length` here.
Dmitry Volyntsev [Sat, 15 Jun 2024 03:54:28 +0000 (20:54 -0700)]
Modules: introduced QuickJS engine.
"js_engine" directive is introduced which sets JavaScript engine.
When the module is built with QuickJS library "js_engine qjs;" sets
QuickJS engine for the current block. By default njs engine is used.
For example,
nginx.conf:
location /a {
js_engine qjs;
# will be handled by QuickJS
js_content main.handler;
}
location /b {
# will be handled by njs
js_content main.handler;
}
QuickJS engine implements drop-in replacement for nginx/njs objects
with the following exceptions:
* nginx module API to be added later: ngx.fetch(), ngx.shared.dict.
* Built-in modules to be added later: fs, crypto, WebCrypto, xml.
* NJS specific API: njs.dump(), njs.on(), console.dump().
* js_preload_object directive.
QuickJS: disabling eval() and Function() in qjs_new_context().
This properly disables eval() after previous attempt in c773ebcaad
(0.8.5). In QuickJS buint-in C level eval API, which is used by njs, is
linked to eval() in JS code. To disable only the JS function
manual modification of global object is required.
Thomas P. [Wed, 7 Aug 2024 09:47:08 +0000 (11:47 +0200)]
Modules: added nocache flag for js_set variables.
This commit adds support for an additional `nocache` flag in `js_set`
directives. If set, the resulting nginx variable will have no_cacheable set
to 1. This enables us to dynamically recompute a variable if the context
changed (for example, in case of an internal redirection).
In case of multiple calls in a location, users should cache the result in a
rewrite variable: `set $cached_variable $js_variable;`
Elijah Zupancic [Tue, 20 Aug 2024 18:41:44 +0000 (11:41 -0700)]
Add badges to README.md
This change adds two badges indicating the current project status and level of
support offered. These badges are standardized across many nginx projects.
Dmitry Volyntsev [Fri, 21 Jun 2024 00:11:24 +0000 (17:11 -0700)]
Fixed maybe-uninitialized warning in error creation.
Ensuring that buf is always initialized in njs_throw_error_va()
and njs_error_fmt_new(), by requiring fmt to always be non NULL.
This fixes GCC warnings like:
169 | njs_unicode_decode_t ctx;
| ^
In function ‘njs_utf8_length’,
inlined from ‘njs_error_new’ at src/njs_error.c:39:14,
inlined from ‘njs_throw_error_va’ at src/njs_error.c:69:5:
src/njs_utf8.h:141:12: error: ‘buf’ may be used uninitialized
[-Werror=maybe-uninitialized]
141 | return njs_utf8_stream_length(&ctx, p, len, 1, 1, NULL);