[njs] Fixed Number.prototype.toString(radix).
details: https://hg.nginx.org/njs/rev/5b1bf60c8ede branches: changeset: 1272:5b1bf60c8ede user: Dmitry Volyntsev date: Tue Dec 03 14:59:26 2019 +0300 description: Fixed Number.prototype.toString(radix). Fixed buffer-overflow in Number.prototype.toString(radix) when fraction == delta == 0. The last comparison might by true for very small numbers (denormals) around zero when fast-math mode is enabled. The issue was introduced in 5f0812d53158. diffstat: auto/clang | 13 src/njs_clang.h | 18 + src/njs_number.c |4 +- src/njs_shell.c | 16 + src/test/njs_unit_test.c | 150 +++--- 5 files changed, 175 insertions(+), 26 deletions(-) diffs (326 lines): diff -r 01c7375c9b5c -r 5b1bf60c8ede auto/clang --- a/auto/clangFri Nov 29 12:53:33 2019 +0300 +++ b/auto/clangTue Dec 03 14:59:26 2019 +0300 @@ -177,3 +177,16 @@ njs_feature_test="#include return 0; }" . auto/feature + + +njs_feature="_mm_setcsr()" +njs_feature_name=NJS_HAVE_DENORMALS_CONTROL +njs_feature_run=no +njs_feature_incs= +njs_feature_libs= +njs_feature_test="#include + int main(void) { + _mm_setcsr(_mm_getcsr()); + return 0; + }" +. auto/feature diff -r 01c7375c9b5c -r 5b1bf60c8ede src/njs_clang.h --- a/src/njs_clang.h Fri Nov 29 12:53:33 2019 +0300 +++ b/src/njs_clang.h Tue Dec 03 14:59:26 2019 +0300 @@ -165,6 +165,24 @@ njs_leading_zeros64(uint64_t x) #endif +#if (NJS_HAVE_DENORMALS_CONTROL) +#include + +/* + * 0x8000 Flush to zero + * 0x0040 Denormals are zeros + */ + +#define NJS_MM_DENORMALS_MASK 0x8040 + +#define njs_mm_denormals(on) \ +_mm_setcsr((_mm_getcsr() & ~NJS_MM_DENORMALS_MASK) | (!(on) ? 0x8040: 0x0)) +#else + +#define njs_mm_denormals(on) +#endif + + #ifndef NJS_MAX_ALIGNMENT #if (NJS_SOLARIS) diff -r 01c7375c9b5c -r 5b1bf60c8ede src/njs_number.c --- a/src/njs_number.c Fri Nov 29 12:53:33 2019 +0300 +++ b/src/njs_number.c Tue Dec 03 14:59:26 2019 +0300 @@ -565,7 +565,7 @@ njs_number_prototype_to_string(njs_vm_t number = njs_number(value); -if (radix != 10 && !isnan(number) && !isinf(number)) { +if (radix != 10 && !isnan(number) && !isinf(number) && number != 0) { return njs_number_to_string_radix(vm, >retval, number, radix); } } @@ -838,7 +838,7 @@ njs_number_to_string_radix(njs_vm_t *vm, delta = 0.5 * (njs_number_next_double(n) - n); delta = njs_max(njs_number_next_double(0.0), delta); -if (fraction >= delta) { +if (fraction >= delta && delta != 0) { *p++ = '.'; do { diff -r 01c7375c9b5c -r 5b1bf60c8ede src/njs_shell.c --- a/src/njs_shell.c Fri Nov 29 12:53:33 2019 +0300 +++ b/src/njs_shell.c Tue Dec 03 14:59:26 2019 +0300 @@ -26,6 +26,7 @@ typedef struct { uint8_t disassemble; +uint8_t denormals; uint8_t interactive; uint8_t module; uint8_t quiet; @@ -232,6 +233,8 @@ main(int argc, char **argv) goto done; } +njs_mm_denormals(opts.denormals); + njs_memzero(_options, sizeof(njs_vm_opt_t)); if (opts.file == NULL) { @@ -306,6 +309,7 @@ njs_get_options(njs_opts_t *opts, int ar "Options:\n" " -cspecify the command to execute.\n" " -dprint disassembled code.\n" +" -fdisabled denormals mode.\n" " -pset path prefix for modules.\n" " -qdisable interactive introduction prompt.\n" " -ssandbox mode.\n" @@ -316,6 +320,8 @@ njs_get_options(njs_opts_t *opts, int ar ret = NJS_DONE; +opts->denormals = 1; + for (i = 1; i < argc; i++) { p = argv[i]; @@ -349,6 +355,16 @@ njs_get_options(njs_opts_t *opts, int ar opts->disassemble = 1; break; +case 'f': + +#if !(NJS_HAVE_DENORMALS_CONTROL) +njs_stderror("option \"-f\" is not supported\n"); +return NJS_ERROR; +#endif + +opts->denormals = 0; +break; + case 'p': if (++i < argc) { opts->n_paths++; diff -r 01c7375c9b5c -r 5b1bf60c8ede src/test/njs_unit_test.c --- a/src/test/njs_unit_test.c Fri Nov 29 12:53:33 2019 +0300 +++ b/src/test/njs_unit_test.c Tue Dec 03 14:59:26 2019 +0300 @@ -361,13 +361,23 @@ static njs_unit_test_t njs_test[] = /* Number.toString(radix) method. */ -#ifndef NJS_SUNC { njs_str("0..toString(2)"), njs_str("0") }, -#endif - -{ njs_str("240..toString(2)"), - njs_str("") }, + +{ njs_str("(1234.567).toString(3)"), + njs_str("1200201.120022100021001021021002202") }, + +{
[njs] Style.
details: https://hg.nginx.org/njs/rev/da7cff928b80 branches: changeset: 1274:da7cff928b80 user: Alexander Borisov date: Tue Dec 03 16:44:03 2019 +0300 description: Style. diffstat: src/njs_diyfp.h | 4 ++-- src/njs_value.c | 1 + src/njs_value.h | 6 ++ 3 files changed, 5 insertions(+), 6 deletions(-) diffs (45 lines): diff -r afe38b7fabe4 -r da7cff928b80 src/njs_diyfp.h --- a/src/njs_diyfp.h Tue Dec 03 16:43:04 2019 +0300 +++ b/src/njs_diyfp.h Tue Dec 03 16:44:03 2019 +0300 @@ -19,8 +19,8 @@ typedef struct { typedef union { - double d; - uint64_tu64; +double d; +uint64_tu64; } njs_diyfp_conv_t; diff -r afe38b7fabe4 -r da7cff928b80 src/njs_value.c --- a/src/njs_value.c Tue Dec 03 16:43:04 2019 +0300 +++ b/src/njs_value.c Tue Dec 03 16:44:03 2019 +0300 @@ -1251,6 +1251,7 @@ njs_value_to_object(njs_vm_t *vm, njs_va return NJS_ERROR; } + void njs_symbol_conversion_failed(njs_vm_t *vm, njs_bool_t to_string) { diff -r afe38b7fabe4 -r da7cff928b80 src/njs_value.h --- a/src/njs_value.h Tue Dec 03 16:43:04 2019 +0300 +++ b/src/njs_value.h Tue Dec 03 16:44:03 2019 +0300 @@ -907,14 +907,12 @@ njs_int_t njs_value_property_delete(njs_ njs_value_t *key, njs_value_t *removed); njs_int_t njs_value_to_object(njs_vm_t *vm, njs_value_t *value); +void njs_symbol_conversion_failed(njs_vm_t *vm, njs_bool_t to_string); + #include "njs_number.h" -void -njs_symbol_conversion_failed(njs_vm_t *vm, njs_bool_t to_string); - - njs_inline njs_int_t njs_value_to_number(njs_vm_t *vm, njs_value_t *value, double *dst) { ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Shell: fixed memory leak when empty line is entered.
details: https://hg.nginx.org/njs/rev/afe38b7fabe4 branches: changeset: 1273:afe38b7fabe4 user: Alexander Borisov date: Tue Dec 03 16:43:04 2019 +0300 description: Shell: fixed memory leak when empty line is entered. diffstat: src/njs_shell.c | 9 - 1 files changed, 4 insertions(+), 5 deletions(-) diffs (21 lines): diff -r 5b1bf60c8ede -r afe38b7fabe4 src/njs_shell.c --- a/src/njs_shell.c Tue Dec 03 14:59:26 2019 +0300 +++ b/src/njs_shell.c Tue Dec 03 16:43:04 2019 +0300 @@ -869,13 +869,12 @@ njs_interactive_shell(njs_opts_t *opts, } line.length = njs_strlen(line.start); -if (line.length == 0) { -continue; -} -add_history((char *) line.start); +if (line.length != 0) { +add_history((char *) line.start); -njs_process_script(opts, vm_options->external, ); +njs_process_script(opts, vm_options->external, ); +} /* editline allocs a new buffer every time. */ free(line.start); ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
Re: [PATCH] Mime type for Web Assembly
Hello! On Fri, Nov 29, 2019 at 09:27:46PM +, Chris Couzens wrote: > # HG changeset patch > # User Chris Couzens > # Date 1575032353 0 > # Fri Nov 29 12:59:13 2019 + > # Node ID d826b28f25157901dff4a010cca180a0d13e7c35 > # Parent d13eddd9e2529b4bc30dc00aad959bd10ced4c33 > Mime.types: Add Web Assembly > > Web assembly is a web standard and so nginx should support hosting > it by default. > > Not serving the correct mime type causes standard compliant browsers > to reject it. > > https://www.w3.org/TR/wasm-web-api-1/#streaming-modules > > > If the Response is not CORS-same-origin, does not represent an ok > > status, or does not match the `application/wasm` MIME type, the > > returned promise will be rejected with a TypeError; > > diff -r d13eddd9e252 -r d826b28f2515 conf/mime.types > --- a/conf/mime.types Tue Nov 19 17:18:58 2019 +0300 > +++ b/conf/mime.types Fri Nov 29 12:59:13 2019 + > @@ -8,6 +8,7 @@ > application/javascript js; > application/atom+xml atom; > application/rss+xml rss; > +application/wasm wasm; > > text/mathml mml; > text/plain txt; Please see https://trac.nginx.org/nginx/ticket/1606 for detailed comments about adding application/wasm MIME type. -- Maxim Dounin http://mdounin.ru/ ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Introduced SpeciesConstructor() from the specification.
details: https://hg.nginx.org/njs/rev/904333a40816 branches: changeset: 1275:904333a40816 user: Alexander Borisov date: Tue Dec 03 17:13:34 2019 +0300 description: Introduced SpeciesConstructor() from the specification. diffstat: src/njs_value.c | 53 + src/njs_value.h | 3 +++ 2 files changed, 56 insertions(+), 0 deletions(-) diffs (73 lines): diff -r da7cff928b80 -r 904333a40816 src/njs_value.c --- a/src/njs_value.c Tue Dec 03 16:44:03 2019 +0300 +++ b/src/njs_value.c Tue Dec 03 17:13:34 2019 +0300 @@ -1259,3 +1259,56 @@ njs_symbol_conversion_failed(njs_vm_t *v ? "Cannot convert a Symbol value to a string" : "Cannot convert a Symbol value to a number"); } + + +njs_int_t +njs_value_species_constructor(njs_vm_t *vm, njs_value_t *object, +njs_value_t *default_constructor, njs_value_t *dst) +{ +njs_int_tret; +njs_value_t constructor, retval; + +static const njs_value_t string_constructor = njs_string("constructor"); +static const njs_value_t string_species = +njs_wellknown_symbol(NJS_SYMBOL_SPECIES); + +ret = njs_value_property(vm, object, njs_value_arg(_constructor), + ); +if (njs_slow_path(ret == NJS_ERROR)) { +return NJS_ERROR; +} + +if (njs_is_undefined()) { +goto default_сonstructor; +} + +if (njs_slow_path(!njs_is_object())) { +njs_type_error(vm, "constructor is not object"); +return NJS_ERROR; +} + +ret = njs_value_property(vm, , njs_value_arg(_species), + ); +if (njs_slow_path(ret == NJS_ERROR)) { +return NJS_ERROR; +} + +if (njs_value_is_null_or_undefined()) { +goto default_сonstructor; +} + +if (!njs_is_function()) { +njs_type_error(vm, "object does not contain a constructor"); +return NJS_ERROR; +} + +*dst = retval; + +return NJS_OK; + +default_сonstructor: + +*dst = *default_constructor; + +return NJS_OK; +} diff -r da7cff928b80 -r 904333a40816 src/njs_value.h --- a/src/njs_value.h Tue Dec 03 16:44:03 2019 +0300 +++ b/src/njs_value.h Tue Dec 03 17:13:34 2019 +0300 @@ -909,6 +909,9 @@ njs_int_t njs_value_to_object(njs_vm_t * void njs_symbol_conversion_failed(njs_vm_t *vm, njs_bool_t to_string); +njs_int_t njs_value_species_constructor(njs_vm_t *vm, njs_value_t *object, +njs_value_t *default_constructor, njs_value_t *dst); + #include "njs_number.h" ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Fixed typo introduced in 904333a40816.
details: https://hg.nginx.org/njs/rev/6e84ff419b88 branches: changeset: 1276:6e84ff419b88 user: Alexander Borisov date: Tue Dec 03 17:58:30 2019 +0300 description: Fixed typo introduced in 904333a40816. diffstat: src/njs_value.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diffs (30 lines): diff -r 904333a40816 -r 6e84ff419b88 src/njs_value.c --- a/src/njs_value.c Tue Dec 03 17:13:34 2019 +0300 +++ b/src/njs_value.c Tue Dec 03 17:58:30 2019 +0300 @@ -1279,7 +1279,7 @@ njs_value_species_constructor(njs_vm_t * } if (njs_is_undefined()) { -goto default_сonstructor; +goto default_constructor; } if (njs_slow_path(!njs_is_object())) { @@ -1294,7 +1294,7 @@ njs_value_species_constructor(njs_vm_t * } if (njs_value_is_null_or_undefined()) { -goto default_сonstructor; +goto default_constructor; } if (!njs_is_function()) { @@ -1306,7 +1306,7 @@ njs_value_species_constructor(njs_vm_t * return NJS_OK; -default_сonstructor: +default_constructor: *dst = *default_constructor; ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Added njs_is_memory_error() function.
details: https://hg.nginx.org/njs/rev/ef64784b77f6 branches: changeset: 1277:ef64784b77f6 user: Alexander Borisov date: Tue Dec 03 18:02:40 2019 +0300 description: Added njs_is_memory_error() function. diffstat: src/njs_error.h | 14 ++ src/njs_vm.c| 7 +-- 2 files changed, 15 insertions(+), 6 deletions(-) diffs (39 lines): diff -r 6e84ff419b88 -r ef64784b77f6 src/njs_error.h --- a/src/njs_error.h Tue Dec 03 17:58:30 2019 +0300 +++ b/src/njs_error.h Tue Dec 03 18:02:40 2019 +0300 @@ -59,4 +59,18 @@ extern const njs_object_type_init_t njs extern const njs_object_type_init_t njs_memory_error_type_init; +njs_inline njs_int_t +njs_is_memory_error(njs_vm_t *vm, njs_value_t *value) +{ +if (njs_is_error(value) +&& njs_has_prototype(vm, value, NJS_OBJ_TYPE_INTERNAL_ERROR) +&& !njs_object(value)->extensible) +{ +return 1; +} + +return 0; +} + + #endif /* _NJS_BOOLEAN_H_INCLUDED_ */ diff -r 6e84ff419b88 -r ef64784b77f6 src/njs_vm.c --- a/src/njs_vm.c Tue Dec 03 17:58:30 2019 +0300 +++ b/src/njs_vm.c Tue Dec 03 18:02:40 2019 +0300 @@ -852,12 +852,7 @@ njs_vm_value_to_string(njs_vm_t *vm, njs } if (njs_is_error(src)) { - -/* MemoryError is a nonextensible internal error. */ - -if (njs_has_prototype(vm, src, NJS_OBJ_TYPE_INTERNAL_ERROR) -&& !njs_object(src)->extensible) -{ +if (njs_is_memory_error(vm, src)) { njs_string_get(_string_memory_error, dst); return NJS_OK; } ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel