]> git.kaiwu.me - njs.git/log
njs.git
2 years agoIgnoring UndefinedBehaviorSanitizer warnings where appropriate.
Dmitry Volyntsev [Sun, 30 Jul 2023 09:21:51 +0000 (10:21 +0100)]
Ignoring UndefinedBehaviorSanitizer warnings where appropriate.

Prodded by David Carlier and Ben Kallus.

2 years agoFixed RegExp.prototype.exec() when second argument is absent.
Dmitry Volyntsev [Tue, 9 Jan 2024 00:40:42 +0000 (16:40 -0800)]
Fixed RegExp.prototype.exec() when second argument is absent.

Previously, when the second argument is undefined, NaN is casted to
unsigned which is undefined behavior.

Found by UndefinedBehaviorSanitizer.

2 years agoImproved array enumeration with length 0.
Dmitry Volyntsev [Tue, 9 Jan 2024 00:40:42 +0000 (16:40 -0800)]
Improved array enumeration with length 0.

The fix eliminates an arithmetic operation with NULL pointer.

Found by UndefinedBehaviorSanitizer.

2 years agoFixed initialization of external prototypes with object entry.
Dmitry Volyntsev [Tue, 9 Jan 2024 00:40:42 +0000 (16:40 -0800)]
Fixed initialization of external prototypes with object entry.

When external was NULL (for example, when .u.object.properties is not
declared), an arithmetic operation was performed with NULL pointer which
is undefined behavior.

Found by UndefinedBehaviorSanitizer.

2 years agoQueryString: fixed underflow in parse().
Dmitry Volyntsev [Tue, 9 Jan 2024 00:40:42 +0000 (16:40 -0800)]
QueryString: fixed underflow in parse().

Previously, njs_query_string_append() might be provided with invalid
val_size value when value in a key-value pair was absent.

Found by UndefinedBehaviorSanitizer.

2 years agoFixed external values initialization in unit tests.
Dmitry Volyntsev [Tue, 9 Jan 2024 00:40:42 +0000 (16:40 -0800)]
Fixed external values initialization in unit tests.

Since 0.8.0 modules can create their own constructors and prototypes.
A modules has two method: preinit() and init(). A module should
add its constructors and prototypes in preinit() and create its own
values in init(). Creating a value in preinit() results in an error.
The patch fixes the issue by creating an external value in init()
instead of preinit().

Found by UndefinedBehaviorSanitizer.

2 years agoUnifying hash function prototypes.
Dmitry Volyntsev [Tue, 9 Jan 2024 00:40:42 +0000 (16:40 -0800)]
Unifying hash function prototypes.

This fixes UndefinedBehaviorSanitizer warning "call to function through
pointer to incorrect function type".

Found by UndefinedBehaviorSanitizer.

2 years agoFixed Date constructor for overflows and with NaN values.
Dmitry Volyntsev [Tue, 9 Jan 2024 00:40:27 +0000 (16:40 -0800)]
Fixed Date constructor for overflows and with NaN values.

Found by UndefinedBehaviorSanitizer.

2 years agoModules: fixed clear() method of a shared dictionary without timeout.
Vadim Zhestikov [Tue, 19 Dec 2023 20:37:05 +0000 (12:37 -0800)]
Modules: fixed clear() method of a shared dictionary without timeout.

This fixes #690 issue on Github.

2 years agoMoving out logger from njs core.
Dmitry Volyntsev [Fri, 15 Dec 2023 06:32:02 +0000 (22:32 -0800)]
Moving out logger from njs core.

Logger is not part of the JS runtime according to ECMAScript and should
be implemented by host environment.

2 years agoIntroduced njs_vm_set_module_loader().
Dmitry Volyntsev [Thu, 14 Dec 2023 02:38:47 +0000 (18:38 -0800)]
Introduced njs_vm_set_module_loader().

2 years agoRemoved not required argument for JSON functions.
Vadim Zhestikov [Tue, 12 Dec 2023 03:10:38 +0000 (19:10 -0800)]
Removed not required argument for JSON functions.

2 years agoRemoved not used arg from njs_get_own_ordered_keys().
Vadim Zhestikov [Tue, 12 Dec 2023 03:10:36 +0000 (19:10 -0800)]
Removed not used arg from njs_get_own_ordered_keys().

2 years agoRefactored asynchronous events.
Dmitry Volyntsev [Tue, 5 Dec 2023 16:54:18 +0000 (08:54 -0800)]
Refactored asynchronous events.

To align njs with other JS engines, async events are removed from njs
core. The following functions were removed: njs_vm_add_event(),
njs_vm_del_event(), njs_vm_waiting(). Instead the host is expected
to manage async events by itself.

In addition, the posted events are renamed to jobs, to better align with
the ECMA specs. The following methods are removed: njs_vm_run().
Instead, the host is expected to call njs_vm_execute_pending_job() in a
loop to execute pending jobs. The following functions were added:
njs_vm_enqueue_job().

2 years agoRemoved remnants of GC code.
Vadim Zhestikov [Thu, 30 Nov 2023 04:46:36 +0000 (20:46 -0800)]
Removed remnants of GC code.

The code never worked and comments are in a broken state.

2 years agoFixed memory over-read in njs_utf8_prev() and njs_utf8_next().
Vadim Zhestikov [Thu, 30 Nov 2023 04:46:32 +0000 (20:46 -0800)]
Fixed memory over-read in njs_utf8_prev() and njs_utf8_next().

Previously, njs_utf8_next() might over-read up to 1 byte
beyond the string memory. Whereas njs_utf8_prev() might
over-read unlimited number of bytes before the string.

2 years agoModules: simplified setTimeout() timer callback.
Dmitry Volyntsev [Thu, 30 Nov 2023 02:43:45 +0000 (18:43 -0800)]
Modules: simplified setTimeout() timer callback.

2 years agoTests: detection when "xml" module is disabled.
Dmitry Volyntsev [Thu, 30 Nov 2023 02:43:37 +0000 (18:43 -0800)]
Tests: detection when "xml" module is disabled.

2 years agoXML: fixed building with libxml2 2.12 and later.
Dmitry Volyntsev [Tue, 28 Nov 2023 02:43:36 +0000 (18:43 -0800)]
XML: fixed building with libxml2 2.12 and later.

This fixes #684 issue on Github.

2 years agoRemove njs_timer.c forgotten in the previous commit.
Dmitry Volyntsev [Tue, 28 Nov 2023 02:43:04 +0000 (18:43 -0800)]
Remove njs_timer.c forgotten in the previous commit.

2 years agoMoving out setTimeout() and clearTimeout() from njs core.
Dmitry Volyntsev [Tue, 21 Nov 2023 17:00:52 +0000 (09:00 -0800)]
Moving out setTimeout() and clearTimeout() from njs core.

This functions are not part of the ECMAScript and should be
implemented by host environment.

2 years agoRenaming ngx_js_retval() to ngx_js_exception().
Dmitry Volyntsev [Tue, 21 Nov 2023 16:57:09 +0000 (08:57 -0800)]
Renaming ngx_js_retval() to ngx_js_exception().

After previous commit ngx_js_retval() is only used for getting the
exception value and should be renamed to better reflect the purpose.

2 years agoModules: fixed js_set with Buffer values.
Dmitry Volyntsev [Tue, 21 Nov 2023 16:57:03 +0000 (08:57 -0800)]
Modules: fixed js_set with Buffer values.

Previously, a Buffer value which contains invalid UTF-8 when returned as a
value for js_set handler was mangled because the bytes value was converted to a
string value.

The fix is to use bytes value of Buffer, TypedArray and ArrayBuffer as is,
and not convert it to a string first.

2 years agoFixed memory overlapping.
Vadim Zhestikov [Tue, 21 Nov 2023 14:49:30 +0000 (06:49 -0800)]
Fixed memory overlapping.

2 years agoTests: added console test for stream module.
Dmitry Volyntsev [Wed, 15 Nov 2023 23:08:18 +0000 (15:08 -0800)]
Tests: added console test for stream module.

2 years agoFetch: fixed Headers.set().
Dmitry Volyntsev [Wed, 15 Nov 2023 23:07:20 +0000 (15:07 -0800)]
Fetch: fixed Headers.set().

This closes #680 issue on Github.

2 years agoShell: refactored njs_process_file().
Dmitry Volyntsev [Fri, 10 Nov 2023 01:09:16 +0000 (17:09 -0800)]
Shell: refactored njs_process_file().

The reading part is separated into njs_read_file().

2 years agoShell: moving njs_vm_opt_t initialisation to njs_create_vm().
Dmitry Volyntsev [Thu, 9 Nov 2023 19:49:25 +0000 (11:49 -0800)]
Shell: moving njs_vm_opt_t initialisation to njs_create_vm().

2 years agoShell: unified normal mode and LLVMFuzzerTestOneInput().
Dmitry Volyntsev [Thu, 9 Nov 2023 19:11:19 +0000 (11:11 -0800)]
Shell: unified normal mode and LLVMFuzzerTestOneInput().

Now both main() and LLVMFuzzerTestOneInput() use njs_main()
as a main routine.

2 years agoFixed include directories order.
Dmitry Volyntsev [Tue, 7 Nov 2023 23:35:35 +0000 (15:35 -0800)]
Fixed include directories order.

Previously, when the previous version of njs.h is installed, an outdated
version of njs.h might be included causing build failures.

The fix is to ensure that the local include directories are included
first.

2 years agoRemoved leftover njs directory include directory path.
Dmitry Volyntsev [Tue, 7 Nov 2023 23:35:25 +0000 (15:35 -0800)]
Removed leftover njs directory include directory path.

2 years agoVersion bump.
Dmitry Volyntsev [Tue, 7 Nov 2023 23:35:18 +0000 (15:35 -0800)]
Version bump.

2 years agoAdded tag 0.8.2 for changeset 45f81882c780
Dmitry Volyntsev [Tue, 24 Oct 2023 04:42:43 +0000 (21:42 -0700)]
Added tag 0.8.2 for changeset 45f81882c780

2 years agoVersion 0.8.2. 0.8.2
Dmitry Volyntsev [Tue, 24 Oct 2023 04:42:29 +0000 (21:42 -0700)]
Version 0.8.2.

2 years agoParser: fixed return statement parsing with invalid expression.
Vadim Zhestikov [Tue, 24 Oct 2023 04:19:03 +0000 (21:19 -0700)]
Parser: fixed return statement parsing with invalid expression.

2 years agoModules: fixed delete() method of a shared dictionary.
Dmitry Volyntsev [Fri, 20 Oct 2023 15:44:52 +0000 (08:44 -0700)]
Modules: fixed delete() method of a shared dictionary.

This fixes #679 issue on Github.

2 years agoXML: fixed compilation with certain GCC versions.
Dmitry Volyntsev [Thu, 19 Oct 2023 01:36:00 +0000 (18:36 -0700)]
XML: fixed compilation with certain GCC versions.

external/njs_xml_module.c:541:16: error: 'name.length' may be used
uninitialized [-Werror=maybe-uninitialized]
  541 |             if (name.length != njs_strlen(node->name).

2 years agoFixed RegExp.prototype.exec() with global regexp and unicode input.
Dmitry Volyntsev [Wed, 18 Oct 2023 00:51:39 +0000 (17:51 -0700)]
Fixed RegExp.prototype.exec() with global regexp and unicode input.

Previously, when exactly 32 characters unicode string was provided and
the "lastIndex" value of "this" regexp was equal to 32 too, the
njs_string_utf8_offset() was called with invalid index argument (longer
than a size of the string).  As a result njs_string_utf8_offset()
returned garbage values.

This was manifested in the following ways:
1) InternalError: pcre2_match() failed: bad offset value

2) Very slow replace calls with global regexps, for
   example in expressions like: str.replace(/<re>/g).

This fixes #677 on Github.

2 years agoModules: fixed items() method of a shared dictionary.
Dmitry Volyntsev [Tue, 17 Oct 2023 01:09:37 +0000 (18:09 -0700)]
Modules: fixed items() method of a shared dictionary.

Previously, under a memory pressure the method might return
prematurely while still holding the mutex for the shared memory.

This fixes #676 issue on Github.

2 years agoFixed Array.prototype.sort() with --debug=YES and --debug-memory=YES.
Dmitry Volyntsev [Fri, 6 Oct 2023 23:52:23 +0000 (16:52 -0700)]
Fixed Array.prototype.sort() with --debug=YES and --debug-memory=YES.

Previously, --debug-memory=YES activated a different allocation
mechanism that was not able to properly handle the 0 size allocation.
Specifically, njs_mp_free() failed to find a block to free when the size
of the block is 0.

The fix is to alloc at least 1 byte in the --debug-memory=YES mode.

2 years agoFixed RegExp.prototype.replace().
Dmitry Volyntsev [Fri, 6 Oct 2023 23:51:53 +0000 (16:51 -0700)]
Fixed RegExp.prototype.replace().

The issue was introduced in cf85d0f8640a.

2 years agoFixed RegExp.prototype.split().
Dmitry Volyntsev [Fri, 6 Oct 2023 23:49:59 +0000 (16:49 -0700)]
Fixed RegExp.prototype.split().

The issue was introduced in c0aad58cfadb.

2 years agoXML: fixed exception handling.
Dmitry Volyntsev [Wed, 4 Oct 2023 22:00:02 +0000 (15:00 -0700)]
XML: fixed exception handling.

This closes #675 issue on Github.

2 years agoImproved memory footprint of RegExp.prototype.split().
Dmitry Volyntsev [Wed, 4 Oct 2023 20:35:38 +0000 (13:35 -0700)]
Improved memory footprint of RegExp.prototype.split().

2 years agoImproved memory footprint of RegExp.prototype.replace().
Dmitry Volyntsev [Wed, 4 Oct 2023 01:09:06 +0000 (18:09 -0700)]
Improved memory footprint of RegExp.prototype.replace().

2 years agoImproved memory footprint of RegExp.prototype.test().
Dmitry Volyntsev [Tue, 3 Oct 2023 07:39:04 +0000 (00:39 -0700)]
Improved memory footprint of RegExp.prototype.test().

2 years agoFS: introduced fs.existsSync().
Dmitry Volyntsev [Sat, 30 Sep 2023 04:41:34 +0000 (21:41 -0700)]
FS: introduced fs.existsSync().

2 years agoRegExp: improved memory footprint when match fails.
Dmitry Volyntsev [Fri, 29 Sep 2023 02:09:56 +0000 (19:09 -0700)]
RegExp: improved memory footprint when match fails.

2 years agoStream: adjusted periodic timeout in tests.
Dmitry Volyntsev [Fri, 29 Sep 2023 01:11:15 +0000 (18:11 -0700)]
Stream: adjusted periodic timeout in tests.

2 years agoFetch: fixed HEAD response handling with large Content-Length.
Dmitry Volyntsev [Thu, 28 Sep 2023 18:00:56 +0000 (11:00 -0700)]
Fetch: fixed HEAD response handling with large Content-Length.

This closes #658 issue on Github.

2 years agoModules: introduced console object.
Dmitry Volyntsev [Fri, 22 Sep 2023 20:00:06 +0000 (13:00 -0700)]
Modules: introduced console object.

The following methods were added: dump(), error(), info(),
log(), time(), timeEnd(), warn().

2 years agoIntroduced API to work with external value pointers.
Dmitry Volyntsev [Fri, 22 Sep 2023 20:00:05 +0000 (13:00 -0700)]
Introduced API to work with external value pointers.

This allows to allocate the necessary context for external
code on demand.

2 years agoModules: added debug log for vm cloning and destroying.
Dmitry Volyntsev [Fri, 22 Sep 2023 20:00:04 +0000 (13:00 -0700)]
Modules: added debug log for vm cloning and destroying.

2 years agoShell: simplified console.time()/timeEnd() pair.
Dmitry Volyntsev [Thu, 21 Sep 2023 19:40:53 +0000 (12:40 -0700)]
Shell: simplified console.time()/timeEnd() pair.

Using a queue instead of a hash here because we assume that the
number of profile timers will be low.

2 years agoShell: introduced error, info and warn methods for console object.
Dmitry Volyntsev [Thu, 21 Sep 2023 04:48:41 +0000 (21:48 -0700)]
Shell: introduced error, info and warn methods for console object.

2 years agoShell: improved shell_test.
Dmitry Volyntsev [Thu, 21 Sep 2023 02:19:58 +0000 (19:19 -0700)]
Shell: improved shell_test.

Setting more appropriate env variables for libedit since we moved to
libedit as a default readline library in 0.8.0.

2 years agoVersion bump.
Dmitry Volyntsev [Thu, 21 Sep 2023 23:11:20 +0000 (16:11 -0700)]
Version bump.

2 years agoAdded tag 0.8.1 for changeset a52b49f9afcf
Dmitry Volyntsev [Tue, 12 Sep 2023 18:57:00 +0000 (11:57 -0700)]
Added tag 0.8.1 for changeset a52b49f9afcf

2 years agoVersion 0.8.1. 0.8.1
Dmitry Volyntsev [Tue, 12 Sep 2023 18:54:22 +0000 (11:54 -0700)]
Version 0.8.1.

2 years agoTypes: added TS description for items() introduced in f5428bc87159.
Dmitry Volyntsev [Tue, 12 Sep 2023 18:36:15 +0000 (11:36 -0700)]
Types: added TS description for items() introduced in f5428bc87159.

2 years agoHTTP: avoid calling body filter when input chain is NULL.
Dmitry Volyntsev [Tue, 12 Sep 2023 03:34:48 +0000 (20:34 -0700)]
HTTP: avoid calling body filter when input chain is NULL.

This solves the problem of erroneous exception thrown in
r.internalRedirect() after 05c7f0b31856 (0.8.0).

2 years agoModules: improved debug log.
Dmitry Volyntsev [Sat, 9 Sep 2023 00:13:19 +0000 (17:13 -0700)]
Modules: improved debug log.

1) Ensuring that consistent prefixes are used:
"http js" in HTTP module and "stream js" in Stream module.
2) Added debug for every event/callback handler entrance.
3) Added debug with a method name for every JS call.

2 years agoFetch: renamed prefix http to fetch to avoid overlap with HTTP module.
Dmitry Volyntsev [Sat, 9 Sep 2023 00:52:07 +0000 (17:52 -0700)]
Fetch: renamed prefix http to fetch to avoid overlap with HTTP module.

2 years agoAdded flat hash overflow check.
Vadim Zhestikov [Fri, 8 Sep 2023 23:05:24 +0000 (16:05 -0700)]
Added flat hash overflow check.

2 years agoModules: implemented items() method of a shared dictionary.
Dmitry Volyntsev [Thu, 7 Sep 2023 23:12:40 +0000 (16:12 -0700)]
Modules: implemented items() method of a shared dictionary.

2 years agoTests: fixed incr() tests for a shared dictionary.
Dmitry Volyntsev [Thu, 7 Sep 2023 23:12:31 +0000 (16:12 -0700)]
Tests: fixed incr() tests for a shared dictionary.

Previously, the incr() method called SharedDict.incr() with a NaN value
as a second argument because parseInt(undefined) returns NaN.

The test itself failed to capture the issue because it matches the whole
HTTP response and the pattern itself was too short, so it matched
accidentally.

2 years agoShell: fixed file error message on CLI without interactive mode.
Dmitry Volyntsev [Thu, 7 Sep 2023 01:02:50 +0000 (18:02 -0700)]
Shell: fixed file error message on CLI without interactive mode.

This closes #669 issue on Github.

2 years agoModules: added a session object for js_periodic handler.
Dmitry Volyntsev [Wed, 6 Sep 2023 01:15:14 +0000 (18:15 -0700)]
Modules: added a session object for js_periodic handler.

Now js_periodic handler is provided with a session object as its first
argument. Session object can be used to access variables created with
js_set, js_var or map directives.

example.conf:
    js_var $js_var  JS-VAR;

    location @periodics {
        js_periodic main.handler interval=60s;
    }

example.js:
    function handler(s) {
        ngx.log(ngx.INFO, s.variables.js_var);
    }

2 years agoModules: added worker_affinity parameter for js_periodic directive.
Dmitry Volyntsev [Tue, 5 Sep 2023 16:17:10 +0000 (09:17 -0700)]
Modules: added worker_affinity parameter for js_periodic directive.

worker_affinity specifies on what set of workers the js_periodic handler
should be executed. By default the js_handler is executed only on worker 0.
The parameter accepts a binary mask or "all" to specify all workers.

example.conf:
worker_processes 4;

...
    location @periodics {
        # to be run at 1 minute intervals in worker 0
        js_periodic main.handler interval=60s;

        # to be run at 1 minute intervals in all the workers
        js_periodic main.handler interval=60s worker_affinity=all;

        # to be run at 1 minute intervals in workers 1 and 3
        js_periodic main.handler interval=60s worker_affinity=0101;
    }

2 years agoFixed typo introduced in c7d2a7846b0b.
Vadim Zhestikov [Thu, 31 Aug 2023 15:24:17 +0000 (08:24 -0700)]
Fixed typo introduced in c7d2a7846b0b.

Found by Coverity (CID 1542439).

2 years agoFixed js_periodic handler stopping after graceful shutdown.
Dmitry Volyntsev [Thu, 31 Aug 2023 03:59:11 +0000 (20:59 -0700)]
Fixed js_periodic handler stopping after graceful shutdown.

The issue was introduced in f1bd0b1db065.

2 years agoModules: fixed size() and keys() methods of a shared dictionary.
Dmitry Volyntsev [Thu, 31 Aug 2023 01:59:28 +0000 (18:59 -0700)]
Modules: fixed size() and keys() methods of a shared dictionary.

Previously, these methods did not take into the account exprired
entries. The expired entries appear in js_shared_dict_zone when timeout
directive is specified as the expired elements are not removed at the
moment they become stale right away.

This closes #665 issue on Github.

2 years agoIntroduced flat hash.
Vadim Zhestikov [Wed, 30 Aug 2023 19:06:12 +0000 (12:06 -0700)]
Introduced flat hash.

Object property enumeration order is corrected.
This fixes #189 issue on Github.

2 years agoFixed building by GCC with -O3.
Vadim Zhestikov [Wed, 23 Aug 2023 17:09:22 +0000 (10:09 -0700)]
Fixed building by GCC with -O3.

2 years agoModules: introduced js_periodic directive.
Dmitry Volyntsev [Tue, 22 Aug 2023 18:13:09 +0000 (11:13 -0700)]
Modules: introduced js_periodic directive.

The directive specifies a JS handler to run at regular intervals. The JS
handler will be executed in each worker process. The handler receives no
arguments. It has access to ngx and other global objects.

example.conf:
    location @periodics {
        # Specifies a JS handler to be run at 1 minute intervals
        js_periodic main.handler interval=60s jitter=5s;

        resolver 10.0.0.1;
        js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
    }

example.js:
    async function handler() {
        if (ngx.worker_id != 0) {
            /* using ngx.worker_id to run handler only in one worker. */
            return;
        }

        let reply = async ngx.fetch('https://nginx.org/en/docs/njs/');
        let body = async reply.text();

        ngx.log(ngx.INFO, body);
    }

This closes #660 issue on Github.

2 years agoHTTP: simplified events handling.
Dmitry Volyntsev [Tue, 22 Aug 2023 18:12:02 +0000 (11:12 -0700)]
HTTP: simplified events handling.

2 years agoFixed typos introduced in ff7eb3c4bf76.
Dmitry Volyntsev [Tue, 22 Aug 2023 18:12:01 +0000 (11:12 -0700)]
Fixed typos introduced in ff7eb3c4bf76.

2 years agoHTTP: fixed setting of Last-Modified header.
Dmitry Volyntsev [Wed, 12 Jul 2023 05:50:44 +0000 (22:50 -0700)]
HTTP: fixed setting of Last-Modified header.

Previously, r.headersOut['Last-Modified'] setter did not update
r->headers_out.last_modified. As a result a client might get two
Last-Modified headers.

2 years agoHTTP: fixed setting of Date header.
Dmitry Volyntsev [Wed, 12 Jul 2023 02:12:34 +0000 (19:12 -0700)]
HTTP: fixed setting of Date header.

Previously, r.headersOut['Date'] setter did not update
r->headers_out.date. As a result a client might get two
Date headers.

2 years agoVersion bump.
Dmitry Volyntsev [Tue, 11 Jul 2023 00:57:45 +0000 (17:57 -0700)]
Version bump.

2 years agoAdded tag 0.8.0 for changeset 0ed1952588ab
Dmitry Volyntsev [Thu, 6 Jul 2023 16:10:47 +0000 (09:10 -0700)]
Added tag 0.8.0 for changeset 0ed1952588ab

2 years agoVersion 0.8.0. 0.8.0
Dmitry Volyntsev [Thu, 6 Jul 2023 00:49:50 +0000 (17:49 -0700)]
Version 0.8.0.

2 years agoModules: introduced js_shared_dict_zone directive.
Dmitry Volyntsev [Mon, 3 Jul 2023 20:32:41 +0000 (13:32 -0700)]
Modules: introduced js_shared_dict_zone directive.

The directive allows to declare a dictionary that is shared among the
working processes. A dictionary expects strings as keys. It stores
string or number as values. The value type is declared using
type= argument of the directive. The default type is string.

example.conf:
    # Declares a shared dictionary of strings of size 1 Mb that
    # removes key-value after 60 seconds of inactivity.
    js_shared_dict_zone zone=foo:1M timeout=60s;

    # Declares a shared dictionary of strings of size 512Kb that
    # forcibly remove oldest key-value pairs when memory is not enough.
    js_shared_dict_zone zone=bar:512K timeout=30s evict;

    # Declares a permanent number shared dictionary of size 32Kb.
    js_shared_dict_zone zone=num:32k type=number;

example.js:
    function get(r) {
        r.return(200, ngx.shared.foo.get(r.args.key));
    }

    function set(r) {
        r.return(200, ngx.shared.foo.set(r.args.key, r.args.value));
    }

    function delete(r) {
        r.return(200, ngx.shared.bar.delete(r.args.key));
    }

    function increment(r) {
        r.return(200, ngx.shared.num.incr(r.args.key, 2));
    }

In collaboration with Artem S. Povalyukhin, Jakub Jirutka and
洪志道 (Hong Zhi Dao).

This closes #437 issue on Github.

2 years agoAdded njs_vm_external_constructor().
Dmitry Volyntsev [Mon, 3 Jul 2023 19:49:00 +0000 (12:49 -0700)]
Added njs_vm_external_constructor().

The new API allows to add new constructor/prototype pairs.

2 years agoTests: improved memory sanitizer build.
Dmitry Volyntsev [Sat, 1 Jul 2023 04:02:44 +0000 (21:02 -0700)]
Tests: improved memory sanitizer build.

Disable webcrypto tests because they required instrumented openssl.

2 years agoImproved interactive shell.
Vadim Zhestikov [Sat, 1 Jul 2023 02:49:46 +0000 (19:49 -0700)]
Improved interactive shell.

2 years agoFixed parsing of invalid for statement.
Vadim Zhestikov [Sat, 1 Jul 2023 02:49:45 +0000 (19:49 -0700)]
Fixed parsing of invalid for statement.

2 years agoTests: fixed benchmark after 57ca02d7404c.
Dmitry Volyntsev [Sat, 1 Jul 2023 00:03:11 +0000 (17:03 -0700)]
Tests: fixed benchmark after 57ca02d7404c.

2 years agoAdded constructor name for async function.
Vadim Zhestikov [Fri, 30 Jun 2023 13:38:36 +0000 (06:38 -0700)]
Added constructor name for async function.

2 years agoModules: introduced ngx.worker_id.
Dmitry Volyntsev [Fri, 30 Jun 2023 03:44:14 +0000 (20:44 -0700)]
Modules: introduced ngx.worker_id.

worker_id corresponds to an nginx internal worker id.
The value is between 0 and worker_processes - 1.

2 years agoIntroduced njs_vm_bind_handler().
Dmitry Volyntsev [Fri, 30 Jun 2023 01:58:45 +0000 (18:58 -0700)]
Introduced njs_vm_bind_handler().

2 years agoImproved Error.prototype.toString().
Dmitry Volyntsev [Thu, 29 Jun 2023 05:15:59 +0000 (22:15 -0700)]
Improved Error.prototype.toString().

Making method more generic by using njs_vm_property() when looking for
"name" and "message" properties in the prototype chain.

2 years agoUsing addon module API to unify injecting of external objects.
Dmitry Volyntsev [Thu, 29 Jun 2023 05:15:57 +0000 (22:15 -0700)]
Using addon module API to unify injecting of external objects.

2 years agoRemoved inappropriate "prototype" property for Math object.
Dmitry Volyntsev [Mon, 26 Jun 2023 23:47:17 +0000 (16:47 -0700)]
Removed inappropriate "prototype" property for Math object.

2 years agoFetch: fixed setting of Content-Type header.
Dmitry Volyntsev [Thu, 22 Jun 2023 22:40:36 +0000 (15:40 -0700)]
Fetch: fixed setting of Content-Type header.

Previously, Content-Type was set unconditionally to
"text/plain;charset=UTF-8" when fetch request contained a string body.
This may overlap with user's Content-Type.

The fix is to set the header only if it was not set before.

This fixes #654 issue on Github.

2 years agoXML: replaced Error with more suitable exception where approriate.
Dmitry Volyntsev [Thu, 22 Jun 2023 22:37:16 +0000 (15:37 -0700)]
XML: replaced Error with more suitable exception where approriate.

2 years agoZlib: replaced Error with more suitable exception where approriate.
Dmitry Volyntsev [Wed, 21 Jun 2023 23:30:12 +0000 (16:30 -0700)]
Zlib: replaced Error with more suitable exception where approriate.

2 years agoWebCrypto: added back custom exception types using new public API.
Dmitry Volyntsev [Wed, 21 Jun 2023 23:30:00 +0000 (16:30 -0700)]
WebCrypto: added back custom exception types using new public API.

In f1432043a6a4, when rewriting webcrypto module using public API all
the exceptions types were squashed into a single Error type. This patch
reintroduces the standard exception types back using new API.

2 years agoQueryString: added back custom exception types using new public API.
Dmitry Volyntsev [Wed, 21 Jun 2023 23:29:51 +0000 (16:29 -0700)]
QueryString: added back custom exception types using new public API.

In fd956d2a25a3, when rewriting querystring module using public API all
the exceptions types were squashed into a single Error type. This patch
reintroduces the standard exception types back using new API.

2 years agoCrypto: added back custom exception types using new public API.
Dmitry Volyntsev [Wed, 21 Jun 2023 23:29:48 +0000 (16:29 -0700)]
Crypto: added back custom exception types using new public API.

In b2cbf06ba017, when rewriting crypto module using public API all the
exceptions types were squashed into a single Error type. This patch
reintroduces the standard exception types back using new API.