]> git.kaiwu.me - njs.git/log
njs.git
3 years agoTests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev [Mon, 6 Feb 2023 17:36:13 +0000 (09:36 -0800)]
Tests: fixed js tests for Fetch API for nginx-1.22 and below.

The fix is to move a test with multiple headers returned by $http_a
variable under an nginx version check.

2 years agoFixed parsing of invalid for-var statement.
Vadim Zhestikov [Thu, 1 Jun 2023 16:39:27 +0000 (09:39 -0700)]
Fixed parsing of invalid for-var statement.

2 years agoFixed parsing of invalid for-in statement.
Vadim Zhestikov [Thu, 1 Jun 2023 16:39:25 +0000 (09:39 -0700)]
Fixed parsing of invalid for-in statement.

The issue was introduced in: b9d18d4dd34e

2 years agoRandom: prioritise CCRandomGenerateBytes over getentropy on macOs.
David CARLIER [Sun, 28 May 2023 14:36:46 +0000 (15:36 +0100)]
Random: prioritise CCRandomGenerateBytes over getentropy on macOs.

It is recommended approach by Apple itself.

2 years agoParser: improved error message for import statement.
Dmitry Volyntsev [Sat, 27 May 2023 04:54:12 +0000 (21:54 -0700)]
Parser: improved error message for import statement.

This closes #642 issue on Github.

2 years agoAdded %TypedArray%.prototype.toReversed().
Dmitry Volyntsev [Sat, 27 May 2023 04:05:15 +0000 (21:05 -0700)]
Added %TypedArray%.prototype.toReversed().

2 years agoAdded %TypedArray%.prototype.toSorted().
Dmitry Volyntsev [Sat, 27 May 2023 03:58:22 +0000 (20:58 -0700)]
Added %TypedArray%.prototype.toSorted().

2 years agoRemoved dead store introduced in 398f4de34fe7.
Dmitry Volyntsev [Sat, 27 May 2023 03:58:19 +0000 (20:58 -0700)]
Removed dead store introduced in 398f4de34fe7.

Found by Coverity (CID 1530432).

2 years agoFixed parsing of for-in loops.
Vadim Zhestikov [Sat, 27 May 2023 02:43:24 +0000 (19:43 -0700)]
Fixed parsing of for-in loops.

This fixes parsing for input like: for (a(b * in d) ;

The issue was introduced in 283ae119d121 (0.7.9).

2 years agoIntroduced Array.prototype.toReversed().
Dmitry Volyntsev [Sat, 27 May 2023 02:13:41 +0000 (19:13 -0700)]
Introduced Array.prototype.toReversed().

2 years agoIntroduced Array.prototype.toSpliced().
Dmitry Volyntsev [Sat, 27 May 2023 02:13:41 +0000 (19:13 -0700)]
Introduced Array.prototype.toSpliced().

2 years agoHTTP: throwing an exception in r.internalRedirect() while filtering.
Dmitry Volyntsev [Sat, 27 May 2023 02:13:39 +0000 (19:13 -0700)]
HTTP: throwing an exception in r.internalRedirect() while filtering.

A user is notified explicitly that r.internalRedirect()
is not supported in filters.

2 years agoImplemented Array.prototype.toSorted().
Dmitry Volyntsev [Thu, 25 May 2023 05:04:38 +0000 (22:04 -0700)]
Implemented Array.prototype.toSorted().

2 years agoTypes: added TS types for ngx properties added in 25b55a064e42.
Dmitry Volyntsev [Wed, 24 May 2023 06:47:43 +0000 (23:47 -0700)]
Types: added TS types for ngx properties added in 25b55a064e42.

2 years agoWebCrypto: introduced CryptoKey properties.
Dmitry Volyntsev [Wed, 24 May 2023 03:58:40 +0000 (20:58 -0700)]
WebCrypto: introduced CryptoKey properties.

The following properties for CryptoKey were added:
    algorithm, extractable, type, usages.

2 years agoWebCrypto: making njs_webcrypto_key_t more compact by using union.
Dmitry Volyntsev [Tue, 23 May 2023 05:48:59 +0000 (22:48 -0700)]
WebCrypto: making njs_webcrypto_key_t more compact by using union.

2 years agoWebCrypto: sorted njs_webcrypto_alg accoding to njs_webcrypto_alg_t.
Dmitry Volyntsev [Tue, 23 May 2023 05:48:58 +0000 (22:48 -0700)]
WebCrypto: sorted njs_webcrypto_alg accoding to njs_webcrypto_alg_t.

So njs_webcrypto_alg[alg->type] can be used to get the algorithm name.

2 years agoTests: imported nginx modules tests from nginx-tests.
Dmitry Volyntsev [Tue, 23 May 2023 00:59:47 +0000 (17:59 -0700)]
Tests: imported nginx modules tests from nginx-tests.

2 years agoRemoved leftover String.prototype.toBytes() from benchmark test.
Dmitry Volyntsev [Sat, 20 May 2023 04:29:23 +0000 (21:29 -0700)]
Removed leftover String.prototype.toBytes() from benchmark test.

The String.prototype.toBytes() and friends were removed in
4df790f42ce7.

2 years agoShell: removed support for building with GNU readline.
Dmitry Volyntsev [Sat, 20 May 2023 03:22:16 +0000 (20:22 -0700)]
Shell: removed support for building with GNU readline.

2 years agoShell: improved working with libedit.
Dmitry Volyntsev [Sat, 20 May 2023 03:22:16 +0000 (20:22 -0700)]
Shell: improved working with libedit.

Previously, libedit unlike GNU readline does not reinstall
rl_callback_handler_install handler after the handler was called.  As a
result make shell_test executed ~20 times longer with libedit.

The fix is to reinstall the rl_callback_handler_install handler
explicitely every time the handler is invoked.

2 years agoFS: added support of OpenBSD for fs.stat() and friends.
Dmitry Volyntsev [Sat, 20 May 2023 03:22:15 +0000 (20:22 -0700)]
FS: added support of OpenBSD for fs.stat() and friends.

2 years agoAdded support of regular expressions not supported directly by PCRE2.
Dmitry Volyntsev [Sat, 20 May 2023 03:22:14 +0000 (20:22 -0700)]
Added support of regular expressions not supported directly by PCRE2.

The following patterns were fixed:
    `[]` - matches nothing, previously was rejected as invalid expression.
    `[^]` - matched any character, unlike `.` this syntax matches new
        line, previously was rejected as invalid expression.
    `++`, `*+`, `?+` - are rejected now, whereas in PCRE2 they are considered
        valid possessive quantifiers.

2 years agoImplemented Array.from().
Dmitry Volyntsev [Fri, 19 May 2023 01:33:36 +0000 (18:33 -0700)]
Implemented Array.from().

2 years agoModules: introduced global nginx properties.
Dmitry Volyntsev [Thu, 18 May 2023 04:16:19 +0000 (21:16 -0700)]
Modules: introduced global nginx properties.

The following properties were introduced:
    ngx.build - an optional nginx build name, corresponds to
        --build=name argument of configure script, by default is "".
    ngx.conf_file_path - the file path to current nginx configuration
        file.
    ngx.error_log_path - the file path to current error log file.
    ngx.prefix - the directory that keeps server files.
    ngx.version - the nginx version as a string, for example: "1.25.0".
    ngx.version_number - the nginx version as a number, for example:
        1025000.

2 years agoChange: removed deprecated r.requestBody and r.responseBody.
Dmitry Volyntsev [Thu, 18 May 2023 00:11:41 +0000 (17:11 -0700)]
Change: removed deprecated r.requestBody and r.responseBody.

Both properties were deprecated since 0.5.0.

2 years agoFixed implicit name for a function expression declared in arrays.
Dmitry Volyntsev [Wed, 17 May 2023 07:39:56 +0000 (00:39 -0700)]
Fixed implicit name for a function expression declared in arrays.

2 years agoFixed evaluation of computed property names with function expressions.
Dmitry Volyntsev [Wed, 17 May 2023 07:39:45 +0000 (00:39 -0700)]
Fixed evaluation of computed property names with function expressions.

Previously, while evaluating a property name expression with a function
expression as the right side, the evaluation modified the value used to
compute the property name in-place.  The in-place modification changes
values not intended to be changed.

The issue was introduced in 74d30c2d70f3 (0.7.8).

This fixes #640 issue on Github.

3 years agoAlways use a sharp (#) symbol as the sed separator.
Sergey A. Osokin [Fri, 12 May 2023 23:38:29 +0000 (19:38 -0400)]
Always use a sharp (#) symbol as the sed separator.

sed(1) command line utility may fail with the following error:
sed: 1: "s, at EXTRA_LIBS@,-lm   -L ...": bad in substitute command: '-'
when a replacement for @EXTRA_LIBS@ contains a comma symbol.

2 years agoRemoved unneeded variable after fd956d2a25a3.
Dmitry Volyntsev [Wed, 17 May 2023 03:58:23 +0000 (20:58 -0700)]
Removed unneeded variable after fd956d2a25a3.

3 years agoModules: added options to disable parts dependant on 3rd party libs.
Dmitry Volyntsev [Thu, 11 May 2023 05:36:53 +0000 (22:36 -0700)]
Modules: added options to disable parts dependant on 3rd party libs.

The following environment variables are added: NJS_OPENSSL, NJS_LIBXSLT,
NJS_ZLIB.  When a variable evaluates to "NO" the part of the module
related to the corresponsing library is disabled.

For example to disable libxslt related code:
    NJS_LIBXSLT=NO ./configure  .. --add-module=/path/to/njs/module

3 years agoFixed memory allocation failure introduced in fc8d1b125cef.
Dmitry Volyntsev [Thu, 11 May 2023 03:50:53 +0000 (20:50 -0700)]
Fixed memory allocation failure introduced in fc8d1b125cef.

Found by Coverity (CID 1529969).

3 years agoFetch: insuring Host header is always the first header.
Dmitry Volyntsev [Wed, 10 May 2023 05:09:13 +0000 (22:09 -0700)]
Fetch: insuring Host header is always the first header.

3 years agoFetch: removed special treatment of forbidden headers.
Dmitry Volyntsev [Wed, 10 May 2023 05:09:13 +0000 (22:09 -0700)]
Fetch: removed special treatment of forbidden headers.

In c43261bad627 (0.7.10), a notion of forbidden headers was introduced
in accordance in Fetch API.  In the API the Forbidden headers are not
allowed to be changed from JavaScript code for security reasons.

The restriction is removed because there are use cases where Host (which
is considered forbidden) is different from the host address in
URL and JavaScript code is expected to be a trusted source (unlike a
browser context).

This closes #638 issue on Github.

3 years agoShell: added $262 as external in CLI.
Dmitry Volyntsev [Wed, 10 May 2023 01:58:52 +0000 (18:58 -0700)]
Shell: added $262 as external in CLI.

3 years agoShell: CLIs is rewritten using public API.
Dmitry Volyntsev [Wed, 10 May 2023 01:18:33 +0000 (18:18 -0700)]
Shell: CLIs is rewritten using public API.

3 years agoShell: simplified input completion handler.
Dmitry Volyntsev [Tue, 9 May 2023 05:03:32 +0000 (22:03 -0700)]
Shell: simplified input completion handler.

Previously, the completion logic was split between njs_vm_completion()
and njs_completion_generator() in shell.  Now the completion part is
done in njs_vm_completion(), as a result njs_completion_generator()
is simplified.

3 years agoHTTP: fixed r.status setter when filtering.
Dmitry Volyntsev [Mon, 8 May 2023 23:40:50 +0000 (16:40 -0700)]
HTTP: fixed r.status setter when filtering.

3 years agoRemoved dead store introduced in fd956d2a25a3.
Dmitry Volyntsev [Sat, 6 May 2023 03:08:58 +0000 (20:08 -0700)]
Removed dead store introduced in fd956d2a25a3.

Found by Clang static analyzer.

3 years agoTests: unit tests are rewritten using public API.
Dmitry Volyntsev [Sat, 6 May 2023 03:08:57 +0000 (20:08 -0700)]
Tests: unit tests are rewritten using public API.

njs_to_int32_test is replaced with ordinary script tests.

3 years agoChange: non-compliant deprecated String methods were removed.
Dmitry Volyntsev [Sat, 6 May 2023 03:08:56 +0000 (20:08 -0700)]
Change: non-compliant deprecated String methods were removed.

The following methods were removed:
    String.bytesFrom(),
    String.prototype.fromBytes(),
    String.prototype.fromUTF8(),
    String.prototype.toBytes(),
    String.prototype.toUTF8(),
    String.prototype.toString(encoding).

Because String.bytesFrom() was used to test the existing code
which works with byte strings it was replaced with $262.bytesString()
which is only available in unit tests.

3 years agoRefactored $262 object as external.
Dmitry Volyntsev [Sat, 6 May 2023 03:08:55 +0000 (20:08 -0700)]
Refactored $262 object as external.

This allows to decouple $262 object which is only needed
for tests from the njs core.

3 years agoWebCrypto: fixed building with OpenSSL 1.1.0.
Dmitry Volyntsev [Fri, 5 May 2023 05:15:46 +0000 (22:15 -0700)]
WebCrypto: fixed building with OpenSSL 1.1.0.

The issue was introduced in 0681bf662222 (0.7.10).

This closes #636 issue on Github.

3 years agoWebCrypto: module is rewritten using public API.
Dmitry Volyntsev [Wed, 3 May 2023 03:50:57 +0000 (20:50 -0700)]
WebCrypto: module is rewritten using public API.

3 years agoFS: module is rewritten using public API.
Dmitry Volyntsev [Wed, 3 May 2023 03:50:55 +0000 (20:50 -0700)]
FS: module is rewritten using public API.

3 years agoQueryString: module is rewritten using public API.
Dmitry Volyntsev [Wed, 3 May 2023 03:50:55 +0000 (20:50 -0700)]
QueryString: module is rewritten using public API.

3 years agoCrypto: module is rewritten using public API.
Dmitry Volyntsev [Wed, 3 May 2023 03:50:52 +0000 (20:50 -0700)]
Crypto: module is rewritten using public API.

3 years agoFixed typos introduced in 5e7fc8efebdc.
Dmitry Volyntsev [Wed, 3 May 2023 03:50:46 +0000 (20:50 -0700)]
Fixed typos introduced in 5e7fc8efebdc.

3 years agoIntroduced njs_value_buffer_get().
Dmitry Volyntsev [Tue, 2 May 2023 00:54:48 +0000 (17:54 -0700)]
Introduced njs_value_buffer_get().

3 years agoPublic header cleanup.
Dmitry Volyntsev [Wed, 3 May 2023 03:33:30 +0000 (20:33 -0700)]
Public header cleanup.

3 years agoMade njs_string.h includable independently from njs_main.h.
Dmitry Volyntsev [Tue, 2 May 2023 03:45:32 +0000 (20:45 -0700)]
Made njs_string.h includable independently from njs_main.h.

3 years agoWebCrypto: fixed retval of crypto.getRandomValues().
Dmitry Volyntsev [Fri, 28 Apr 2023 00:28:52 +0000 (17:28 -0700)]
WebCrypto: fixed retval of crypto.getRandomValues().

Previously, crypto.getRandomValues() did not return any value,
but it has to return its buffer argument.

3 years agoRefactored njs_object_iterate() API.
Dmitry Volyntsev [Thu, 27 Apr 2023 04:19:48 +0000 (21:19 -0700)]
Refactored njs_object_iterate() API.

As a side-effect it fixes dangling-pointer compilation error
found by GCC 13.1.

3 years agoSource files sorted into groups.
Dmitry Volyntsev [Thu, 27 Apr 2023 02:38:27 +0000 (19:38 -0700)]
Source files sorted into groups.

System, data structures, VM, parser, generator, standard objects.

3 years agoTypes: added ts types for "zlib" module.
Dmitry Volyntsev [Thu, 27 Apr 2023 02:38:23 +0000 (19:38 -0700)]
Types: added ts types for "zlib" module.

3 years agoTypes: added forgotten ts types for XML modification API.
Dmitry Volyntsev [Thu, 27 Apr 2023 02:38:21 +0000 (19:38 -0700)]
Types: added forgotten ts types for XML modification API.

3 years agoTypes: added definitions for Hash.copy() method.
Dmitry Volyntsev [Thu, 27 Apr 2023 02:38:13 +0000 (19:38 -0700)]
Types: added definitions for Hash.copy() method.

3 years agoTests: dropping all environment variables in a portable way.
Dmitry Volyntsev [Thu, 27 Apr 2023 00:27:48 +0000 (17:27 -0700)]
Tests: dropping all environment variables in a portable way.

This fixes njs_unit_test crash on macOS.

The issue was introduced in 0.7.8.

3 years agoChange: native methods are provided with retval argument.
Dmitry Volyntsev [Wed, 19 Apr 2023 07:20:37 +0000 (00:20 -0700)]
Change: native methods are provided with retval argument.

Previously, native methods were expected to return
their retval using vm->retval.  This caused problem in the part
(1aa137411b09293fe42c5e1c) because vm->retval can be overwritten
unexpectedly as a side-effect of operations like ToString(), ToNumber().

The fix is to never used a global retval. Instead methods
are provided with a retval argument to store their retval value.

As a part of the change, retval and exception values are split.
The normal value is returned in the retval argument.
The exception value is thrown by njs_vm_throw() or njs_vm_error().
The exception value can be acquired using njs_vm_exception_get().

3 years agoVM: simplified NJS_VMCODE_TEMPLATE_LITERAL instruction.
Dmitry Volyntsev [Thu, 13 Apr 2023 01:26:42 +0000 (18:26 -0700)]
VM: simplified NJS_VMCODE_TEMPLATE_LITERAL instruction.

3 years agoVM: removed unused NJS_VMCODE_OBJECT_COPY instruction.
Dmitry Volyntsev [Thu, 13 Apr 2023 01:26:40 +0000 (18:26 -0700)]
VM: removed unused NJS_VMCODE_OBJECT_COPY instruction.

3 years agoSimplified functional stack unwinding.
Dmitry Volyntsev [Tue, 11 Apr 2023 06:06:34 +0000 (23:06 -0700)]
Simplified functional stack unwinding.

3 years agoVersion bump.
Dmitry Volyntsev [Tue, 11 Apr 2023 06:06:29 +0000 (23:06 -0700)]
Version bump.

3 years agoAdded tag 0.7.12 for changeset a1faa64d4972
Dmitry Volyntsev [Mon, 10 Apr 2023 16:53:24 +0000 (09:53 -0700)]
Added tag 0.7.12 for changeset a1faa64d4972

3 years agoVersion 0.7.12. 0.7.12
Dmitry Volyntsev [Mon, 10 Apr 2023 16:50:19 +0000 (09:50 -0700)]
Version 0.7.12.

3 years agoTests: improved shell_test portability to different environments.
Dmitry Volyntsev [Wed, 5 Apr 2023 05:19:49 +0000 (22:19 -0700)]
Tests: improved shell_test portability to different environments.

3 years agoVM: removed vm->variables_hash.
Dmitry Volyntsev [Wed, 5 Apr 2023 05:19:48 +0000 (22:19 -0700)]
VM: removed vm->variables_hash.

3 years agoVM: removed vm->global_items.
Dmitry Volyntsev [Wed, 5 Apr 2023 05:17:26 +0000 (22:17 -0700)]
VM: removed vm->global_items.

3 years agoAligned Number constructor to the spec.
Dmitry Volyntsev [Thu, 30 Mar 2023 03:28:33 +0000 (20:28 -0700)]
Aligned Number constructor to the spec.

Previously, negative hexadecimal numbers were accepted as valid,
whereas they are invalid input for the constructor.
Also previously, the constructor did not accepted positive binary or
octadecimal numbers as valid.

This closes #630 issue on Github.

3 years agoAdded "zlib" module.
Dmitry Volyntsev [Tue, 28 Mar 2023 05:41:27 +0000 (22:41 -0700)]
Added "zlib" module.

    - zlib.deflateRawSync(string|buffer, options?) compresses data using
        deflate, and do not append a zlib header, returns Buffer.
    - zlib.deflateSync(string|buffer, options?) compresses data using
        deflate, returns Buffer.
    - zlib.inflateRawSync(string|buffer) decompresses a raw deflate
        stream, returns Buffer.
    - zlib.inflateSync(string|buffer) decompresses a deflate stream,
        return Buffer.

3 years agoFix compiler detection when CC has a wrapper.
Orgad Shaneh [Wed, 22 Mar 2023 13:22:37 +0000 (15:22 +0200)]
Fix compiler detection when CC has a wrapper.

For example CC='ccache gcc'.

3 years agoFixed invalid NULL pointer check.
Vadim Zhestikov [Wed, 22 Mar 2023 16:36:58 +0000 (09:36 -0700)]
Fixed invalid NULL pointer check.

This fixes Coverity issues CID 1524495 and CID 1524494.

3 years agoCrypto: added Hash.copy() method.
Dmitry Volyntsev [Tue, 21 Mar 2023 04:25:47 +0000 (21:25 -0700)]
Crypto: added Hash.copy() method.

This closes #625 issue on Github.

3 years agoAdded support for export {name as default} statement.
Vadim Zhestikov [Tue, 21 Mar 2023 04:09:58 +0000 (21:09 -0700)]
Added support for export {name as default} statement.

This fixes #624 issue on Github.

3 years agoFetch: fixed Headers() constructor.
Dmitry Volyntsev [Fri, 10 Mar 2023 22:15:29 +0000 (14:15 -0800)]
Fetch: fixed Headers() constructor.

Previously, the 'guard' field of ngx_js_headers_t structure was uninitialized,
that caused spurious exception "Error: cannot append to immutable object".

This issue was introduced on 0.7.10.

3 years agoVersion bump.
Dmitry Volyntsev [Fri, 10 Mar 2023 21:28:21 +0000 (13:28 -0800)]
Version bump.

3 years agoAdded tag 0.7.11 for changeset 26dd3824b9f3
Dmitry Volyntsev [Thu, 9 Mar 2023 21:21:48 +0000 (13:21 -0800)]
Added tag 0.7.11 for changeset 26dd3824b9f3

3 years agoVersion 0.7.11. 0.7.11
Dmitry Volyntsev [Thu, 9 Mar 2023 17:26:03 +0000 (09:26 -0800)]
Version 0.7.11.

3 years agoFixed String.prototype.replace() with replacement containing "$'", "$`".
Dmitry Volyntsev [Wed, 8 Mar 2023 04:51:45 +0000 (20:51 -0800)]
Fixed String.prototype.replace() with replacement containing "$'", "$`".

Previously, the resulting string was might be broken when the string to
replace and the search string were UTF-8.  pos is always a character
offset, it should not be directly used as a byte size or offset.

3 years agoMaking njs_string_prop() a macro.
Dmitry Volyntsev [Wed, 8 Mar 2023 04:38:08 +0000 (20:38 -0800)]
Making njs_string_prop() a macro.

3 years agoIntroduced njs_string_offset() which support any string.
Dmitry Volyntsev [Wed, 8 Mar 2023 04:35:00 +0000 (20:35 -0800)]
Introduced njs_string_offset() which support any string.

3 years agoImproved njs_string_create_chb().
Dmitry Volyntsev [Sat, 4 Mar 2023 02:50:23 +0000 (18:50 -0800)]
Improved njs_string_create_chb().

Adding a more informative description when the function cannot build a
valid UTF-8 string out of chained buffers.

3 years agoFixed njs_string_to_number() with additional space symbols.
Artem S. Povalyukhin [Fri, 3 Mar 2023 19:57:30 +0000 (22:57 +0300)]
Fixed njs_string_to_number() with additional space symbols.

This closes #621 issue on Github.

3 years agoFixed Array.prototype.sort() when array is changed while sorting.
Dmitry Volyntsev [Sat, 4 Mar 2023 01:49:11 +0000 (17:49 -0800)]
Fixed Array.prototype.sort() when array is changed while sorting.

Previously, the fast-path check did not take into account the fact that
the flat array may be resized as a side effect of the array's values
evaluation.

In addition, the slow_path fix ensures that "this" array is repopulated
again even if the array was resized.

This fixes #594 issue on Github.

3 years agoFetch: fixed typo in debug level.
Dmitry Volyntsev [Sat, 4 Mar 2023 01:49:10 +0000 (17:49 -0800)]
Fetch: fixed typo in debug level.

3 years agoXML: removed XML_PARSE_DTDVALID during a document parsing.
Dmitry Volyntsev [Thu, 2 Mar 2023 05:38:09 +0000 (21:38 -0800)]
XML: removed XML_PARSE_DTDVALID during a document parsing.

When XML_PARSE_DTDVALID is enabled libxml2 parses and executes external
entities present inside an xml document.  This can lead to all the
classic XXE exploits, including SSRF and local file disclosure.

The issue was introduced in 99b9f83e4d4d (0.7.10).

Thanks to @BitK_.

3 years agoXML: fixed memory leaks in node.$tags set handler.
Dmitry Volyntsev [Wed, 1 Mar 2023 04:34:38 +0000 (20:34 -0800)]
XML: fixed memory leaks in node.$tags set handler.

If xmlAddChild() failed the node pointer leaked,
if xmlReconciliateNs() failed the copy pointer leaked.

3 years agoXML: fixed memory leak when exception happens in node.addChild().
Dmitry Volyntsev [Wed, 1 Mar 2023 04:34:31 +0000 (20:34 -0800)]
XML: fixed memory leak when exception happens in node.addChild().

The issue was introduced in 3891f338e2c9.

Found by Coverity (CID 1521487).

3 years agoFixed attaching of a stack to an error object.
Dmitry Volyntsev [Tue, 28 Feb 2023 08:26:45 +0000 (00:26 -0800)]
Fixed attaching of a stack to an error object.

This problem is similar to previous commits.  When
njs_error_stack_attach() accepted the value as a pointer to vm->retval
that value might be changed as a side effert of njs_error_stack_new()
evaluation.  This may result in a garbage value for
njs_object(value) expression.

The workaround fix is to make a copy of vm->retval to ensure its
intergrity and to preserve it as a retval. The proper fix is to
eliminate vm->retval altogether.

This fixes #612, #613, #616 issues on Github.

3 years agoWebCrypto: fixed compilation with --debug=YES.
Dmitry Volyntsev [Tue, 28 Feb 2023 07:55:55 +0000 (23:55 -0800)]
WebCrypto: fixed compilation with --debug=YES.

The issue was introduced in 2e3bbe8743af (0.7.10).

3 years agoFixed a func instance dumping with "name" as getter.
Dmitry Volyntsev [Tue, 28 Feb 2023 06:14:36 +0000 (22:14 -0800)]
Fixed a func instance dumping with "name" as getter.

After njs_value_property() call the value argument might be
overwritten.

This is similar to #615.

3 years agoFixed njs_object_property() with NJS_WHITEOUT properties.
Dmitry Volyntsev [Tue, 28 Feb 2023 06:14:36 +0000 (22:14 -0800)]
Fixed njs_object_property() with NJS_WHITEOUT properties.

Previosly, an error object dumping might result in invalid pointer
dereference when 'name' or 'message' property of accessor descriptor
type was added and removed before.

The fix is to properly handle NJS_WHITEOUT properties.

This fixes #617 issue on Github.

3 years agoFixed array instance with a getter property dumping.
Dmitry Volyntsev [Tue, 28 Feb 2023 06:14:36 +0000 (22:14 -0800)]
Fixed array instance with a getter property dumping.

This closes #618 issue on Github.

3 years agoFixed Error() instance dumping when "name" prop is not primitive.
Dmitry Volyntsev [Tue, 28 Feb 2023 06:14:34 +0000 (22:14 -0800)]
Fixed Error() instance dumping when "name" prop is not primitive.

Previously, njs_error_to_string2() might be invoked with error argument
pointing to vm->retval.  When "name" prop was not primitive vm->retval
might be overwritten.  As a result error pointer might be referencing a
primitive value.  In turn the second call of njs_object_property()
received an invalid object pointer because it expects only object value
types.

The fix is to ensure that error object pointer is never overwritten.

This closes #615 issue on Github.

3 years agoUnit tests: replacing njs_vm_retval_string() with njs_vm_retval_dump().
Dmitry Volyntsev [Tue, 28 Feb 2023 03:05:03 +0000 (19:05 -0800)]
Unit tests: replacing njs_vm_retval_string() with njs_vm_retval_dump().

The change allows to cover CLI behaviour more closely.

3 years agoParser: fixed the detection of await in arguments.
Vadim Zhestikov [Tue, 28 Feb 2023 02:39:44 +0000 (18:39 -0800)]
Parser: fixed the detection of await in arguments.

This fixes #619 issue on Github.

3 years agoStream: added missed linking with libxml2 for the dynamic module.
Dmitry Volyntsev [Tue, 28 Feb 2023 02:16:01 +0000 (18:16 -0800)]
Stream: added missed linking with libxml2 for the dynamic module.

The issue was introduced in 99b9f83e4d4d (0.7.10).

3 years agoXML: added XMLNode API to modify XML documents.
Dmitry Volyntsev [Thu, 23 Feb 2023 03:13:08 +0000 (19:13 -0800)]
XML: added XMLNode API to modify XML documents.

    - delete node.$attr$a is a shorthand syntax for
        node.removeAttribute('a')

    - node.removeAllAttributes() removes all attributes of the node.

    - node.removeAttribute(attr_name) removes attribute named
        attr_name.

    - node.setAttribute(attr_name, value || null) sets a value for an
    attr_name. When value is null attribute named attr_name is
    deleted.

    - node.$attr$a = 'xxx' is a shorthand syntax for
        node.setAttribute('a', 'xxx');

    - The methods and operations below make copy-on-write
        changes to the original XML parsed document.

        For example:
        var doc = xml.parse(<r><a><b/></a></r>);
        var b = doc.$root.a.b;
        doc.$root.removeAllChildren();

        console.log((new TextDecoder()).decode(xml.c14n(doc))); /* <r></r> */
        console.log(b); /* XMLNode {$name:'b'} */
        console.log(b.$parent); /* XMLNode {$name:'a',$tags:[XMLNode
                                  {$name:'b'}] */

        "b" is valid after removeAllChildren() call, but is not a part
        of the document tree anymore.

    - node.addChild(nd) adds XMLNode as a child to node.
      nd recursively copied before adding to the node.

    - node.removeChildren(tag_name?) removes all the children tags
        named tag_name. If tag_name is absent all children tags are
        removed.

    - node.removeText() removes the node's text value.

    - node.setText(string || null) sets a text value for the node.
        When value is null the node's text is deleted.

    - node.$tags = [node1, node2, ..] is a shorthand syntax for
        node.removeChildren();
        node.addChild(node1);
        node.addChild(node2)

    - node.$text = 'xxx' is a shorthand syntax for
        node.setText('xxx');

    In addition the following method were added:
    - xml.serialize() is the same as xml.c14n()

    - xml.serializeToString() is the same as xml.c14n()
        except it returns the result as string.

    Example:
        const xml = require("xml");
        let data = `<note><to b="bar" a="foo">Tove</to><from>Jani</from></note>`;
        let doc = xml.parse(data);

        doc.$root.to.$attr$b = 'bar2';
        doc.$root.to.setAttribute('c', 'baz');
        delete doc.$root.to.$attr$a;

        console.log(xml.serializeToString(doc.$root.to)) /* '<to b="bar2" c="baz">Tove</to>' */

        doc.$root.to.removeAllAttributes();
        doc.$root.from.$text = 'Jani2';

        console.log(xml.serializeToString(doc)) /* '<note><to>Tove</to><from>Jani2</from></note>' */

        doc.$root.to.$tags = [xml.parse(`<a/>`), xml.parse(`<b/>`)];
        doc.$root.to.addChild(xml.parse(`<a/>`));

        console.log(xml.serializeToString(doc.$root.to)) /* '<to><a></a><b></b><a></a></to>' */

        doc.$root.to.removeChildren('a');

        console.log(xml.serializeToString(doc.$root.to)) /* '<to><b></b></to>' */

3 years agoAdded njs_vm_value_to_c_string().
Dmitry Volyntsev [Sat, 18 Feb 2023 06:38:25 +0000 (22:38 -0800)]
Added njs_vm_value_to_c_string().

3 years agoTypes: updated Fetch API types.
Dmitry Volyntsev [Fri, 10 Feb 2023 02:34:51 +0000 (18:34 -0800)]
Types: updated Fetch API types.