Stream: improved async callback support for s.send().
Previously, the "from_upstream" flag (introduced in b33aae5e8dc6) was
ignored for s.send() calls invoked directly from a body filter.
This makes the s.send() behaviour context dependent.
The fix is to always take "from_upstream" flag into account when it is
provided.
Fixed property set instruction when key modifies base binding.
Previously, when obj[prop] expression was evaluated, and prop was an
object with custom "toString" method, which modifies obj binding as its
side-effect, the binding update was visible to property set instruction
which is not correct.
Fixed String.prototype.trimEnd() with unicode string.
Previously, when the method was invoked with a string consisting of space
characters and at least one of them was a Unicode space separator (code
point above 127) it returned invalid string value with non-zero size
but zero length.
The fix is to update the size of the resulting string appropriately.
Dmitry Volyntsev [Tue, 30 Aug 2022 04:09:12 +0000 (21:09 -0700)]
Fixed njs_value_to_string() with non-writable dst argument.
njs_arg(args, nargs, N) returns a pointer to Nth argument OR a pointer
to undefined constant value njs_value_undefined if N >= nargs.
njs_value_to_string() writes to a dst argument its result.
This means that it is incorrect to use value of njs_arg() directly
as a second argument to njs_value_to_string().
Dmitry Volyntsev [Wed, 24 Aug 2022 02:36:16 +0000 (19:36 -0700)]
Stream: improved s.send() with async callbacks.
Previously, s.send() was a context dependant method because the
direction it was sending data to was determined by a callback (upstream
or downstream) it was called from. This works for synchronous
callbacks it was originally designed, but fails with async functions
(e.g. ngx.fetch()).
The fix is to store the direction data was going to as a separate flag
which can be used by s.send().
Modules: extending allowed context for js directives.
HTTP: js_import, js_path, js_set and js_var are allowed in server and
location contexts. js_content, js_body_filter and js_header_filter
are allowed in 'if' context.
Stream: js_import, js_path, js_set and js_var are allowed in server context.
Throwing SyntaxError for octal escape sequences and \8 and \9.
Error messages are same as messages generated by FireFox, because
they are looks more informative in comparison with messages
generated by chrome, nodejs, quickjs.
HTTP: fixed r.headersOut setter for special headers.
The issue was introduced in 5b7676ec600d (0.7.5) when njs module was
adapted to changes in nginx/1.23 related to header structures.
When special headers (Content-Length, Content-Type, Content-Encoding)
were set, the value of the last outgoing header might be overwritten
with a new set value.
Ensuring that double type is always evaluated at standard precision.
Previously, GCC on x86 uses extended precision for intermediate
calculations by default. This might conflict with njs_diyfp_t because
GCC is not always rounds back the intermediate values to standard
precision.
The fix is to explicitly tell to a compiler to do so.
Dmitry Volyntsev [Wed, 29 Jun 2022 06:04:00 +0000 (23:04 -0700)]
Fixed break instruction in a try-catch block.
Previously, JUMP offset for a break instruction inside a try-catch
block was not set to a correct offset during code generation
when a return instruction was present in inner try-catch block.
The fix is to update the JUMP offset appropriately.
Dmitry Volyntsev [Fri, 17 Jun 2022 00:33:49 +0000 (17:33 -0700)]
Fixed working with array-like object in Promise.all() and friends.
Prevously, the code while iterating over an array-like object did not
take into account objects with absent elements. As a result, the
resulting array object was returning with elements containing garbage
values.
The fix is to allocate and fill the resulting array object on the fly.
Dmitry Volyntsev [Thu, 16 Jun 2022 00:10:39 +0000 (17:10 -0700)]
Propertly handling NJS_DECLINE in promise native functions.
Previously, NJS_DECLINE was returned from a Promise.all() and friends
when "resolve" property was not found in a promise constructor.
NJS_DECLINE was treated as NJS_ERROR in one place, but as NJS_OK in a
different place during the promise function evaluation. As a result,
the VM was left in inconsistent state during stack unwinding which
resulted in a garbage return value.
The fix is to ensure that only NJS_ERROR or NJS_OK is returned
from ordinary native functions.
Fixed template literal from producing byte-strings.
Previously, as a side effect of creating a key for the values hash a
byte-string was created. This byte-string was reused internally and
might appear in template literal. As a result a byte-string was
produced as a value for a template literal. Byte-strings are obsolete
and are scheduled for removal because they can cause issues with
internal routines not prepared for them.
Fixed typed-array ctor when source array is changed while iterating.
Previously, the function used optimization for ordinary arrays with no
gaps (so called fast arrays). For a fast array code took elements
directly from internal flat C array. The direct pointer may become
invalid as side-effect of custom valueOf() method for an element.
The fix is to eliminate the micro-optimization which uses direct
pointers.
The problem is similar to the 9578cc729205 (0.7.2) commit.
Previously, while interpreting a user function, njs_vmcode_interpreter()
might return prematurely when an error happens in await instruction.
This is not correct because the current frame has to be unwound (or
exception caught) first.
The fix is to exit through only 5 appropriate exit points to ensure
proper unwinding.
The patch correctly fixes issue reported in 07ef6c1f04f1 (0.7.3).