[njs] String.prototype.indexOf() method fixes.
details: http://hg.nginx.org/njs/rev/74785cebd8df branches: changeset: 222:74785cebd8df user: Igor Sysoev <i...@sysoev.ru> date: Thu Oct 27 10:47:48 2016 +0300 description: String.prototype.indexOf() method fixes. diffstat: njs/njs_string.c | 66 +-- njs/test/njs_unit_test.c | 6 2 files changed, 63 insertions(+), 9 deletions(-) diffs (104 lines): diff -r f21747d5ac83 -r 74785cebd8df njs/njs_string.c --- a/njs/njs_string.c Tue Oct 25 17:52:18 2016 +0300 +++ b/njs/njs_string.c Thu Oct 27 10:47:48 2016 +0300 @@ -1212,24 +1212,72 @@ static njs_ret_t njs_string_prototype_index_of(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { -ssize_t start, index; - -index = -1; +ssize_tindex, length, search_length; +const u_char *p, *end; +njs_string_prop_t string, search; if (nargs > 1) { -start = 0; +length = njs_string_prop(, [0]); +search_length = njs_string_prop(, [1]); + +if (length < search_length) { +goto small; +} + +index = 0; if (nargs > 2) { -start = args[2].data.u.number; - -if (start < 0) { -start = 0; +index = args[2].data.u.number; + +if (index < 0) { +index = 0; } } -index = njs_string_index_of(vm, [0], [1], start); +if (index < length) { +end = string.start + string.size; + +if (string.size == (size_t) length) { +/* Byte or ASCII string. */ + +end -= (search.size - 1); + +for (p = string.start + index; p < end; p++) { +if (memcmp(p, search.start, search.size) == 0) { +goto done; +} + +index++; +} + +} else { +/* UTF-8 string. */ + +p = njs_string_offset(string.start, end, index); +end -= search.size - 1; + +while (p < end) { +if (memcmp(p, search.start, search.size) == 0) { +goto done; +} + +index++; +p = nxt_utf8_next(p, end); +} +} + +} else if (search.size == 0) { +index = length; +goto done; +} } +small: + +index = -1; + +done: + njs_number_set(>retval, index); return NXT_OK; diff -r f21747d5ac83 -r 74785cebd8df njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Tue Oct 25 17:52:18 2016 +0300 +++ b/njs/test/njs_unit_test.c Thu Oct 27 10:47:48 2016 +0300 @@ -3212,9 +3212,15 @@ static njs_unit_test_t njs_test[] = { nxt_string("'12345'.indexOf()"), nxt_string("-1") }, +{ nxt_string("''.indexOf('')"), + nxt_string("0") }, + { nxt_string("'12345'.indexOf(45, '0')"), nxt_string("3") }, +{ nxt_string("'12'.indexOf('12345')"), + nxt_string("-1") }, + { nxt_string("''.indexOf.call(12345, 45, '0')"), nxt_string("3") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Incomplete non-recursive parser has been removed.
details: http://hg.nginx.org/njs/rev/12a38e4e030b branches: changeset: 219:12a38e4e030b user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 24 18:27:31 2016 +0300 description: Incomplete non-recursive parser has been removed. diffstat: Makefile |16 - njs/njs_nonrecursive_parser.c | 1553 - 2 files changed, 0 insertions(+), 1569 deletions(-) diffs (truncated from 1597 to 1000 lines): diff -r 0fe25989e0a6 -r 12a38e4e030b Makefile --- a/Makefile Mon Oct 24 17:29:27 2016 +0300 +++ b/Makefile Mon Oct 24 18:27:31 2016 +0300 @@ -31,7 +31,6 @@ main: $(NXT_BUILDDIR)/libnjs.a $(NXT_BUILDDIR)/njs_builtin.o \ $(NXT_BUILDDIR)/njs_lexer.o \ $(NXT_BUILDDIR)/njs_lexer_keyword.o \ - $(NXT_BUILDDIR)/njs_nonrecursive_parser.o \ $(NXT_BUILDDIR)/njs_parser.o \ $(NXT_BUILDDIR)/njs_parser_expression.o \ $(NXT_BUILDDIR)/njs_generator.o \ @@ -64,7 +63,6 @@ main: $(NXT_BUILDDIR)/libnjs.a $(NXT_BUILDDIR)/njs_builtin.o \ $(NXT_BUILDDIR)/njs_lexer.o \ $(NXT_BUILDDIR)/njs_lexer_keyword.o \ - $(NXT_BUILDDIR)/njs_nonrecursive_parser.o \ $(NXT_BUILDDIR)/njs_parser.o \ $(NXT_BUILDDIR)/njs_parser_expression.o \ $(NXT_BUILDDIR)/njs_generator.o \ @@ -329,20 +327,6 @@ dist: -I$(NXT_LIB) -Injs \ njs/njs_lexer_keyword.c -$(NXT_BUILDDIR)/njs_nonrecursive_parser.o: \ - $(NXT_BUILDDIR)/libnxt.a \ - njs/njscript.h \ - njs/njs_vm.h \ - njs/njs_number.h \ - njs/njs_object.h \ - njs/njs_parser.h \ - njs/njs_nonrecursive_parser.c \ - - $(NXT_CC) -c -o $(NXT_BUILDDIR)/njs_nonrecursive_parser.o \ - $(NXT_CFLAGS) \ - -I$(NXT_LIB) -Injs \ - njs/njs_nonrecursive_parser.c - $(NXT_BUILDDIR)/njs_parser.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ diff -r 0fe25989e0a6 -r 12a38e4e030b njs/njs_nonrecursive_parser.c --- a/njs/njs_nonrecursive_parser.c Mon Oct 24 17:29:27 2016 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 + @@ -1,1553 +0,0 @@ - -/* - * Copyright (C) Igor Sysoev - * Copyright (C) NGINX, Inc. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -typedef nxt_int_t (*njs_parser_operation_t)(njs_vm_t *vm, -njs_parser_t *parser, njs_token_t token, const void *data); - -typedef nxt_int_t (*njs_parser_stack_operation_t)(njs_vm_t *vm, -njs_parser_t *parser, const void *data); - - -#define NJS_TOKEN_ANYNJS_TOKEN_ILLEGAL -#define NJS_PARSER_NODE ((void *) -1) -#define NJS_PARSER_VOID ((void *) -2) - - -typedef struct { -njs_token_t token; -njs_parser_operation_t operation; -const void *data; -const void *primed; -} njs_parser_terminal_t; - - -#define NJS_PARSER_IGNORE_LINE_END 0 -#define NJS_PARSER_TEST_LINE_END1 - - -typedef struct { -uint8_t take_line_end; /* 1 bit */ -uint8_t count; -#if (NXT_SUNC) -/* - * SunC supports C99 flexible array members but does not allow - * static struct's initialization with arbitrary number of members. - */ -const njs_parser_terminal_t terminal[9]; -#else -const njs_parser_terminal_t terminal[]; -#endif -} njs_parser_switch_t; - - -njs_token_t njs_parser_token(njs_parser_t *parser); -static void *njs_parser_stack_pop(njs_parser_t *parser); -static nxt_int_t njs_parser_stack_push(njs_vm_t *vm, njs_parser_t *parser, -const void *data); - -static const void *const njs_parser_statement[]; -static const void *const njs_parser_expression0[]; - - -/* STUB */ -static nxt_int_ttop = -1; -static void *stack[1024]; -/**/ - - -njs_parser_node_t * -njs_nonrecursive_parser(njs_vm_t *vm, njs_parser_t *parser) -{ -nxt_int_t ret; -njs_token_t token; -njs_parser_stack_operation_t operation; - -if (top < 0) { -njs_parser_stack_push(vm, parser, njs_parser_statement); -} - -token = njs_parser_token(parser); -if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) { -/* TODO: NJS_TOKEN_AGAIN */ -return NULL; -} - -do { -operation = (njs_parser_stack_operation_t) njs_parser_stack_pop(parser); - -if (operation == NULL) { - -if (parser->lexer->token == NJS_TOKEN_END) { -return parser->node; -} - -break; -} - -ret = operation(vm, parser, njs_parser_stack_pop(parser)); - -} while (ret == NXT_OK); - -nxt_thread_log_error(NXT_LOG_ERR, "unexpected token"); - -return NULL; -} - - -njs_token_t
[njs] A build with -Werror=return-type has been fixed.
details: http://hg.nginx.org/njs/rev/eef409d1d4be branches: changeset: 217:eef409d1d4be user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 24 17:23:00 2016 +0300 description: A build with -Werror=return-type has been fixed. Patch by Piotr Sikora. diffstat: nxt/auto/clang | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (11 lines): diff -r f87eefdd2c3d -r eef409d1d4be nxt/auto/clang --- a/nxt/auto/clangMon Oct 24 17:16:10 2016 +0300 +++ b/nxt/auto/clangMon Oct 24 17:23:00 2016 +0300 @@ -198,6 +198,7 @@ nxt_feature_incs= nxt_feature_libs= nxt_feature_test="int main(void) { __builtin_prefetch(0); + return 0; }" . ${NXT_AUTO}feature ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Style unification of configure feature tests.
details: http://hg.nginx.org/njs/rev/0fe25989e0a6 branches: changeset: 218:0fe25989e0a6 user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 24 17:29:27 2016 +0300 description: Style unification of configure feature tests. diffstat: nxt/auto/clang | 10 +- nxt/auto/getrandom | 2 +- nxt/auto/time | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diffs (76 lines): diff -r eef409d1d4be -r 0fe25989e0a6 nxt/auto/clang --- a/nxt/auto/clangMon Oct 24 17:23:00 2016 +0300 +++ b/nxt/auto/clangMon Oct 24 17:29:27 2016 +0300 @@ -205,20 +205,20 @@ nxt_feature_test="int main(void) { nxt_feature="GCC __attribute__ visibility" nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_VISIBILITY -nxt_feature_run= +nxt_feature_run=no nxt_feature_path= nxt_feature_libs= nxt_feature_test="int n __attribute__ ((visibility(\"default\"))); int main(void) { - return 1; + return 0; }" . ${NXT_AUTO}feature nxt_feature="GCC __attribute__ malloc" nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_MALLOC -nxt_feature_run= +nxt_feature_run=no nxt_feature_path= nxt_feature_libs= nxt_feature_test="#include @@ -251,13 +251,13 @@ else nxt_feature="GCC __attribute__ aligned" nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_ALIGNED -nxt_feature_run= +nxt_feature_run=no nxt_feature_path= nxt_feature_libs= nxt_feature_test="int n __attribute__ ((aligned(64))); int main(void) { - return 1; + return 0; }" . ${NXT_AUTO}feature diff -r eef409d1d4be -r 0fe25989e0a6 nxt/auto/getrandom --- a/nxt/auto/getrandomMon Oct 24 17:23:00 2016 +0300 +++ b/nxt/auto/getrandomMon Oct 24 17:29:27 2016 +0300 @@ -7,7 +7,7 @@ nxt_feature="getrandom()" nxt_feature_name=NXT_HAVE_GETRANDOM -nxt_feature_run= +nxt_feature_run=no nxt_feature_incs= nxt_feature_libs= nxt_feature_test="#include diff -r eef409d1d4be -r 0fe25989e0a6 nxt/auto/time --- a/nxt/auto/time Mon Oct 24 17:23:00 2016 +0300 +++ b/nxt/auto/time Mon Oct 24 17:29:27 2016 +0300 @@ -7,7 +7,7 @@ nxt_feature="struct tm.tm_gmtoff" nxt_feature_name=NXT_HAVE_TM_GMTOFF -nxt_feature_run= +nxt_feature_run=no nxt_feature_incs= nxt_feature_libs= nxt_feature_test="#include @@ -27,7 +27,7 @@ nxt_feature_test="#include nxt_feature="altzone" nxt_feature_name=NXT_HAVE_ALTZONE -nxt_feature_run= +nxt_feature_run=no nxt_feature_incs= nxt_feature_libs= nxt_feature_test="#include ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] A build with -Werror=old-style-definition has been fixed.
details: http://hg.nginx.org/njs/rev/f87eefdd2c3d branches: changeset: 216:f87eefdd2c3d user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 24 17:16:10 2016 +0300 description: A build with -Werror=old-style-definition has been fixed. Patch by Piotr Sikora. diffstat: nxt/auto/clang | 10 +- nxt/auto/getrandom | 2 +- nxt/auto/memalign | 4 ++-- nxt/auto/pcre | 2 +- nxt/auto/time | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diffs (114 lines): diff -r 4b187e72aa9d -r f87eefdd2c3d nxt/auto/clang --- a/nxt/auto/clangMon Oct 24 15:04:57 2016 +0300 +++ b/nxt/auto/clangMon Oct 24 17:16:10 2016 +0300 @@ -185,7 +185,7 @@ nxt_feature_name=NXT_HAVE_BUILTIN_UNREAC nxt_feature_run=no nxt_feature_incs= nxt_feature_libs= -nxt_feature_test="int main() { +nxt_feature_test="int main(void) { __builtin_unreachable(); }" . ${NXT_AUTO}feature @@ -196,7 +196,7 @@ nxt_feature_name=NXT_HAVE_BUILTIN_PREFET nxt_feature_run=no nxt_feature_incs= nxt_feature_libs= -nxt_feature_test="int main() { +nxt_feature_test="int main(void) { __builtin_prefetch(0); }" . ${NXT_AUTO}feature @@ -209,7 +209,7 @@ nxt_feature_path= nxt_feature_libs= nxt_feature_test="int n __attribute__ ((visibility(\"default\"))); - int main() { + int main(void) { return 1; }" . ${NXT_AUTO}feature @@ -228,7 +228,7 @@ nxt_feature_test="#include return malloc(1); } - int main() { + int main(void) { if (f() != NULL) { return 1; } @@ -255,7 +255,7 @@ else nxt_feature_libs= nxt_feature_test="int n __attribute__ ((aligned(64))); - int main() { + int main(void) { return 1; }" . ${NXT_AUTO}feature diff -r 4b187e72aa9d -r f87eefdd2c3d nxt/auto/getrandom --- a/nxt/auto/getrandomMon Oct 24 15:04:57 2016 +0300 +++ b/nxt/auto/getrandomMon Oct 24 17:16:10 2016 +0300 @@ -14,7 +14,7 @@ nxt_feature_test="#include #include #include - int main() { + int main(void) { char buf[4]; (void) syscall(SYS_getrandom, buf, 4, 0); diff -r 4b187e72aa9d -r f87eefdd2c3d nxt/auto/memalign --- a/nxt/auto/memalign Mon Oct 24 15:04:57 2016 +0300 +++ b/nxt/auto/memalign Mon Oct 24 17:16:10 2016 +0300 @@ -13,7 +13,7 @@ nxt_feature_incs= nxt_feature_libs= nxt_feature_test="#include - int main() { + int main(void) { void *p; if (posix_memalign(, 4096, 4096) != 0) @@ -34,7 +34,7 @@ if [ $nxt_found = no ]; then nxt_feature_libs= nxt_feature_test="#include - int main() { + int main(void) { if (memalign(4096, 4096) == NULL) return 1; return 0; diff -r 4b187e72aa9d -r f87eefdd2c3d nxt/auto/pcre --- a/nxt/auto/pcre Mon Oct 24 15:04:57 2016 +0300 +++ b/nxt/auto/pcre Mon Oct 24 17:16:10 2016 +0300 @@ -20,7 +20,7 @@ if /bin/sh -c "(pcre-config --version)" nxt_feature_libs=$NXT_PCRE_LIB nxt_feature_test="#include - int main() { + int main(void) { pcre *re; re = pcre_compile(NULL, 0, NULL, 0, NULL); diff -r 4b187e72aa9d -r f87eefdd2c3d nxt/auto/time --- a/nxt/auto/time Mon Oct 24 15:04:57 2016 +0300 +++ b/nxt/auto/time Mon Oct 24 17:16:10 2016 +0300 @@ -12,7 +12,7 @@ nxt_feature_incs= nxt_feature_libs= nxt_feature_test="#include - int main() { + int main(void) { time_t t; struct tm tm; @@ -32,7 +32,7 @@ nxt_feature_incs= nxt_feature_libs= nxt_feature_test="#include - int main() { + int main(void) { altzone = 0; return 0; }" ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Version 0.1.4.
details: http://hg.nginx.org/njs/rev/508689c1fb94 branches: changeset: 214:508689c1fb94 user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 24 15:04:50 2016 +0300 description: Version 0.1.4. diffstat: Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (10 lines): diff -r 50555ae1d978 -r 508689c1fb94 Makefile --- a/Makefile Mon Oct 24 14:56:28 2016 +0300 +++ b/Makefile Mon Oct 24 15:04:50 2016 +0300 @@ -1,5 +1,5 @@ -NJS_VER = 0.1.3 +NJS_VER = 0.1.4 NXT_LIB = nxt ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] A fix in decodeURI() and decodeURIComponent() functions.
details: http://hg.nginx.org/njs/rev/cec366d97854 branches: changeset: 211:cec366d97854 user: Igor Sysoev <i...@sysoev.ru> date: Sat Oct 22 20:24:32 2016 +0300 description: A fix in decodeURI() and decodeURIComponent() functions. Found with afl-fuzz. diffstat: njs/njs_string.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diffs (36 lines): diff -r 7685bf403554 -r cec366d97854 njs/njs_string.c --- a/njs/njs_string.c Fri Oct 21 23:03:02 2016 +0300 +++ b/njs/njs_string.c Sat Oct 22 20:24:32 2016 +0300 @@ -3070,7 +3070,6 @@ njs_string_decode(njs_vm_t *vm, njs_valu byte = *src++; if (byte == '%') { - size -= 2; if (size <= 0) { @@ -3117,6 +3116,8 @@ njs_string_decode(njs_vm_t *vm, njs_valu byte = *src++; if (byte == '%') { +size -= 2; + d0 = hex[*src++]; d1 = hex[*src++]; byte = (d0 << 4) + d1; @@ -3124,7 +3125,6 @@ njs_string_decode(njs_vm_t *vm, njs_valu utf8 |= (byte >= 0x80); if ((reserve[byte >> 5] & ((uint32_t) 1 << (byte & 0x1f))) != 0) { -size -= 2; *dst++ = '%'; *dst++ = src[-2]; byte = src[-1]; @@ -3132,7 +3132,6 @@ njs_string_decode(njs_vm_t *vm, njs_valu } *dst++ = byte; - size--; } while (size != 0); ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] njs_array_realloc() has been changed to njs_array_expand().
details: http://hg.nginx.org/njs/rev/50555ae1d978 branches: changeset: 213:50555ae1d978 user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 24 14:56:28 2016 +0300 description: njs_array_realloc() has been changed to njs_array_expand(). diffstat: njs/njs_array.c | 58 +++ njs/njs_array.h | 2 +- njs/njs_string.c | 8 ++ njs/njs_vm.c | 17 ++- 4 files changed, 39 insertions(+), 46 deletions(-) diffs (178 lines): diff -r bf848210269c -r 50555ae1d978 njs/njs_array.c --- a/njs/njs_array.c Mon Oct 24 14:12:12 2016 +0300 +++ b/njs/njs_array.c Mon Oct 24 14:56:28 2016 +0300 @@ -148,17 +148,14 @@ njs_array_add(njs_vm_t *vm, njs_array_t { njs_ret_t ret; -if (array->size == array->length) { -ret = njs_array_realloc(vm, array, 0, array->size + 1); -if (nxt_slow_path(ret != NXT_OK)) { -return ret; -} +ret = njs_array_expand(vm, array, 0, 1); + +if (nxt_fast_path(ret == NXT_OK)) { +/* GC: retain value. */ +array->start[array->length++] = *value; } -/* GC: retain value. */ -array->start[array->length++] = *value; - -return NXT_OK; +return ret; } @@ -168,31 +165,34 @@ njs_array_string_add(njs_vm_t *vm, njs_a { njs_ret_t ret; -if (array->size == array->length) { -ret = njs_array_realloc(vm, array, 0, array->size + 1); -if (nxt_slow_path(ret != NXT_OK)) { -return ret; -} +ret = njs_array_expand(vm, array, 0, 1); + +if (nxt_fast_path(ret == NXT_OK)) { +return njs_string_create(vm, >start[array->length++], + start, size, length); } -return njs_string_create(vm, >start[array->length++], -start, size, length); +return ret; } njs_ret_t -njs_array_realloc(njs_vm_t *vm, njs_array_t *array, uint32_t prepend, +njs_array_expand(njs_vm_t *vm, njs_array_t *array, uint32_t prepend, uint32_t size) { njs_value_t *start, *old; -if (size != array->size) { -if (size < 16) { -size *= 2; +size += array->length; -} else { -size += size / 2; -} +if (nxt_fast_path(size <= array->size && prepend == 0)) { +return NXT_OK; +} + +if (size < 16) { +size *= 2; + +} else { +size += size / 2; } start = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), @@ -438,11 +438,9 @@ njs_array_prototype_push(njs_vm_t *vm, n array = args[0].data.u.array; if (nargs != 0) { -if (nargs > array->size - array->length) { -ret = njs_array_realloc(vm, array, 0, array->size + nargs); -if (nxt_slow_path(ret != NXT_OK)) { -return ret; -} +ret = njs_array_expand(vm, array, 0, nargs); +if (nxt_slow_path(ret != NXT_OK)) { +return ret; } for (i = 1; i < nargs; i++) { @@ -500,7 +498,7 @@ njs_array_prototype_unshift(njs_vm_t *vm if (n != 0) { if ((intptr_t) n > (array->start - array->data)) { -ret = njs_array_realloc(vm, array, n, 0); +ret = njs_array_expand(vm, array, n, 0); if (nxt_slow_path(ret != NXT_OK)) { return ret; } @@ -627,7 +625,7 @@ njs_array_prototype_splice(njs_vm_t *vm, * Index of the first item is in "n". */ if (delta > 0) { -ret = njs_array_realloc(vm, array, 0, array->size + delta); +ret = njs_array_expand(vm, array, 0, delta); if (nxt_slow_path(ret != NXT_OK)) { return ret; } diff -r bf848210269c -r 50555ae1d978 njs/njs_array.h --- a/njs/njs_array.h Mon Oct 24 14:12:12 2016 +0300 +++ b/njs/njs_array.h Mon Oct 24 14:56:28 2016 +0300 @@ -14,7 +14,7 @@ njs_array_t *njs_array_alloc(njs_vm_t *vm, uint32_t length, uint32_t spare); njs_ret_t njs_array_string_add(njs_vm_t *vm, njs_array_t *array, u_char *start, size_t size, size_t length); -njs_ret_t njs_array_realloc(njs_vm_t *vm, njs_array_t *array, uint32_t prepend, +njs_ret_t njs_array_expand(njs_vm_t *vm, njs_array_t *array, uint32_t prepend, uint32_t size); njs_ret_t njs_array_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); diff -r bf848210269c -r 50555ae1d978 njs/njs_string.c --- a/njs/njs_string.c Mon Oct 24 14:12:12 2016 +0300 +++ b/njs/njs_string.c Mon Oct 24 14:56:28 2016 +0300 @@ -1659,11 +1659,9 @@ njs_string_match_multiple(njs_vm_t *vm, string.size, vm->single_match_data); if (ret >= 0) {
[njs] Array creation and reallocation optimizations.
details: http://hg.nginx.org/njs/rev/bf848210269c branches: changeset: 212:bf848210269c user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 24 14:12:12 2016 +0300 description: Array creation and reallocation optimizations. diffstat: njs/njs_array.c| 35 ++- njs/njs_disassembler.c | 5 +++-- njs/njs_generator.c| 6 +- njs/njs_parser.c | 5 +++-- njs/njs_vm.c | 41 ++--- 5 files changed, 47 insertions(+), 45 deletions(-) diffs (213 lines): diff -r cec366d97854 -r bf848210269c njs/njs_array.c --- a/njs/njs_array.c Sat Oct 22 20:24:32 2016 +0300 +++ b/njs/njs_array.c Mon Oct 24 14:12:12 2016 +0300 @@ -184,8 +184,7 @@ njs_ret_t njs_array_realloc(njs_vm_t *vm, njs_array_t *array, uint32_t prepend, uint32_t size) { -nxt_uint_t n; -njs_value_t *value, *old; +njs_value_t *start, *old; if (size != array->size) { if (size < 16) { @@ -196,35 +195,21 @@ njs_array_realloc(njs_vm_t *vm, njs_arra } } -value = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), +start = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), (prepend + size) * sizeof(njs_value_t)); -if (nxt_slow_path(value == NULL)) { +if (nxt_slow_path(start == NULL)) { return NXT_ERROR; } -old = array->data; -array->data = value; - -while (prepend != 0) { -njs_set_invalid(value); -value++; -prepend--; -} - -memcpy(value, array->start, array->size * sizeof(njs_value_t)); - -array->start = value; -n = array->size; array->size = size; -value += n; -size -= n; +old = array->data; +array->data = start; +start += prepend; -while (size != 0) { -njs_set_invalid(value); -value++; -size--; -} +memcpy(start, array->start, array->length * sizeof(njs_value_t)); + +array->start = start; nxt_mem_cache_free(vm->mem_cache_pool, old); @@ -515,7 +500,7 @@ njs_array_prototype_unshift(njs_vm_t *vm if (n != 0) { if ((intptr_t) n > (array->start - array->data)) { -ret = njs_array_realloc(vm, array, n, array->size); +ret = njs_array_realloc(vm, array, n, 0); if (nxt_slow_path(ret != NXT_OK)) { return ret; } diff -r cec366d97854 -r bf848210269c njs/njs_disassembler.c --- a/njs/njs_disassembler.cSat Oct 22 20:24:32 2016 +0300 +++ b/njs/njs_disassembler.cMon Oct 24 14:12:12 2016 +0300 @@ -197,8 +197,9 @@ njs_disassemble(u_char *start, u_char *e if (operation == njs_vmcode_array) { array = (njs_vmcode_array_t *) p; -printf("%05zd ARRAY %04zX %zd\n", - p - start, (size_t) array->retval, (size_t) array->length); +printf("%05zd ARRAY %04zX %zd%s\n", + p - start, (size_t) array->retval, (size_t) array->length, + array->code.ctor ? " INIT" : ""); p += sizeof(njs_vmcode_array_t); diff -r cec366d97854 -r bf848210269c njs/njs_generator.c --- a/njs/njs_generator.c Sat Oct 22 20:24:32 2016 +0300 +++ b/njs/njs_generator.c Mon Oct 24 14:12:12 2016 +0300 @@ -1510,15 +1510,11 @@ njs_generate_array(njs_vm_t *vm, njs_par array->code.operation = njs_vmcode_array; array->code.operands = NJS_VMCODE_1OPERAND; array->code.retval = NJS_VMCODE_RETVAL; +array->code.ctor = node->ctor; array->retval = node->index; array->length = node->u.length; -if (node->left == NULL) { -return NXT_OK; -} - /* Initialize array. */ - return njs_generator(vm, parser, node->left); } diff -r cec366d97854 -r bf848210269c njs/njs_parser.c --- a/njs/njs_parser.c Sat Oct 22 20:24:32 2016 +0300 +++ b/njs/njs_parser.c Mon Oct 24 14:12:12 2016 +0300 @@ -1885,6 +1885,7 @@ njs_parser_array(njs_vm_t *vm, njs_parse } if (token == NJS_TOKEN_COMMA) { +obj->ctor = 1; index++; continue; } @@ -1942,11 +1943,11 @@ njs_parser_array(njs_vm_t *vm, njs_parse stmt->left = left; stmt->right = assign; -parser->code_size += sizeof(njs_vmcode_2addr_t); parser->node = stmt; - left = stmt; +obj->ctor = 0; + if (token == NJS_TOKEN_CLOSE_BRACKET) { break; } diff -r cec366d97854 -r bf848210269c njs/njs_vm.c --- a/njs/njs_vm.c Sat Oct 22 20:24:32 2016 +0300 +++ b/njs/njs_vm.c Mon Oct 24 14:12:12 2016 +0300 @@ -366,7 +366,7 @@ njs_vmcode_object(njs_vm_t *vm, njs_valu njs_ret_t njs_vmcode_array(njs_vm_t *vm
[njs] A fix in Array.prototype.splice() function.
details: http://hg.nginx.org/njs/rev/7685bf403554 branches: changeset: 210:7685bf403554 user: Igor Sysoev <i...@sysoev.ru> date: Fri Oct 21 23:03:02 2016 +0300 description: A fix in Array.prototype.splice() function. Found with afl-fuzz. diffstat: njs/njs_array.c | 39 --- njs/test/njs_unit_test.c | 9 + 2 files changed, 37 insertions(+), 11 deletions(-) diffs (97 lines): diff -r b290544f11bc -r 7685bf403554 njs/njs_array.c --- a/njs/njs_array.c Thu Oct 20 17:12:42 2016 +0300 +++ b/njs/njs_array.c Fri Oct 21 23:03:02 2016 +0300 @@ -574,8 +574,8 @@ njs_array_prototype_splice(njs_vm_t *vm, njs_index_t unused) { njs_ret_tret; -nxt_int_titems, delta; -nxt_uint_t i, n, start, delete, length; +nxt_int_tn, start, length, items, delta, delete; +nxt_uint_t i; njs_array_t *array, *deleted; array = NULL; @@ -584,19 +584,33 @@ njs_array_prototype_splice(njs_vm_t *vm, if (njs_is_array([0])) { array = args[0].data.u.array; +length = array->length; if (nargs > 1) { start = args[1].data.u.number; -if (start > array->length) { -start = array->length; +if (start < 0) { +start += length; + +if (start < 0) { +start = 0; +} + +} else if (start > length) { +start = length; } +delete = length - start; + if (nargs > 2) { -delete = args[2].data.u.number; +n = args[2].data.u.number; -} else { -delete = array->length - start; +if (n < 0) { +delete = 0; + +} else if (n < delete) { +delete = n; +} } } } @@ -606,17 +620,20 @@ njs_array_prototype_splice(njs_vm_t *vm, return NXT_ERROR; } -if (array != NULL && (delete != 0 || nargs > 3)) { -length = array->length; +if (array != NULL && (delete >= 0 || nargs > 3)) { /* Move deleted items to a new array to return. */ -for (i = 0, n = start; i < delete && n < length; i++, n++) { +for (i = 0, n = start; i < (nxt_uint_t) delete; i++, n++) { /* No retention required. */ deleted->start[i] = array->start[n]; } items = nargs - 3; -items = items >= 0 ? items : 0; + +if (items < 0) { +items = 0; +} + delta = items - delete; if (delta != 0) { diff -r b290544f11bc -r 7685bf403554 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Oct 20 17:12:42 2016 +0300 +++ b/njs/test/njs_unit_test.c Fri Oct 21 23:03:02 2016 +0300 @@ -2316,6 +2316,15 @@ static njs_unit_test_t njs_test[] = { nxt_string("var a = []; a.splice()"), nxt_string("") }, +{ nxt_string("[].splice(0,5,0)"), + nxt_string("") }, + +{ nxt_string("[1,2,3,4,5].splice(-2,3,0)"), + nxt_string("4,5") }, + +{ nxt_string("[].__proto__.splice(0,1,0)"), + nxt_string("") }, + { nxt_string("var a = [];" "a.splice(9,0,1,2).join(':') + '|' + a"), nxt_string("|1,2") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Array.indexOf() and Array.lastIndexOf() have been fixed.
details: http://hg.nginx.org/njs/rev/fa9ced8246e5 branches: changeset: 208:fa9ced8246e5 user: Igor Sysoev <i...@sysoev.ru> date: Tue Oct 18 17:44:01 2016 +0300 description: Array.indexOf() and Array.lastIndexOf() have been fixed. diffstat: njs/njs_array.c | 2 +- njs/test/njs_unit_test.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletions(-) diffs (25 lines): diff -r 59b3b4a0b535 -r fa9ced8246e5 njs/njs_array.c --- a/njs/njs_array.c Tue Oct 18 15:48:22 2016 +0300 +++ b/njs/njs_array.c Tue Oct 18 17:44:01 2016 +0300 @@ -996,7 +996,7 @@ njs_array_index_of(njs_vm_t *vm, njs_val index = -1; -if (nargs > 1) { +if (nargs > 1 && njs_is_array([0])) { i = 0; array = args[0].data.u.array; length = array->length; diff -r 59b3b4a0b535 -r fa9ced8246e5 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Tue Oct 18 15:48:22 2016 +0300 +++ b/njs/test/njs_unit_test.c Tue Oct 18 17:44:01 2016 +0300 @@ -2359,6 +2359,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("var a = [1,2,3,4,3,4]; a.indexOf(3, -10)"), nxt_string("2") }, +{ nxt_string("[].indexOf.bind(0)(0, 0)"), + nxt_string("-1") }, + { nxt_string("var a = [1,2,3,4]; a.lastIndexOf()"), nxt_string("-1") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Fixes in generating "continue" and "break" statements.
details: http://hg.nginx.org/njs/rev/462f7d2113f9 branches: changeset: 205:462f7d2113f9 user: Igor Sysoev <i...@sysoev.ru> date: Tue Oct 18 15:48:13 2016 +0300 description: Fixes in generating "continue" and "break" statements. diffstat: njs/njs_generator.c | 8 njs/test/njs_unit_test.c | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diffs (38 lines): diff -r d055824ff0f7 -r 462f7d2113f9 njs/njs_generator.c --- a/njs/njs_generator.c Mon Oct 17 23:29:15 2016 +0300 +++ b/njs/njs_generator.c Tue Oct 18 15:48:13 2016 +0300 @@ -1089,8 +1089,8 @@ found: patch = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_parser_patch_t)); if (nxt_fast_path(patch != NULL)) { -patch->next = parser->block->continuation; -parser->block->continuation = patch; +patch->next = block->continuation; +block->continuation = patch; njs_generate_code(parser, njs_vmcode_jump_t, jump); jump->code.operation = njs_vmcode_jump; @@ -1133,8 +1133,8 @@ found: patch = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_parser_patch_t)); if (nxt_fast_path(patch != NULL)) { -patch->next = parser->block->exit; -parser->block->exit = patch; +patch->next = block->exit; +block->exit = patch; njs_generate_code(parser, njs_vmcode_jump_t, jump); jump->code.operation = njs_vmcode_jump; diff -r d055824ff0f7 -r 462f7d2113f9 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Mon Oct 17 23:29:15 2016 +0300 +++ b/njs/test/njs_unit_test.c Tue Oct 18 15:48:13 2016 +0300 @@ -1657,6 +1657,9 @@ static njs_unit_test_t njs_test[] = "for (i in a) { if (a[i] > 4) continue; s += a[i] } s"), nxt_string("10") }, +{ nxt_string("var a; for (a = 1; a; a--) switch (a) { case 0: continue }"), + nxt_string("undefined") }, + /* break. */ { nxt_string("break"), ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] A fix of function name usage.
details: http://hg.nginx.org/njs/rev/b2a23cf748f8 branches: changeset: 206:b2a23cf748f8 user: Igor Sysoev <i...@sysoev.ru> date: Tue Oct 18 15:48:19 2016 +0300 description: A fix of function name usage. diffstat: njs/njs_generator.c | 9 ++--- njs/njs_parser.c| 1 + njs/njs_variable.h | 3 ++- 3 files changed, 5 insertions(+), 8 deletions(-) diffs (52 lines): diff -r 462f7d2113f9 -r b2a23cf748f8 njs/njs_generator.c --- a/njs/njs_generator.c Tue Oct 18 15:48:13 2016 +0300 +++ b/njs/njs_generator.c Tue Oct 18 15:48:19 2016 +0300 @@ -333,14 +333,9 @@ njs_generator(njs_vm_t *vm, njs_parser_t static nxt_int_t njs_generate_name(njs_vm_t *vm, njs_parser_t *parser, njs_parser_node_t *node) { -njs_index_t index; -njs_value_t *value; njs_vmcode_object_copy_t *copy; -index = node->u.variable->index; -value = njs_variable_value(parser, index); - -if (value->type == NJS_FUNCTION) { +if (node->u.variable->function) { node->index = njs_generator_dest_index(vm, parser, node); if (nxt_slow_path(node->index == NJS_INDEX_ERROR)) { @@ -352,7 +347,7 @@ njs_generate_name(njs_vm_t *vm, njs_pars copy->code.operands = NJS_VMCODE_2OPERANDS; copy->code.retval = NJS_VMCODE_RETVAL; copy->retval = node->index; -copy->object = index; +copy->object = node->u.variable->index; return NXT_OK; } diff -r 462f7d2113f9 -r b2a23cf748f8 njs/njs_parser.c --- a/njs/njs_parser.c Tue Oct 18 15:48:13 2016 +0300 +++ b/njs/njs_parser.c Tue Oct 18 15:48:19 2016 +0300 @@ -315,6 +315,7 @@ njs_parser_function_declaration(njs_vm_t } var->state = NJS_VARIABLE_DECLARED; +var->function = 1; node->index = var->index; token = njs_parser_token(parser); diff -r 462f7d2113f9 -r b2a23cf748f8 njs/njs_variable.h --- a/njs/njs_variable.hTue Oct 18 15:48:13 2016 +0300 +++ b/njs/njs_variable.hTue Oct 18 15:48:19 2016 +0300 @@ -20,7 +20,8 @@ typedef enum { typedef struct { u_char*name_start; uint16_t name_len; -njs_variable_state_t state:8; /* 3 bits */ +njs_variable_state_t state:8; /* 3 bits */ +uint8_t function; /* 1 bit */ njs_index_t index; } njs_variable_t; ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Style fixes.
details: http://hg.nginx.org/njs/rev/6fc0e6b7f797 branches: changeset: 203:6fc0e6b7f797 user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 17 17:03:22 2016 +0300 description: Style fixes. diffstat: njs/njs_array.c | 2 ++ njs/njs_string.c | 38 +++--- 2 files changed, 21 insertions(+), 19 deletions(-) diffs (80 lines): diff -r 938d49b0f420 -r 6fc0e6b7f797 njs/njs_array.c --- a/njs/njs_array.c Mon Oct 17 16:42:31 2016 +0300 +++ b/njs/njs_array.c Mon Oct 17 17:03:22 2016 +0300 @@ -759,6 +759,7 @@ njs_array_prototype_join(njs_vm_t *vm, n for (i = 0; i < array->length; i++) { value = >start[i]; + if (!njs_is_string(value) && njs_is_valid(value) && !njs_is_null_or_void(value)) @@ -783,6 +784,7 @@ njs_array_prototype_join(njs_vm_t *vm, n for (i = 0; i < array->length; i++) { value = >start[i]; + if (!njs_is_string(value) && njs_is_valid(value) && !njs_is_null_or_void(value)) diff -r 938d49b0f420 -r 6fc0e6b7f797 njs/njs_string.c --- a/njs/njs_string.c Mon Oct 17 16:42:31 2016 +0300 +++ b/njs/njs_string.c Mon Oct 17 17:03:22 2016 +0300 @@ -1018,7 +1018,7 @@ static nxt_noinline void njs_string_slice_args(njs_slice_prop_t *slice, njs_value_t *args, nxt_uint_t nargs) { -ssize_tstart, end, length; +ssize_t start, end, length; length = slice->string_length; start = 0; @@ -1079,30 +1079,30 @@ njs_string_slice(njs_vm_t *vm, njs_value start = string->start; if (string->size == slice->string_length) { - /* Byte or ASCII string. */ - start += slice->start; - size = slice->length; +/* Byte or ASCII string. */ +start += slice->start; +size = slice->length; } else { - /* UTF-8 string. */ +/* UTF-8 string. */ end = start + string->size; - start = njs_string_offset(start, end, slice->start); - - /* Evaluate size of the slice in bytes and ajdust length. */ - p = start; - n = length; - - do { - p = nxt_utf8_next(p, end); - n--; - } while (n != 0 && p < end); - - size = p - start; - length -= n; +start = njs_string_offset(start, end, slice->start); + +/* Evaluate size of the slice in bytes and ajdust length. */ +p = start; +n = length; + +do { +p = nxt_utf8_next(p, end); +n--; +} while (n != 0 && p < end); + +size = p - start; +length -= n; } if (nxt_fast_path(size != 0)) { - return njs_string_new(vm, >retval, start, size, length); +return njs_string_new(vm, >retval, start, size, length); } vm->retval = njs_string_empty; ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Fixes in various String methods which return part of string.
details: http://hg.nginx.org/njs/rev/938d49b0f420 branches: changeset: 202:938d49b0f420 user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 17 16:42:31 2016 +0300 description: Fixes in various String methods which return part of string. diffstat: njs/njs_array.c |3 + njs/njs_string.c | 164 ++ njs/njs_vm.c | 16 ++-- njs/test/njs_unit_test.c | 15 4 files changed, 118 insertions(+), 80 deletions(-) diffs (296 lines): diff -r c583e4985a7b -r 938d49b0f420 njs/njs_array.c --- a/njs/njs_array.c Fri Oct 14 18:21:37 2016 +0300 +++ b/njs/njs_array.c Mon Oct 17 16:42:31 2016 +0300 @@ -409,6 +409,9 @@ njs_array_prototype_slice(njs_vm_t *vm, start = 0; length = 0; } + +} else { +length -= start; } } } diff -r c583e4985a7b -r 938d49b0f420 njs/njs_string.c --- a/njs/njs_string.c Fri Oct 14 18:21:37 2016 +0300 +++ b/njs/njs_string.c Mon Oct 17 16:42:31 2016 +0300 @@ -886,21 +886,29 @@ njs_string_prototype_substring(njs_vm_t if (start < 0) { start = 0; + +} else if (start > length) { +start = length; } +end = length; + if (nargs > 2) { end = args[2].data.u.number; if (end < 0) { end = 0; + +} else if (end >= length) { +end = length; } - -length = end - start; - -if (length < 0) { -length = -length; -start = end; -} +} + +length = end - start; + +if (length < 0) { +length = -length; +start = end; } } @@ -920,7 +928,7 @@ static njs_ret_t njs_string_prototype_substr(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { -ssize_tstart, length; +ssize_tstart, length, n; njs_slice_prop_t slice; njs_string_prop_t string; @@ -931,17 +939,32 @@ njs_string_prototype_substr(njs_vm_t *vm if (nargs > 1) { start = args[1].data.u.number; - -if (start < 0) { - -start += length; +if (start < length) { + if (start < 0) { -start = 0; +start += length; + +if (start < 0) { +start = 0; +} } -} - -if (nargs > 2) { -length = args[2].data.u.number; + +length -= start; + +if (nargs > 2) { +n = args[2].data.u.number; + +if (n < 0) { +length = 0; + +} else if (n < length) { +length = n; +} +} + +} else { +start = 0; +length = 0; } } @@ -968,7 +991,8 @@ njs_string_prototype_char_at(njs_vm_t *v if (nargs > 1) { start = args[1].data.u.number; -if (start < 0) { +if (start < 0 || start >= (ssize_t) slice.string_length) { +start = 0; length = 0; } } @@ -1010,21 +1034,32 @@ njs_string_slice_args(njs_slice_prop_t * } } -end = length; - -if (nargs > 2) { -end = args[2].data.u.number; - -if (end < 0) { -end += length; -} -} - -length = end - start; - -if (length < 0) { +if (start >= length) { start = 0; length = 0; + +} else { +end = length; + +if (nargs > 2) { +end = args[2].data.u.number; + +if (end < 0) { +end += length; +} +} + +if (length >= end) { +length = end - start; + +if (length < 0) { +start = 0; +length = 0; +} + +} else { +length -= start; +} } } @@ -1038,51 +1073,36 @@ njs_string_slice(njs_vm_t *vm, njs_value const njs_string_prop_t *string, njs_slice_prop_t *slice) { size_tsize, n, length; -ssize_t excess; const u_char *p, *start, *end; length = slice->length; - -if (length > 0 && slice->start < slice->string_length) { - -start = string->start; +start = string->start; + +if (string->size == slice->string_length) { + /* Byte or ASCII string. */ + start += slice->start; + size = slice->length; + +} else { + /* UTF-8 string. */ end = start + string->si
[njs] A fix of var declaration.
details: http://hg.nginx.org/njs/rev/5d08fa7106b8 branches: changeset: 200:5d08fa7106b8 user: Igor Sysoev <i...@sysoev.ru> date: Fri Oct 14 18:12:36 2016 +0300 description: A fix of var declaration. diffstat: njs/njs_parser.c | 1 + njs/test/njs_unit_test.c | 6 ++ 2 files changed, 7 insertions(+), 0 deletions(-) diffs (27 lines): diff -r c68db870b8b0 -r 5d08fa7106b8 njs/njs_parser.c --- a/njs/njs_parser.c Fri Oct 14 17:21:35 2016 +0300 +++ b/njs/njs_parser.c Fri Oct 14 18:12:36 2016 +0300 @@ -641,6 +641,7 @@ njs_parser_var_statement(njs_vm_t *vm, n njs_variable_t *var; njs_parser_node_t *left, *stmt, *name, *assign; +parser->node = NULL; left = NULL; do { diff -r c68db870b8b0 -r 5d08fa7106b8 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Fri Oct 14 17:21:35 2016 +0300 +++ b/njs/test/njs_unit_test.c Fri Oct 14 18:12:36 2016 +0300 @@ -68,6 +68,12 @@ static njs_unit_test_t njs_test[] = { nxt_string("var a = 1; var b; a"), nxt_string("1") }, +{ nxt_string("a = 1;for(;a;a--)var a; a"), + nxt_string("0") }, + +{ nxt_string("if(1)if(0){0?0:0}else\nvar a\nelse\nvar b"), + nxt_string("undefined") }, + { nxt_string("function f(){} function f(){}"), nxt_string("SyntaxError: Duplicate declaration \"f\" in 1") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
Re: [PATCH] Remove duplicate implementation of njs_parser_token()
On 17 Oct 2016, at 11:25, 洪志道 <hongzhi...@gmail.com> wrote: > Hello! > > It seems the file njs/njs_nonrecursive_parser.c is unused. Yes, I’m going to remove it. -- Igor Sysoev http://nginx.com ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] A fix in Array.slice() function.
details: http://hg.nginx.org/njs/rev/8046b999aaaf branches: changeset: 198:8046b999aaaf user: Igor Sysoev <i...@sysoev.ru> date: Wed Oct 12 19:08:57 2016 +0300 description: A fix in Array.slice() function. diffstat: njs/njs_array.c | 34 +- njs/test/njs_unit_test.c | 18 ++ 2 files changed, 39 insertions(+), 13 deletions(-) diffs (74 lines): diff -r beba11b9f2a1 -r 8046b999aaaf njs/njs_array.c --- a/njs/njs_array.c Tue Oct 11 20:09:18 2016 +0300 +++ b/njs/njs_array.c Wed Oct 12 19:08:57 2016 +0300 @@ -387,21 +387,29 @@ njs_array_prototype_slice(njs_vm_t *vm, } } -end = length; - -if (nargs > 2) { -end = args[2].data.u.number; - -if (end < 0) { -end += length; -} -} - -length = end - start; - -if (length < 0) { +if (start >= length) { start = 0; length = 0; + +} else { +end = length; + +if (nargs > 2) { +end = args[2].data.u.number; + +if (end < 0) { +end += length; +} +} + +if (length >= end) { +length = end - start; + +if (length < 0) { +start = 0; +length = 0; +} +} } } } diff -r beba11b9f2a1 -r 8046b999aaaf njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Tue Oct 11 20:09:18 2016 +0300 +++ b/njs/test/njs_unit_test.c Wed Oct 12 19:08:57 2016 +0300 @@ -2260,6 +2260,24 @@ static njs_unit_test_t njs_test[] = { nxt_string("a = [1,2]; a[100] = 100; a[100] +' '+ a.length"), nxt_string("100 101") }, +{ nxt_string("Array.prototype.slice(1)"), + nxt_string("") }, + +{ nxt_string("Array.prototype.slice(1,2)"), + nxt_string("") }, + +{ nxt_string("Array.prototype.pop()"), + nxt_string("undefined") }, + +{ nxt_string("Array.prototype.shift()"), + nxt_string("undefined") }, + +{ nxt_string("[0,1,2,3,4].slice(1,4)"), + nxt_string("1,2,3") }, + +{ nxt_string("[0,1,2,3,4].slice(6,7)"), + nxt_string("") }, + { nxt_string("a = [1,2,3,4,5]; b = a.slice(3); b[0] +' '+ b[1] +' '+ b[2]"), nxt_string("4 5 undefined") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Accessing the global this object caused segfault.
details: http://hg.nginx.org/njs/rev/a3588250473b branches: changeset: 196:a3588250473b user: Igor Sysoev <i...@sysoev.ru> date: Tue Oct 11 17:44:05 2016 +0300 description: Accessing the global this object caused segfault. diffstat: njs/njs_builtin.c| 17 ++--- njs/njs_generator.c | 1 + njs/njs_parser.c | 10 -- njs/njs_parser.h | 3 ++- njs/njs_vm.h | 3 ++- njs/test/njs_unit_test.c | 3 +++ 6 files changed, 26 insertions(+), 11 deletions(-) diffs (105 lines): diff -r f8cc880d9b9b -r a3588250473b njs/njs_builtin.c --- a/njs/njs_builtin.c Tue Oct 11 17:44:01 2016 +0300 +++ b/njs/njs_builtin.c Tue Oct 11 17:44:05 2016 +0300 @@ -107,7 +107,8 @@ njs_builtin_objects_create(njs_vm_t *vm) }; static const njs_object_init_t*object_init[] = { -_math_object_init, +NULL, /* global this*/ +_math_object_init,/* Math */ }; static const njs_object_init_t*function_init[] = { @@ -164,12 +165,14 @@ njs_builtin_objects_create(njs_vm_t *vm) objects = vm->shared->objects; -for (i = NJS_OBJECT_MATH; i < NJS_OBJECT_MAX; i++) { -ret = njs_object_hash_create(vm, [i].shared_hash, - object_init[i]->properties, - object_init[i]->items); -if (nxt_slow_path(ret != NXT_OK)) { -return NXT_ERROR; +for (i = NJS_OBJECT_THIS; i < NJS_OBJECT_MAX; i++) { +if (object_init[i] != NULL) { +ret = njs_object_hash_create(vm, [i].shared_hash, + object_init[i]->properties, + object_init[i]->items); +if (nxt_slow_path(ret != NXT_OK)) { +return NXT_ERROR; +} } objects[i].shared = 1; diff -r f8cc880d9b9b -r a3588250473b njs/njs_generator.c --- a/njs/njs_generator.c Tue Oct 11 17:44:01 2016 +0300 +++ b/njs/njs_generator.c Tue Oct 11 17:44:05 2016 +0300 @@ -289,6 +289,7 @@ njs_generator(njs_vm_t *vm, njs_parser_t case NJS_TOKEN_NAME: return njs_generate_name(vm, parser, node); +case NJS_TOKEN_GLOBAL_THIS: case NJS_TOKEN_MATH: case NJS_TOKEN_EVAL: case NJS_TOKEN_TO_STRING: diff -r f8cc880d9b9b -r a3588250473b njs/njs_parser.c --- a/njs/njs_parser.c Tue Oct 11 17:44:01 2016 +0300 +++ b/njs/njs_parser.c Tue Oct 11 17:44:05 2016 +0300 @@ -1644,8 +1644,14 @@ njs_parser_terminal(njs_vm_t *vm, njs_pa case NJS_TOKEN_THIS: nxt_thread_log_debug("JS: this"); -node->index = NJS_INDEX_THIS; -break; +if (parser->scope != NJS_SCOPE_GLOBAL) { +node->index = NJS_INDEX_THIS; +break; +} + +node->token = NJS_TOKEN_GLOBAL_THIS; + +/* Fall through. */ case NJS_TOKEN_MATH: return njs_parser_builtin_object(vm, parser, node); diff -r f8cc880d9b9b -r a3588250473b njs/njs_parser.h --- a/njs/njs_parser.h Tue Oct 11 17:44:01 2016 +0300 +++ b/njs/njs_parser.h Tue Oct 11 17:44:05 2016 +0300 @@ -160,8 +160,9 @@ typedef enum { NJS_TOKEN_THIS, -#define NJS_TOKEN_FIRST_OBJECT NJS_TOKEN_MATH +#define NJS_TOKEN_FIRST_OBJECT NJS_TOKEN_GLOBAL_THIS +NJS_TOKEN_GLOBAL_THIS, NJS_TOKEN_MATH, NJS_TOKEN_OBJECT_CONSTRUCTOR, diff -r f8cc880d9b9b -r a3588250473b njs/njs_vm.h --- a/njs/njs_vm.h Tue Oct 11 17:44:01 2016 +0300 +++ b/njs/njs_vm.h Tue Oct 11 17:44:05 2016 +0300 @@ -741,7 +741,8 @@ enum njs_constructor_e { enum njs_object_e { -NJS_OBJECT_MATH = 0, +NJS_OBJECT_THIS = 0, +NJS_OBJECT_MATH, #define NJS_OBJECT_MAX (NJS_OBJECT_MATH + 1) }; diff -r f8cc880d9b9b -r a3588250473b njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Tue Oct 11 17:44:01 2016 +0300 +++ b/njs/test/njs_unit_test.c Tue Oct 11 17:44:05 2016 +0300 @@ -4237,6 +4237,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("/./ instanceof Object"), nxt_string("true") }, +{ nxt_string("this"), + nxt_string("[object Object]") }, + { nxt_string("var o = Object(); o"), nxt_string("[object Object]") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Segfaults in Date have been fixed.
details: http://hg.nginx.org/njs/rev/40a753cefac1 branches: changeset: 193:40a753cefac1 user: Igor Sysoev <i...@sysoev.ru> date: Tue Oct 11 13:01:41 2016 +0300 description: Segfaults in Date have been fixed. diffstat: njs/njs_date.c | 2 ++ njs/test/njs_unit_test.c | 6 ++ 2 files changed, 8 insertions(+), 0 deletions(-) diffs (35 lines): diff -r aa8137bb7838 -r 40a753cefac1 njs/njs_date.c --- a/njs/njs_date.cMon Oct 10 17:22:26 2016 +0300 +++ b/njs/njs_date.cTue Oct 11 13:01:41 2016 +0300 @@ -108,6 +108,7 @@ njs_date_constructor(njs_vm_t *vm, njs_v for (i = 1; i < n; i++) { if (!njs_is_numeric([i])) { +vm->frame->trap_scratch.data.u.value = [i]; return NJS_TRAP_NUMBER_ARG; } @@ -186,6 +187,7 @@ njs_date_utc(njs_vm_t *vm, njs_value_t * for (i = 1; i < n; i++) { if (!njs_is_numeric([i])) { +vm->frame->trap_scratch.data.u.value = [i]; return NJS_TRAP_NUMBER_ARG; } diff -r aa8137bb7838 -r 40a753cefac1 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Mon Oct 10 17:22:26 2016 +0300 +++ b/njs/test/njs_unit_test.c Tue Oct 11 13:01:41 2016 +0300 @@ -5030,6 +5030,12 @@ static njs_unit_test_t njs_test[] = { nxt_string("var d = new Date(); d.__proto__ === Date.prototype"), nxt_string("true") }, +{ nxt_string("new Date(eval)"), + nxt_string("Invalid Date") }, + +{ nxt_string("Date.UTC(eval)"), + nxt_string("NaN") }, + { nxt_string("Date.name"), nxt_string("Date") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Added tag 0.1.3 for changeset 360449773d51
details: http://hg.nginx.org/njs/rev/aa8137bb7838 branches: changeset: 192:aa8137bb7838 user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 10 17:22:26 2016 +0300 description: Added tag 0.1.3 for changeset 360449773d51 diffstat: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (8 lines): diff -r 360449773d51 -r aa8137bb7838 .hgtags --- a/.hgtags Mon Oct 10 17:21:53 2016 +0300 +++ b/.hgtags Mon Oct 10 17:22:26 2016 +0300 @@ -1,3 +1,4 @@ cdb8d20935ee96f1fa0c99d994d4b11cefcbc119 0.1.0 0039a747d25a3e08792c23c43b75768896724031 0.1.1 5b066b4db54c17dc0a9a72948474f36957462e87 0.1.2 +360449773d51e7f451e5396e27021badc6b86085 0.1.3 ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Version 0.1.3.
details: http://hg.nginx.org/njs/rev/360449773d51 branches: changeset: 191:360449773d51 user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 10 17:21:53 2016 +0300 description: Version 0.1.3. diffstat: Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (10 lines): diff -r 03d12ab0961e -r 360449773d51 Makefile --- a/Makefile Mon Oct 10 16:33:56 2016 +0300 +++ b/Makefile Mon Oct 10 17:21:53 2016 +0300 @@ -1,5 +1,5 @@ -NJS_VER = 0.1.2 +NJS_VER = 0.1.3 NXT_LIB = nxt ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Now njs_vm_compile() returns all global functions via the ...
details: http://hg.nginx.org/njs/rev/03d12ab0961e branches: changeset: 190:03d12ab0961e user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 10 16:33:56 2016 +0300 description: Now njs_vm_compile() returns all global functions via the export array. diffstat: nginx/ngx_http_js_module.c | 4 +- nginx/ngx_stream_js_module.c | 4 +- njs/njs_variable.c | 59 njs/njs_variable.h | 7 + njs/njscript.c | 7 - njs/njscript.h | 2 +- njs/test/njs_unit_test.c | 8 ++-- 7 files changed, 81 insertions(+), 10 deletions(-) diffs (207 lines): diff -r 769173883f87 -r 03d12ab0961e nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.cMon Oct 10 13:08:40 2016 +0300 +++ b/nginx/ngx_http_js_module.cMon Oct 10 16:33:56 2016 +0300 @@ -1225,7 +1225,7 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_ ngx_fd_t fd; ngx_str_t *value, file; nxt_int_t rc; -nxt_str_t text, ext; +nxt_str_t text, ext, *export; nxt_lvlhsh_t externals; ngx_file_info_tfi; njs_vm_shared_t *shared; @@ -1321,7 +1321,7 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_ return NGX_CONF_ERROR; } -rc = njs_vm_compile(jlcf->vm, , end, NULL); +rc = njs_vm_compile(jlcf->vm, , end, NULL, ); if (rc != NJS_OK) { njs_vm_exception(jlcf->vm, ); diff -r 769173883f87 -r 03d12ab0961e nginx/ngx_stream_js_module.c --- a/nginx/ngx_stream_js_module.c Mon Oct 10 13:08:40 2016 +0300 +++ b/nginx/ngx_stream_js_module.c Mon Oct 10 16:33:56 2016 +0300 @@ -933,7 +933,7 @@ ngx_stream_js_include(ngx_conf_t *cf, ng ngx_fd_t fd; ngx_str_t *value, file; nxt_int_t rc; -nxt_str_t text, ext; +nxt_str_t text, ext, *export; nxt_lvlhsh_t externals; ngx_file_info_tfi; njs_vm_shared_t *shared; @@ -1029,7 +1029,7 @@ ngx_stream_js_include(ngx_conf_t *cf, ng return NGX_CONF_ERROR; } -rc = njs_vm_compile(jscf->vm, , end, NULL); +rc = njs_vm_compile(jscf->vm, , end, NULL, ); if (rc != NJS_OK) { njs_vm_exception(jscf->vm, ); diff -r 769173883f87 -r 03d12ab0961e njs/njs_variable.c --- a/njs/njs_variable.cMon Oct 10 13:08:40 2016 +0300 +++ b/njs/njs_variable.cMon Oct 10 16:33:56 2016 +0300 @@ -153,6 +153,65 @@ njs_parser_variable(njs_vm_t *vm, njs_pa } +nxt_str_t * +njs_vm_export_functions(njs_vm_t *vm) +{ +size_t n; +nxt_str_t *ex, *export; +njs_value_t*value; +njs_variable_t *var; +nxt_lvlhsh_each_t lhe; + +n = 1; + +memset(, 0, sizeof(nxt_lvlhsh_each_t)); +lhe.proto = _variables_hash_proto; + +for ( ;; ) { +var = nxt_lvlhsh_each(>variables_hash, ); +if (var == NULL) { +break; +} + +value = njs_global_variable_value(vm, var); + +if (njs_is_function(value) && !value->data.u.function->native) { +n++; +} +} + +export = nxt_mem_cache_alloc(vm->mem_cache_pool, n * sizeof(nxt_str_t)); +if (nxt_slow_path(export == NULL)) { +return NULL; +} + +memset(, 0, sizeof(nxt_lvlhsh_each_t)); +lhe.proto = _variables_hash_proto; + +ex = export; + +for ( ;; ) { +var = nxt_lvlhsh_each(>variables_hash, ); +if (var == NULL) { +break; +} + +value = njs_global_variable_value(vm, var); + +if (njs_is_function(value) && !value->data.u.function->native) { +ex->length = var->name_len; +ex->start = var->name_start; +ex++; +} +} + +ex->length = 0; +ex->start = NULL; + +return export; +} + + njs_function_t * njs_vm_function(njs_vm_t *vm, nxt_str_t *name) { diff -r 769173883f87 -r 03d12ab0961e njs/njs_variable.h --- a/njs/njs_variable.hMon Oct 10 13:08:40 2016 +0300 +++ b/njs/njs_variable.hMon Oct 10 16:33:56 2016 +0300 @@ -26,10 +26,17 @@ typedef struct { } njs_variable_t; +#define njs_global_variable_value(vm, var)\ +(njs_value_t *) ((u_char *) vm->global_scope \ + + njs_offset((var)->index) - NJS_INDEX_GLOBAL_OFFSET) + + + njs_variable_t *njs_parser_name_alloc(njs_vm_t *vm, njs_parser_t *parser); njs_variable_t *njs_parser_variable(njs_vm_t *vm, njs_parser_t *parser, nxt_uint_t *level); njs_value_t *njs_variable_value(njs_parser_t *parser, njs_index_t index); +nxt_str_t *njs_vm_export_functions(njs_vm_t *vm); #endif /* _NJS_VARIABLE_H_INCLUDED_ */ diff -r 769173883f87 -r 03d12ab0961e njs/njscript.c --- a/njs/njscript.cMon Oct 10 13:08:
[njs] Now setting property of primitive type returns TypeError e...
details: http://hg.nginx.org/njs/rev/769173883f87 branches: changeset: 189:769173883f87 user: Igor Sysoev <i...@sysoev.ru> date: Mon Oct 10 13:08:40 2016 +0300 description: Now setting property of primitive type returns TypeError exception. diffstat: njs/njs_vm.c | 5 + njs/test/njs_unit_test.c | 9 ++--- 2 files changed, 11 insertions(+), 3 deletions(-) diffs (50 lines): diff -r 1261cc58591e -r 769173883f87 njs/njs_vm.c --- a/njs/njs_vm.c Tue Oct 04 11:28:29 2016 +0300 +++ b/njs/njs_vm.c Mon Oct 10 13:08:40 2016 +0300 @@ -642,6 +642,11 @@ njs_vmcode_property_set(njs_vm_t *vm, nj njs_property_query_t pq; njs_vmcode_prop_set_t *code; +if (njs_is_primitive(object)) { +vm->exception = _exception_type_error; +return NXT_ERROR; +} + code = (njs_vmcode_prop_set_t *) vm->current; value = njs_vmcode_operand(vm, code->value); diff -r 1261cc58591e -r 769173883f87 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Tue Oct 04 11:28:29 2016 +0300 +++ b/njs/test/njs_unit_test.c Mon Oct 10 13:08:40 2016 +0300 @@ -1833,6 +1833,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("a = {}; a.b.c"), nxt_string("TypeError") }, +{ nxt_string("'a'.b = 1"), + nxt_string("TypeError") }, + { nxt_string("a = {}; a.b = 1; a.b"), nxt_string("1") }, @@ -1867,10 +1870,10 @@ static njs_unit_test_t njs_test[] = nxt_string("TypeError") }, { nxt_string("a = true; a.b++; a.b"), - nxt_string("undefined") }, + nxt_string("TypeError") }, { nxt_string("a = 1; a.b++; a.b"), - nxt_string("undefined") }, + nxt_string("TypeError") }, { nxt_string("a = {}; a.b = {}; a.b.c = 1; a.b['c']"), nxt_string("1") }, @@ -1885,7 +1888,7 @@ static njs_unit_test_t njs_test[] = nxt_string("2 1") }, { nxt_string("a = 2; a.b = 1; c = a.b++; a +' '+ a.b +' '+ c"), - nxt_string("2 undefined NaN") }, + nxt_string("TypeError") }, { nxt_string("x = { a: 1 }; x.a"), nxt_string("1") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] A dead code found by Coverity Scan has been removed.
details: http://hg.nginx.org/njs/rev/1261cc58591e branches: changeset: 188:1261cc58591e user: Igor Sysoev <i...@sysoev.ru> date: Tue Oct 04 11:28:29 2016 +0300 description: A dead code found by Coverity Scan has been removed. diffstat: njs/njs_parser_expression.c | 5 - 1 files changed, 0 insertions(+), 5 deletions(-) diffs (15 lines): diff -r 8c2cea409034 -r 1261cc58591e njs/njs_parser_expression.c --- a/njs/njs_parser_expression.c Fri Sep 30 22:07:07 2016 +0300 +++ b/njs/njs_parser_expression.c Tue Oct 04 11:28:29 2016 +0300 @@ -971,11 +971,6 @@ njs_parser_call_expression(njs_vm_t *vm, func->ctor = 0; -if (token != NJS_TOKEN_OPEN_PARENTHESIS) { -parser->node = func; -return token; -} - token = njs_parser_arguments(vm, parser, func); if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) { return token; ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] A "var" statement termination has been fixed.
details: http://hg.nginx.org/njs/rev/b3e83fa52345 branches: changeset: 186:b3e83fa52345 user: Igor Sysoev <i...@sysoev.ru> date: Fri Sep 30 14:11:27 2016 +0300 description: A "var" statement termination has been fixed. diffstat: njs/njs_parser.c| 19 +++- njs/njs_parser_expression.c |1 - njs/test/njs_unit_test.c| 251 ++- 3 files changed, 146 insertions(+), 125 deletions(-) diffs (642 lines): diff -r 322359ec0913 -r b3e83fa52345 njs/njs_parser.c --- a/njs/njs_parser.c Wed Sep 28 19:52:05 2016 +0300 +++ b/njs/njs_parser.c Fri Sep 30 14:11:27 2016 +0300 @@ -717,7 +717,24 @@ njs_parser_var_statement(njs_vm_t *vm, n } while (token == NJS_TOKEN_COMMA); -return token; +/* + * A var statement must be terminated by semicolon, + * or by a close curly brace or by the end of line. + */ +switch (token) { + +case NJS_TOKEN_SEMICOLON: +case NJS_TOKEN_CLOSE_BRACE: +case NJS_TOKEN_END: +return token; + +default: +if (parser->lexer->prev_token == NJS_TOKEN_LINE_END) { +return token; +} + +return NJS_TOKEN_ILLEGAL; +} } diff -r 322359ec0913 -r b3e83fa52345 njs/njs_parser_expression.c --- a/njs/njs_parser_expression.c Wed Sep 28 19:52:05 2016 +0300 +++ b/njs/njs_parser_expression.c Fri Sep 30 14:11:27 2016 +0300 @@ -474,7 +474,6 @@ njs_parser_assignment_expression(njs_vm_ } token = njs_parser_assignment_expression(vm, parser, NULL, token); - if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) { return token; } diff -r 322359ec0913 -r b3e83fa52345 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Wed Sep 28 19:52:05 2016 +0300 +++ b/njs/test/njs_unit_test.c Fri Sep 30 14:11:27 2016 +0300 @@ -837,13 +837,13 @@ static njs_unit_test_t njs_test[] = { nxt_string("null < ({})"), nxt_string("false") }, -{ nxt_string("var a = { valueOf: function() { return 1 } } null < a"), - nxt_string("true") }, - -{ nxt_string("var a = { valueOf: function() { return 'null' } } null < a"), +{ nxt_string("var a = { valueOf: function() { return 1 } }; null < a"), + nxt_string("true") }, + +{ nxt_string("var a = { valueOf: function() { return 'null' } };null < a"), nxt_string("false") }, -{ nxt_string("var a = { valueOf: function() { return '1' } }null < a"), +{ nxt_string("var a = { valueOf: function() { return '1' } }; null < a"), nxt_string("true") }, /**/ @@ -887,14 +887,14 @@ static njs_unit_test_t njs_test[] = { nxt_string("undefined < ({})"), nxt_string("false") }, -{ nxt_string("var a = { valueOf: function() { return 1 } } undefined < a"), +{ nxt_string("var a = { valueOf: function() { return 1 } }; undefined < a"), nxt_string("false") }, -{ nxt_string("var a = { valueOf: function() { return 'undefined' } }" +{ nxt_string("var a = { valueOf: function() { return 'undefined' } };" "undefined < a"), nxt_string("false") }, -{ nxt_string("var a = { valueOf: function() { return '1' } }" +{ nxt_string("var a = { valueOf: function() { return '1' } };" "undefined < a"), nxt_string("false") }, @@ -1083,16 +1083,16 @@ static njs_unit_test_t njs_test[] = { nxt_string("var a = {}; a = ++a"), nxt_string("NaN") }, -{ nxt_string("var a = { valueOf: function() { return 1 } } a = ++a"), - nxt_string("2") }, - -{ nxt_string("var a = { valueOf: function() { return '1' } } a = ++a"), +{ nxt_string("var a = { valueOf: function() { return 1 } }; a = ++a"), nxt_string("2") }, -{ nxt_string("var a = { valueOf: function() { return [1] } } a = ++a"), +{ nxt_string("var a = { valueOf: function() { return '1' } }; a = ++a"), + nxt_string("2") }, + +{ nxt_string("var a = { valueOf: function() { return [1] } }; a = ++a"), nxt_string("NaN") }, -{ nxt_string("var a = { valueOf: function() { return {} } } a = ++a"), +{ nxt_string("var a = { valueOf: function() { return {} } }; a = ++a"), nxt_string("NaN") }, /**/ @@ -1109,19 +1109,19 @@ static njs_unit_test_t njs_test[] = { nxt_string("var a = {}; var b = ++a; a +' '+ b"), nxt_string("NaN NaN") }, -{ nxt_string("var a = { valueOf: function() { return 1 } }" +{ nxt_string("var a = { va
[njs] The cause of linker hanging on Linux/PPC64 has been
details: http://hg.nginx.org/njs/rev/eed097d72d5e branches: changeset: 182:eed097d72d5e user: Igor Sysoev <i...@sysoev.ru> date: Mon Sep 26 14:01:39 2016 +0300 description: The cause of linker hanging on Linux/PPC64 has been finally tracked down and thus only the aligment attribute has been correctly disabled on this platform. diffstat: nxt/auto/clang | 150 1 files changed, 75 insertions(+), 75 deletions(-) diffs (177 lines): diff -r 5ef1091ecfaf -r eed097d72d5e nxt/auto/clang --- a/nxt/auto/clangSun Sep 25 10:54:51 2016 +0300 +++ b/nxt/auto/clangMon Sep 26 14:01:39 2016 +0300 @@ -166,6 +166,77 @@ END # C language features. +nxt_feature="GCC __builtin_expect()" +nxt_feature_name=NXT_HAVE_BUILTIN_EXPECT +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="int main(int argc, char *const *argv) { + if ((__typeof__(argc == 0)) + __builtin_expect((argc == 0), 0)) + return 0; + return 1; + }" +. ${NXT_AUTO}feature + + +nxt_feature="GCC __builtin_unreachable()" +nxt_feature_name=NXT_HAVE_BUILTIN_UNREACHABLE +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="int main() { + __builtin_unreachable(); + }" +. ${NXT_AUTO}feature + + +nxt_feature="GCC __builtin_prefetch()" +nxt_feature_name=NXT_HAVE_BUILTIN_PREFETCH +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="int main() { + __builtin_prefetch(0); + }" +. ${NXT_AUTO}feature + + +nxt_feature="GCC __attribute__ visibility" +nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_VISIBILITY +nxt_feature_run= +nxt_feature_path= +nxt_feature_libs= +nxt_feature_test="int n __attribute__ ((visibility(\"default\"))); + + int main() { + return 1; + }" +. ${NXT_AUTO}feature + + +nxt_feature="GCC __attribute__ malloc" +nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_MALLOC +nxt_feature_run= +nxt_feature_path= +nxt_feature_libs= +nxt_feature_test="#include + + void *f(void) __attribute__ ((__malloc__)); + + void *f(void) { + return malloc(1); + } + + int main() { + if (f() != NULL) { + return 1; + } + return 0; + }" +. ${NXT_AUTO}feature + + nxt_os="$NXT_SYSTEM/$NXT_SYSTEM_PLATFORM" if [ "$nxt_os" = "Linux/ppc64le" ]; then @@ -173,59 +244,10 @@ if [ "$nxt_os" = "Linux/ppc64le" ]; then # Old GNU ld linker may hang on Linux ppc64le platform # if some of these features are enabled. -echo "checking for C language features is disabled for $nxt_os." +echo "checking for GCC __attribute__ aligned is disabled for $nxt_os." else -nxt_feature="GCC __builtin_expect()" -nxt_feature_name=NXT_HAVE_BUILTIN_EXPECT -nxt_feature_run=no -nxt_feature_incs= -nxt_feature_libs= -nxt_feature_test="int main(int argc, char *const *argv) { - if ((__typeof__(argc == 0)) - __builtin_expect((argc == 0), 0)) - return 0; - return 1; - }" -. ${NXT_AUTO}feature - - -nxt_feature="GCC __builtin_unreachable()" -nxt_feature_name=NXT_HAVE_BUILTIN_UNREACHABLE -nxt_feature_run=no -nxt_feature_incs= -nxt_feature_libs= -nxt_feature_test="int main() { - __builtin_unreachable(); - }" -. ${NXT_AUTO}feature - - -nxt_feature="GCC __builtin_prefetch()" -nxt_feature_name=NXT_HAVE_BUILTIN_PREFETCH -nxt_feature_run=no -nxt_feature_incs= -nxt_feature_libs= -nxt_feature_test="int main() { - __builtin_prefetch(0); - }" -. ${NXT_AUTO}feature - - -nxt_feature="GCC __attribute__ visibility" -nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_VISIBILITY -nxt_feature_run= -nxt_feature_path= -nxt_feature_libs= -nxt_feature_test="int n __attribute__ ((visibility(\"default\"))); - - int main() { - return 1; - }" -. ${NXT_AUTO}feature - - nxt_feature="GCC __attribute__ aligned" nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_ALIGNED nxt_feature_run= @@ -233,31 +255,9 @@ else nxt_feature_libs= nxt_feature_test="int n __attribute__ ((aligned(64)));
[njs] All C feature attributes have been disabled for Linux/PPC64.
details: http://hg.nginx.org/njs/rev/6a983847db14 branches: changeset: 180:6a983847db14 user: Igor Sysoev <i...@sysoev.ru> date: Sat Sep 24 22:13:31 2016 +0300 description: All C feature attributes have been disabled for Linux/PPC64. diffstat: nxt/auto/clang | 155 ++- nxt/nxt_clang.h |6 -- 2 files changed, 84 insertions(+), 77 deletions(-) diffs (190 lines): diff -r 6c65289c3696 -r 6a983847db14 nxt/auto/clang --- a/nxt/auto/clangFri Sep 23 11:59:58 2016 +0300 +++ b/nxt/auto/clangSat Sep 24 22:13:31 2016 +0300 @@ -166,85 +166,98 @@ END # C language features. -nxt_feature="GCC __builtin_expect()" -nxt_feature_name=NXT_HAVE_BUILTIN_EXPECT -nxt_feature_run=no -nxt_feature_incs= -nxt_feature_libs= -nxt_feature_test="int main(int argc, char *const *argv) { - if ((__typeof__(argc == 0)) - __builtin_expect((argc == 0), 0)) - return 0; - return 1; - }" -. ${NXT_AUTO}feature - +nxt_os="$NXT_SYSTEM/$NXT_SYSTEM_PLATFORM" -nxt_feature="GCC __builtin_unreachable()" -nxt_feature_name=NXT_HAVE_BUILTIN_UNREACHABLE -nxt_feature_run=no -nxt_feature_incs= -nxt_feature_libs= -nxt_feature_test="int main() { - __builtin_unreachable(); - }" -. ${NXT_AUTO}feature +if [ "$nxt_os" = "Linux/ppc64le" ]; then +# Old GNU ld linker may hang on Linux ppc64le platform +# if some of these features are enabled. -nxt_feature="GCC __builtin_prefetch()" -nxt_feature_name=NXT_HAVE_BUILTIN_PREFETCH -nxt_feature_run=no -nxt_feature_incs= -nxt_feature_libs= -nxt_feature_test="int main() { - __builtin_prefetch(0); - }" -. ${NXT_AUTO}feature +echo "checking for C language features is disabled for $nxt_os." + +else + +nxt_feature="GCC __builtin_expect()" +nxt_feature_name=NXT_HAVE_BUILTIN_EXPECT +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="int main(int argc, char *const *argv) { + if ((__typeof__(argc == 0)) + __builtin_expect((argc == 0), 0)) + return 0; + return 1; + }" +. ${NXT_AUTO}feature -nxt_feature="GCC __attribute__ visibility" -nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_VISIBILITY -nxt_feature_run= -nxt_feature_path= -nxt_feature_libs= -nxt_feature_test="int n __attribute__ ((visibility(\"default\"))); - - int main() { - return 1; - }" -. ${NXT_AUTO}feature +nxt_feature="GCC __builtin_unreachable()" +nxt_feature_name=NXT_HAVE_BUILTIN_UNREACHABLE +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="int main() { + __builtin_unreachable(); + }" +. ${NXT_AUTO}feature -nxt_feature="GCC __attribute__ aligned" -nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_ALIGNED -nxt_feature_run= -nxt_feature_path= -nxt_feature_libs= -nxt_feature_test="int n __attribute__ ((aligned(64))); - - int main() { - return 1; - }" -. ${NXT_AUTO}feature +nxt_feature="GCC __builtin_prefetch()" +nxt_feature_name=NXT_HAVE_BUILTIN_PREFETCH +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="int main() { + __builtin_prefetch(0); + }" +. ${NXT_AUTO}feature -nxt_feature="GCC __attribute__ malloc" -nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_MALLOC -nxt_feature_run= -nxt_feature_path= -nxt_feature_libs= -nxt_feature_test="#include - - void *f(void) __attribute__ ((__malloc__)); +nxt_feature="GCC __attribute__ visibility" +nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_VISIBILITY +nxt_feature_run= +nxt_feature_path= +nxt_feature_libs= +nxt_feature_test="int n __attribute__ ((visibility(\"default\"))); - void *f(void) { - return malloc(1); - } + int main() { + return 1; + }" +. ${NXT_AUTO}feature - int main() { - if (f() != NULL) { - return 1; - } - return 0; - }" -. ${NXT_AUTO}feature + +nxt_feature="GCC __attribute__ aligned" +nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_ALIGNED +nxt_feature_run= +nxt_feature_path=
[njs] A fix of possible sign extension overflow,
details: http://hg.nginx.org/njs/rev/5ef1091ecfaf branches: changeset: 181:5ef1091ecfaf user: Igor Sysoev <i...@sysoev.ru> date: Sun Sep 25 10:54:51 2016 +0300 description: A fix of possible sign extension overflow, the issue has been found by Coverity Scan. diffstat: nxt/nxt_array.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (21 lines): diff -r 6a983847db14 -r 5ef1091ecfaf nxt/nxt_array.c --- a/nxt/nxt_array.c Sat Sep 24 22:13:31 2016 +0300 +++ b/nxt/nxt_array.c Sun Sep 25 10:54:51 2016 +0300 @@ -113,7 +113,7 @@ nxt_array_add_multiple(nxt_array_t *arra old = array->start; array->start = start; -memcpy(start, old, array->items * array->item_size); +memcpy(start, old, (uint32_t) array->items * array->item_size); if (array->separate == 0) { array->separate = 1; @@ -123,7 +123,7 @@ nxt_array_add_multiple(nxt_array_t *arra } } -item = (char *) array->start + array->items * array->item_size; +item = (char *) array->start + (uint32_t) array->items * array->item_size; array->items = items; ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] The visibility attribute disabling in the commit af6c17324584
details: http://hg.nginx.org/njs/rev/6c65289c3696 branches: changeset: 179:6c65289c3696 user: Igor Sysoev <i...@sysoev.ru> date: Fri Sep 23 11:59:58 2016 +0300 description: The visibility attribute disabling in the commit af6c17324584 had not resovled the issue. So now it is enabled and the aligment attribute has been disabled instead for Linux/PPC64. diffstat: nxt/auto/clang | 13 + nxt/nxt_clang.h | 22 ++ 2 files changed, 27 insertions(+), 8 deletions(-) diffs (62 lines): diff -r 9d09f9a522d6 -r 6c65289c3696 nxt/auto/clang --- a/nxt/auto/clangFri Sep 23 11:59:56 2016 +0300 +++ b/nxt/auto/clangFri Sep 23 11:59:58 2016 +0300 @@ -202,6 +202,19 @@ nxt_feature_test="int main() { . ${NXT_AUTO}feature +nxt_feature="GCC __attribute__ visibility" +nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_VISIBILITY +nxt_feature_run= +nxt_feature_path= +nxt_feature_libs= +nxt_feature_test="int n __attribute__ ((visibility(\"default\"))); + + int main() { + return 1; + }" +. ${NXT_AUTO}feature + + nxt_feature="GCC __attribute__ aligned" nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_ALIGNED nxt_feature_run= diff -r 9d09f9a522d6 -r 6c65289c3696 nxt/nxt_clang.h --- a/nxt/nxt_clang.h Fri Sep 23 11:59:56 2016 +0300 +++ b/nxt/nxt_clang.h Fri Sep 23 11:59:58 2016 +0300 @@ -60,6 +60,20 @@ #endif +#if (NXT_HAVE_GCC_ATTRIBUTE_ALIGNED) + +#if (NXT_LINUX && __PPC64__) +/* Old GNU ld linker may hang on Linux ppc64le platform. */ +#define nxt_aligned(x) +#else +#define nxt_aligned(x) __attribute__((aligned(x))) +#endif + +#else +#define nxt_aligned(x) +#endif + + #if (NXT_HAVE_GCC_ATTRIBUTE_MALLOC) #define NXT_MALLOC_LIKE__attribute__((__malloc__)) @@ -68,14 +82,6 @@ #endif -#if (NXT_HAVE_GCC_ATTRIBUTE_ALIGNED) -#define nxt_aligned(x) __attribute__((aligned(x))) - -#else -#define nxt_aligned(x) -#endif - - #if (NXT_CLANG) /* Any __asm__ directive disables loop vectorization in GCC and Clang. */ #define nxt_pragma_loop_disable_vectorization __asm__("") ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] String.replace() function.
details: http://hg.nginx.org/njs/rev/04aee54864c3 branches: changeset: 177:04aee54864c3 user: Igor Sysoev <i...@sysoev.ru> date: Fri Sep 23 11:59:48 2016 +0300 description: String.replace() function. diffstat: njs/njs_function.h | 11 +- njs/njs_regexp.c |4 +- njs/njs_regexp_pattern.h |6 + njs/njs_string.c | 739 ++- njs/njs_string.h | 29 + njs/njs_vm.c | 14 + njs/test/njs_unit_test.c | 90 + nxt/auto/clang |2 +- nxt/nxt_array.c | 66 ++- nxt/nxt_array.h | 20 +- nxt/nxt_pcre.c | 23 +- nxt/nxt_pcre.h |4 +- nxt/nxt_regex.h |1 + 13 files changed, 949 insertions(+), 60 deletions(-) diffs (truncated from 1296 to 1000 lines): diff -r 28bc6acceb0e -r 04aee54864c3 njs/njs_function.h --- a/njs/njs_function.hThu Sep 15 18:00:55 2016 +0300 +++ b/njs/njs_function.hFri Sep 23 11:59:48 2016 +0300 @@ -11,11 +11,12 @@ #define NJS_SKIP_ARG 1 #define NJS_NUMBER_ARG 2 #define NJS_INTEGER_ARG3 -#define NJS_STRING_OBJECT_ARG 4 -#define NJS_STRING_ARG 5 -#define NJS_OBJECT_ARG 6 -#define NJS_REGEXP_ARG 7 -#define NJS_DATE_ARG 8 +#define NJS_STRING_ARG 4 +#define NJS_OBJECT_ARG 5 +#define NJS_STRING_OBJECT_ARG 6 +#define NJS_FUNCTION_ARG 7 +#define NJS_REGEXP_ARG 8 +#define NJS_DATE_ARG 9 struct njs_function_lambda_s { diff -r 28bc6acceb0e -r 04aee54864c3 njs/njs_regexp.c --- a/njs/njs_regexp.c Thu Sep 15 18:00:55 2016 +0300 +++ b/njs/njs_regexp.c Fri Sep 23 11:59:48 2016 +0300 @@ -609,7 +609,7 @@ njs_regexp_prototype_test(njs_vm_t *vm, if (ret >= 0) { retval = _value_true; -} else if (ret != NGX_REGEX_NOMATCH) { +} else if (ret != NXT_REGEX_NOMATCH) { return NXT_ERROR; } } @@ -683,7 +683,7 @@ njs_regexp_prototype_exec(njs_vm_t *vm, utf8); } -if (nxt_slow_path(ret != NGX_REGEX_NOMATCH)) { +if (nxt_slow_path(ret != NXT_REGEX_NOMATCH)) { nxt_regex_match_data_free(match_data, vm->regex_context); return NXT_ERROR; diff -r 28bc6acceb0e -r 04aee54864c3 njs/njs_regexp_pattern.h --- a/njs/njs_regexp_pattern.h Thu Sep 15 18:00:55 2016 +0300 +++ b/njs/njs_regexp_pattern.h Fri Sep 23 11:59:48 2016 +0300 @@ -10,6 +10,12 @@ #include +typedef enum { +NJS_REGEXP_BYTE = 0, +NJS_REGEXP_UTF8, +} njs_regexp_utf8_t; + + struct njs_regexp_pattern_s { nxt_regex_t regex[2]; diff -r 28bc6acceb0e -r 04aee54864c3 njs/njs_string.c --- a/njs/njs_string.c Thu Sep 15 18:00:55 2016 +0300 +++ b/njs/njs_string.c Fri Sep 23 11:59:48 2016 +0300 @@ -33,6 +33,50 @@ #include +typedef struct { +u_char *start; +size_t size; +njs_value_tvalue; +} njs_string_replace_part_t; + + +#define NJS_SUBST_COPY255 +#define NJS_SUBST_PRECEDING 254 +#define NJS_SUBST_FOLLOWING 253 + + +typedef struct { + uint32_t type; + uint32_t size; + u_char*start; +} njs_string_subst_t; + + +typedef struct { +union { +njs_continuation_t cont; +u_char padding[NJS_CONTINUATION_SIZE]; +} u; +/* + * This retval value must be aligned so the continuation + * is padded to aligned size. + */ +njs_value_tretval; + +nxt_array_tparts; +njs_string_replace_part_t array[3]; +njs_string_replace_part_t *part; + +nxt_array_t*substitutions; +njs_function_t *function; + +nxt_regex_match_data_t *match_data; + +njs_utf8_t utf8:8; +njs_regexp_utf8_t type:8; +} njs_string_replace_t; + + static nxt_noinline void njs_string_slice_prop(njs_string_prop_t *string, njs_slice_prop_t *slice, njs_value_t *args, nxt_uint_t nargs); static nxt_noinline void njs_string_slice_args(njs_slice_prop_t *slice, @@ -45,6 +89,28 @@ static njs_ret_t njs_string_match_multip njs_regexp_pattern_t *pattern); static njs_ret_t njs_string_split_part_add(njs_vm_t *vm, njs_array_t *array, u_char *start, size_t size, nxt_uint_t utf8); +static njs_ret_t njs_string_replace_regexp(njs_vm_t *vm, njs_value_t *args, +njs_string_replace_t *r); +static njs_ret_t njs_string_replace_regexp_function(njs_vm_t *vm, +njs_value_t *args, njs_string_replace_t *r, int *captures, nxt_uint_t n); +static njs_ret_t njs_string_replace_regexp_continuation(njs_vm_t *vm, +njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +static njs_ret_t njs_string_replace_regexp_join(njs_vm_t *vm, +njs_string_replace_t *r); +static njs_ret_t njs_string_replace_sea
[njs] Added tag 0.1.2 for changeset 5b066b4db54c
details: http://hg.nginx.org/njs/rev/efd2f95aaeb4 branches: changeset: 172:efd2f95aaeb4 user: Igor Sysoev <i...@sysoev.ru> date: Tue Sep 13 16:59:27 2016 +0300 description: Added tag 0.1.2 for changeset 5b066b4db54c diffstat: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (7 lines): diff -r 5b066b4db54c -r efd2f95aaeb4 .hgtags --- a/.hgtags Tue Sep 13 16:59:09 2016 +0300 +++ b/.hgtags Tue Sep 13 16:59:27 2016 +0300 @@ -1,2 +1,3 @@ cdb8d20935ee96f1fa0c99d994d4b11cefcbc119 0.1.0 0039a747d25a3e08792c23c43b75768896724031 0.1.1 +5b066b4db54c17dc0a9a72948474f36957462e87 0.1.2 ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Constructor function prototypes now have correct types and...
details: http://hg.nginx.org/njs/rev/cb414901 branches: changeset: 169:cb414901 user: Igor Sysoev <i...@sysoev.ru> date: Tue Sep 13 16:19:26 2016 +0300 description: Constructor function prototypes now have correct types and values. diffstat: njs/njs_array.c |3 +- njs/njs_array.h |9 -- njs/njs_builtin.c| 49 -- njs/njs_date.c |3 +- njs/njs_date.h |6 - njs/njs_function.c |6 +- njs/njs_object.c | 52 +-- njs/njs_object.h |6 - njs/njs_regexp.c |3 +- njs/njs_regexp.h | 16 - njs/njs_vm.c |8 +- njs/njs_vm.h | 150 +++--- njs/test/njs_unit_test.c | 48 +++ 13 files changed, 234 insertions(+), 125 deletions(-) diffs (762 lines): diff -r 19758fdcd554 -r cb414901 njs/njs_array.c --- a/njs/njs_array.c Thu Sep 01 16:12:31 2016 +0300 +++ b/njs/njs_array.c Tue Sep 13 16:19:26 2016 +0300 @@ -133,7 +133,8 @@ njs_array_alloc(njs_vm_t *vm, uint32_t l array->start = array->data; nxt_lvlhsh_init(>object.hash); nxt_lvlhsh_init(>object.shared_hash); -array->object.__proto__ = >prototypes[NJS_PROTOTYPE_ARRAY]; +array->object.__proto__ = >prototypes[NJS_PROTOTYPE_ARRAY].object; +array->object.type = NJS_ARRAY; array->object.shared = 0; array->size = size; array->length = length; diff -r 19758fdcd554 -r cb414901 njs/njs_array.h --- a/njs/njs_array.h Thu Sep 01 16:12:31 2016 +0300 +++ b/njs/njs_array.h Tue Sep 13 16:19:26 2016 +0300 @@ -10,15 +10,6 @@ #define NJS_ARRAY_SPARE 8 -struct njs_array_s { -/* Must be aligned to njs_value_t. */ -njs_object_t object; -uint32_t size; -uint32_t length; -njs_value_t *start; -njs_value_t *data; -}; - njs_array_t *njs_array_alloc(njs_vm_t *vm, uint32_t length, uint32_t spare); njs_ret_t njs_array_string_add(njs_vm_t *vm, njs_array_t *array, u_char *start, diff -r 19758fdcd554 -r cb414901 njs/njs_builtin.c --- a/njs/njs_builtin.c Thu Sep 01 16:12:31 2016 +0300 +++ b/njs/njs_builtin.c Tue Sep 13 16:19:26 2016 +0300 @@ -37,10 +37,11 @@ typedef struct { nxt_int_t njs_builtin_objects_create(njs_vm_t *vm) { -nxt_int_t ret; -nxt_uint_t i; -njs_object_t*objects, *prototypes; -njs_function_t *functions, *constructors; +nxt_int_t ret; +nxt_uint_t i; +njs_object_t*objects; +njs_function_t *functions, *constructors; +njs_object_prototype_t *prototypes; static const njs_object_init_t*prototype_init[] = { _object_prototype_init, @@ -53,6 +54,29 @@ njs_builtin_objects_create(njs_vm_t *vm) _date_prototype_init, }; +static const njs_object_prototype_t prototype_values[] = { +{ .object.type = NJS_OBJECT }, +{ .object.type = NJS_ARRAY }, + +/* + * The .object.type field must be initialzed after the .value field, + * otherwise SunC 5.9 treats the .value as .object.value or so. + */ +{ .object_value = { .value = njs_value(NJS_BOOLEAN, 0, 0.0), +.object.type = NJS_OBJECT_BOOLEAN } }, + +{ .object_value = { .value = njs_value(NJS_NUMBER, 0, 0.0), +.object.type = NJS_OBJECT_NUMBER } }, + +{ .object_value = { .value = njs_string(""), +.object.type = NJS_OBJECT_STRING } }, + +{ .object.type = NJS_FUNCTION }, +{ .object.type = NJS_REGEXP }, + +{ .date = { .time = NJS_NAN, .object.type = NJS_DATE } }, +}; + static const njs_object_init_t*constructor_init[] = { _object_constructor_init, _array_constructor_init, @@ -172,7 +196,9 @@ njs_builtin_objects_create(njs_vm_t *vm) prototypes = vm->shared->prototypes; for (i = NJS_PROTOTYPE_OBJECT; i < NJS_PROTOTYPE_MAX; i++) { -ret = njs_object_hash_create(vm, [i].shared_hash, +prototypes[i] = prototype_values[i]; + +ret = njs_object_hash_create(vm, [i].object.shared_hash, prototype_init[i]->properties, prototype_init[i]->items); if (nxt_slow_path(ret != NXT_OK)) { @@ -180,6 +206,9 @@ njs_builtin_objects_create(njs_vm_t *vm) } } +prototypes[NJS_PROTOTYPE_REGEXP].regexp.pattern = + vm->empty_regexp.data.u.regexp->pattern; + constructors = vm->shared->constructors; for (i = NJS_CONSTRUCTOR_OBJECT; i < NJS_CONSTRUCTOR_MAX; i++) { @@ -249,22 +278,24 @@ njs_builtin_objects_clone(njs_vm_t *vm) size_tsize; nxt_uint_ti; njs_value_t *va
[njs] Now Date.parse() and Date() accept shortcut date strings.
details: http://hg.nginx.org/njs/rev/19758fdcd554 branches: changeset: 168:19758fdcd554 user: Igor Sysoev <i...@sysoev.ru> date: Thu Sep 01 16:12:31 2016 +0300 description: Now Date.parse() and Date() accept shortcut date strings. diffstat: njs/njs_date.c | 305 -- njs/test/njs_unit_test.c | 39 ++ 2 files changed, 247 insertions(+), 97 deletions(-) diffs (487 lines): diff -r af6c17324584 -r 19758fdcd554 njs/njs_date.c --- a/njs/njs_date.cThu Sep 01 13:28:44 2016 +0300 +++ b/njs/njs_date.cThu Sep 01 16:12:31 2016 +0300 @@ -44,6 +44,10 @@ static nxt_noinline double njs_date_string_parse(njs_value_t *date); +static double njs_date_rfc2822_string_parse(struct tm *tm, const u_char *p, +const u_char *end); +static double njs_date_js_string_parse(struct tm *tm, const u_char *p, +const u_char *end); static const u_char *njs_date_skip_week_day(const u_char *p, const u_char *end); static const u_char *njs_date_skip_spaces(const u_char *p, const u_char *end); static nxt_noinline nxt_int_t njs_date_month_parse(const u_char *p, @@ -297,9 +301,9 @@ njs_date_parse(njs_vm_t *vm, njs_value_t static nxt_noinline double njs_date_string_parse(njs_value_t *date) { -intext, ms, gmtoff; +intext, ms; struct tm tm; -nxt_bool_t sign; +nxt_bool_t sign, week; const u_char *p, *next, *end; njs_string_prop_t string; @@ -308,7 +312,7 @@ njs_date_string_parse(njs_value_t *date) p = string.start; end = p + string.size; -if (nxt_slow_path(p + 10 >= end)) { +if (nxt_slow_path(p >= end)) { return NJS_NAN; } @@ -324,11 +328,21 @@ njs_date_string_parse(njs_value_t *date) sign = 0; } +tm.tm_mon = 0; +tm.tm_mday = 1; +tm.tm_hour = 0; +tm.tm_min = 0; +tm.tm_sec = 0; + next = njs_date_number_parse(_year, p, end, 4); if (next != NULL) { /* ISO-8601 format: "1970-09-28T06:00:00.000Z" */ +if (next == end) { +goto year; +} + if (*next != '-') { /* Extended ISO-8601 format: "+001970-09-28T06:00:00.000Z" */ @@ -347,6 +361,10 @@ njs_date_string_parse(njs_value_t *date) tm.tm_year = -tm.tm_year; } +if (next == end) { +goto year; +} + if (*next != '-') { return NJS_NAN; } @@ -361,7 +379,11 @@ njs_date_string_parse(njs_value_t *date) tm.tm_mon--; -if (nxt_slow_path(p >= end || *p != '-')) { +if (p == end) { +goto done; +} + +if (nxt_slow_path(*p != '-')) { return NJS_NAN; } @@ -370,7 +392,11 @@ njs_date_string_parse(njs_value_t *date) return NJS_NAN; } -if (nxt_slow_path(p >= end || *p != 'T')) { +if (p == end) { +goto done; +} + +if (nxt_slow_path(*p != 'T')) { return NJS_NAN; } @@ -379,6 +405,10 @@ njs_date_string_parse(njs_value_t *date) return NJS_NAN; } +if (p == end) { +goto done; +} + if (nxt_slow_path(p >= end || *p != '.')) { return NJS_NAN; } @@ -399,86 +429,68 @@ njs_date_string_parse(njs_value_t *date) return NJS_NAN; } -p = njs_date_skip_week_day(p, end); -if (nxt_slow_path(p == NULL)) { -return NJS_NAN; +week = 1; + +for ( ;; ) { +next = njs_date_number_parse(_mday, p, end, 2); + +if (next != NULL) { +/* + * RFC 2822 format: + * "Mon, 28 Sep 1970 06:00:00 GMT", + * "Mon, 28 Sep 1970 06:00:00 UTC", + * "Mon, 28 Sep 1970 12:00:00 +0600". + */ +return njs_date_rfc2822_string_parse(, next, end); +} + +tm.tm_mon = njs_date_month_parse(p, end); + +if (tm.tm_mon >= 0) { +/* Date.toString() format: "Mon Sep 28 1970 12:00:00 GMT+0600". */ + +return njs_date_js_string_parse(, p + 3, end); +} + +if (!week) { +return NJS_NAN; +} + +p = njs_date_skip_week_day(p, end); +if (nxt_slow_path(p == NULL)) { +return NJS_NAN; +} + +p = njs_date_skip_spaces(p, end); +if (nxt_slow_path(p == NULL)) { +return NJS_NAN; +} + +week = 0; } +year: + +tm.tm_year -= 1900; + +done: + +return njs_timegm() * 1000; +} + + +static double +njs_date_rfc2822_string_parse(struct tm *tm, const u_char *p, const u_char *end) +{ +int gmtoff; + p = njs_date_skip_spaces(p, end); if (nxt_slow_path(p == NULL)) { return NJS_NAN;
[njs] A fix in decodeURI() and decodeURIComponent() functions.
details: http://hg.nginx.org/njs/rev/715b147cbfe0 branches: changeset: 166:715b147cbfe0 user: Igor Sysoev <i...@sysoev.ru> date: Wed Aug 31 19:28:08 2016 +0300 description: A fix in decodeURI() and decodeURIComponent() functions. diffstat: njs/njs_string.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diffs (23 lines): diff -r 584114a51b51 -r 715b147cbfe0 njs/njs_string.c --- a/njs/njs_string.c Wed Aug 31 19:18:47 2016 +0300 +++ b/njs/njs_string.c Wed Aug 31 19:28:08 2016 +0300 @@ -2317,8 +2317,8 @@ njs_string_decode(njs_vm_t *vm, njs_valu { int8_t d0, d1; u_char byte, *start, *src, *dst; -size_t n, size; -ssize_t length; +size_t n; +ssize_t size, length; nxt_bool_t utf8; njs_string_prop_tstring; @@ -2358,7 +2358,7 @@ njs_string_decode(njs_vm_t *vm, njs_valu size -= 2; -if (size == 0) { +if (size <= 0) { goto uri_error; } ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] A fix in decodeURI() function.
details: http://hg.nginx.org/njs/rev/584114a51b51 branches: changeset: 165:584114a51b51 user: Igor Sysoev <i...@sysoev.ru> date: Wed Aug 31 19:18:47 2016 +0300 description: A fix in decodeURI() function. diffstat: njs/njs_string.c | 6 -- 1 files changed, 4 insertions(+), 2 deletions(-) diffs (23 lines): diff -r 76f16f0ef6c5 -r 584114a51b51 njs/njs_string.c --- a/njs/njs_string.c Wed Aug 31 17:51:54 2016 +0300 +++ b/njs/njs_string.c Wed Aug 31 19:18:47 2016 +0300 @@ -2355,7 +2355,10 @@ njs_string_decode(njs_vm_t *vm, njs_valu byte = *src++; if (byte == '%') { -if (size < 3) { + +size -= 2; + +if (size == 0) { goto uri_error; } @@ -2372,7 +2375,6 @@ njs_string_decode(njs_vm_t *vm, njs_valu byte = (d0 << 4) + d1; if ((reserve[byte >> 5] & ((uint32_t) 1 << (byte & 0x1f))) == 0) { -size -= 2; n += 2; } } ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] A fix in decodeURI() and decodeURIComponent() functions.
details: http://hg.nginx.org/njs/rev/76f16f0ef6c5 branches: changeset: 164:76f16f0ef6c5 user: Igor Sysoev <i...@sysoev.ru> date: Wed Aug 31 17:51:54 2016 +0300 description: A fix in decodeURI() and decodeURIComponent() functions. diffstat: njs/njs_string.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (11 lines): diff -r c0aa3ecd2e83 -r 76f16f0ef6c5 njs/njs_string.c --- a/njs/njs_string.c Wed Aug 31 15:53:13 2016 +0300 +++ b/njs/njs_string.c Wed Aug 31 17:51:54 2016 +0300 @@ -2372,6 +2372,7 @@ njs_string_decode(njs_vm_t *vm, njs_valu byte = (d0 << 4) + d1; if ((reserve[byte >> 5] & ((uint32_t) 1 << (byte & 0x1f))) == 0) { +size -= 2; n += 2; } } ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] An invalid value of Date object has been fixed.
details: http://hg.nginx.org/njs/rev/c0aa3ecd2e83 branches: changeset: 163:c0aa3ecd2e83 user: Igor Sysoev <i...@sysoev.ru> date: Wed Aug 31 15:53:13 2016 +0300 description: An invalid value of Date object has been fixed. diffstat: njs/njs_date.c | 10 ++ njs/test/njs_unit_test.c | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diffs (47 lines): diff -r 47f4830c3d22 -r c0aa3ecd2e83 njs/njs_date.c --- a/njs/njs_date.cTue Aug 30 12:11:24 2016 +0300 +++ b/njs/njs_date.cWed Aug 31 15:53:13 2016 +0300 @@ -81,8 +81,8 @@ njs_ret_t njs_date_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { -double num; -int64_t time, values[8]; +double num, time; +int64_t values[8]; nxt_uint_t i, n; njs_date_t *date; struct tm tm; @@ -110,8 +110,8 @@ njs_date_constructor(njs_vm_t *vm, njs_v num = args[i].data.u.number; if (njs_is_nan(num)) { -nargs = 0; -break; +time = num; +goto done; } values[i] = num; @@ -138,6 +138,8 @@ njs_date_constructor(njs_vm_t *vm, njs_v } } +done: + date = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_date_t)); if (nxt_slow_path(date == NULL)) { return NXT_ERROR; diff -r 47f4830c3d22 -r c0aa3ecd2e83 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Tue Aug 30 12:11:24 2016 +0300 +++ b/njs/test/njs_unit_test.c Wed Aug 31 15:53:13 2016 +0300 @@ -4465,6 +4465,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("var o = Object.create(null); '__proto__' in o"), nxt_string("false") }, +{ nxt_string("var d = new Date(''); d +' '+ d.getTime()"), + nxt_string("Invalid Date NaN") }, + { nxt_string("var d = new Date(130889520); d.getTime()"), nxt_string("130889520") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] C language features have been enabled.
details: http://hg.nginx.org/njs/rev/47f4830c3d22 branches: changeset: 162:47f4830c3d22 user: Igor Sysoev <i...@sysoev.ru> date: Tue Aug 30 12:11:24 2016 +0300 description: C language features have been enabled. diffstat: nxt/auto/clang | 86 ++ 1 files changed, 86 insertions(+), 0 deletions(-) diffs (93 lines): diff -r 323f00dc9879 -r 47f4830c3d22 nxt/auto/clang --- a/nxt/auto/clangTue Aug 30 12:05:46 2016 +0300 +++ b/nxt/auto/clangTue Aug 30 12:11:24 2016 +0300 @@ -162,3 +162,89 @@ cat << END >> $NXT_MAKEFILE_CONF NXT_CC = ${CC} NXT_CFLAGS = ${CFLAGS} ${NXT_CFLAGS} END + + +# C language features. + +nxt_feature="GCC __builtin_expect()" +nxt_feature_name=NXT_HAVE_BUILTIN_EXPECT +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="int main(int argc, char *const *argv) { + if ((__typeof__(argc == 0)) + __builtin_expect((argc == 0), 0)) + return 0; + return 1; + }" +. ${NXT_AUTO}feature + + +nxt_feature="GCC __builtin_unreachable()" +nxt_feature_name=NXT_HAVE_BUILTIN_UNREACHABLE +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="int main() { + __builtin_unreachable(); + }" +. ${NXT_AUTO}feature + + +nxt_feature="GCC __builtin_prefetch()" +nxt_feature_name=NXT_HAVE_BUILTIN_PREFETCH +nxt_feature_run=no +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="int main() { + __builtin_prefetch(0); + }" +. ${NXT_AUTO}feature + + +nxt_feature="GCC __attribute__ visibility" +nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_VISIBILITY +nxt_feature_run= +nxt_feature_path= +nxt_feature_libs= +nxt_feature_test="int n __attribute__ ((visibility(\"default\"))); + + int main() { + return 1; + }" +. ${NXT_AUTO}feature + + +nxt_feature="GCC __attribute__ aligned" +nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_ALIGNED +nxt_feature_run= +nxt_feature_path= +nxt_feature_libs= +nxt_feature_test="int n __attribute__ ((aligned(64))); + + int main() { + return 1; + }" +. ${NXT_AUTO}feature + + +nxt_feature="GCC __attribute__ malloc" +nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_MALLOC +nxt_feature_run= +nxt_feature_path= +nxt_feature_libs= +nxt_feature_test="#include + + void *f(void) __attribute__ ((__malloc__)); + + void *f(void) { + return malloc(1); + } + + int main() { + if (f() != NULL) { + return 1; + } + return 0; + }" +. ${NXT_AUTO}feature ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] decodeURI() and decodeURIComponent() functions.
details: http://hg.nginx.org/njs/rev/323f00dc9879 branches: changeset: 161:323f00dc9879 user: Igor Sysoev <i...@sysoev.ru> date: Tue Aug 30 12:05:46 2016 +0300 description: decodeURI() and decodeURIComponent() functions. diffstat: njs/njs_builtin.c|4 + njs/njs_generator.c |2 + njs/njs_lexer_keyword.c |2 + njs/njs_parser.c |2 + njs/njs_parser.h | 10 +- njs/njs_string.c | 206 +++ njs/njs_string.h |4 + njs/njs_vm.c |1 + njs/njs_vm.h |5 +- njs/test/njs_unit_test.c | 33 +++ 10 files changed, 264 insertions(+), 5 deletions(-) diffs (403 lines): diff -r d63ecb57f164 -r 323f00dc9879 njs/njs_builtin.c --- a/njs/njs_builtin.c Tue Aug 30 12:02:31 2016 +0300 +++ b/njs/njs_builtin.c Tue Aug 30 12:05:46 2016 +0300 @@ -90,6 +90,8 @@ njs_builtin_objects_create(njs_vm_t *vm) NULL, /* parseFloat */ NULL, /* encodeURI */ NULL, /* encodeURIComponent */ +NULL, /* decodeURI */ +NULL, /* decodeURIComponent */ }; static const njs_function_init_t native_functions[] = { @@ -103,6 +105,8 @@ njs_builtin_objects_create(njs_vm_t *vm) { njs_number_parse_float, { NJS_SKIP_ARG, NJS_STRING_ARG } }, { njs_string_encode_uri, { NJS_SKIP_ARG, NJS_STRING_ARG } }, { njs_string_encode_uri_component, { NJS_SKIP_ARG, NJS_STRING_ARG } }, +{ njs_string_decode_uri, { NJS_SKIP_ARG, NJS_STRING_ARG } }, +{ njs_string_decode_uri_component, { NJS_SKIP_ARG, NJS_STRING_ARG } }, }; static const njs_object_prop_tnull_proto_property = { diff -r d63ecb57f164 -r 323f00dc9879 njs/njs_generator.c --- a/njs/njs_generator.c Tue Aug 30 12:02:31 2016 +0300 +++ b/njs/njs_generator.c Tue Aug 30 12:05:46 2016 +0300 @@ -302,6 +302,8 @@ njs_generator(njs_vm_t *vm, njs_parser_t case NJS_TOKEN_PARSE_FLOAT: case NJS_TOKEN_ENCODE_URI: case NJS_TOKEN_ENCODE_URI_COMPONENT: +case NJS_TOKEN_DECODE_URI: +case NJS_TOKEN_DECODE_URI_COMPONENT: return njs_generate_builtin_object(vm, parser, node); case NJS_TOKEN_FUNCTION: diff -r d63ecb57f164 -r 323f00dc9879 njs/njs_lexer_keyword.c --- a/njs/njs_lexer_keyword.c Tue Aug 30 12:02:31 2016 +0300 +++ b/njs/njs_lexer_keyword.c Tue Aug 30 12:05:46 2016 +0300 @@ -95,6 +95,8 @@ static const njs_keyword_t njs_keywords { nxt_string("parseFloat"),NJS_TOKEN_PARSE_FLOAT, 0 }, { nxt_string("encodeURI"), NJS_TOKEN_ENCODE_URI, 0 }, { nxt_string("encodeURIComponent"), NJS_TOKEN_ENCODE_URI_COMPONENT, 0 }, +{ nxt_string("decodeURI"), NJS_TOKEN_DECODE_URI, 0 }, +{ nxt_string("decodeURIComponent"), NJS_TOKEN_DECODE_URI_COMPONENT, 0 }, /* Reserved words. */ diff -r d63ecb57f164 -r 323f00dc9879 njs/njs_parser.c --- a/njs/njs_parser.c Tue Aug 30 12:02:31 2016 +0300 +++ b/njs/njs_parser.c Tue Aug 30 12:05:46 2016 +0300 @@ -1673,6 +1673,8 @@ njs_parser_terminal(njs_vm_t *vm, njs_pa case NJS_TOKEN_PARSE_FLOAT: case NJS_TOKEN_ENCODE_URI: case NJS_TOKEN_ENCODE_URI_COMPONENT: +case NJS_TOKEN_DECODE_URI: +case NJS_TOKEN_DECODE_URI_COMPONENT: return njs_parser_builtin_function(vm, parser, node); default: diff -r d63ecb57f164 -r 323f00dc9879 njs/njs_parser.h --- a/njs/njs_parser.h Tue Aug 30 12:02:31 2016 +0300 +++ b/njs/njs_parser.h Tue Aug 30 12:05:46 2016 +0300 @@ -183,14 +183,16 @@ typedef enum { NJS_TOKEN_PARSE_FLOAT, NJS_TOKEN_ENCODE_URI, NJS_TOKEN_ENCODE_URI_COMPONENT, +NJS_TOKEN_DECODE_URI, +NJS_TOKEN_DECODE_URI_COMPONENT, NJS_TOKEN_RESERVED, } njs_token_t; typedef struct { -njs_token_t token:8; -njs_token_t prev_token:8; +njs_token_t token:16; +njs_token_t prev_token:16; uint8_t property; /* 1 bit */ uint32_tkey_hash; @@ -222,8 +224,8 @@ typedef enum { typedef struct njs_parser_node_snjs_parser_node_t; struct njs_parser_node_s { -njs_token_t token:8; -njs_variable_node_state_t state:8;/* 2 bits */ +njs_token_t token:16; +njs_variable_node_state_t state:2;/* 2 bits */ uint8_t ctor:1; /* 1 bit */ uint8_t temporary; /* 1 bit */ uint32_ttoken_line; diff -r d63ecb57f164 -r 323f00dc9879 njs/njs_string.c --- a/njs/njs_string.c Tue Aug 30 12:02:31 2016 +0300 +++ b/njs/njs_string.c Tue Aug 30 12:05:46 2016 +0300 @@ -47,6 +47,8 @@ static njs_
[njs] Added tag 0.1.1 for changeset 0039a747d25a
details: http://hg.nginx.org/njs/rev/7cce82b6b40b branches: changeset: 159:7cce82b6b40b user: Igor Sysoev <i...@sysoev.ru> date: Tue Aug 16 19:13:41 2016 +0300 description: Added tag 0.1.1 for changeset 0039a747d25a diffstat: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (6 lines): diff -r 0039a747d25a -r 7cce82b6b40b .hgtags --- a/.hgtags Tue Aug 16 19:09:03 2016 +0300 +++ b/.hgtags Tue Aug 16 19:13:41 2016 +0300 @@ -1,1 +1,2 @@ cdb8d20935ee96f1fa0c99d994d4b11cefcbc119 0.1.0 +0039a747d25a3e08792c23c43b75768896724031 0.1.1 ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] A return statement has been disabled outside of function.
details: http://hg.nginx.org/njs/rev/e6e192a55774 branches: changeset: 155:e6e192a55774 user: Igor Sysoev <i...@sysoev.ru> date: Mon Aug 15 11:33:37 2016 +0300 description: A return statement has been disabled outside of function. diffstat: njs/njs_parser.c | 7 +++ njs/test/njs_unit_test.c | 3 +++ 2 files changed, 10 insertions(+), 0 deletions(-) diffs (30 lines): diff -r 0c9a771b7664 -r e6e192a55774 njs/njs_parser.c --- a/njs/njs_parser.c Thu Aug 11 13:57:36 2016 +0300 +++ b/njs/njs_parser.c Mon Aug 15 11:33:37 2016 +0300 @@ -584,6 +584,13 @@ njs_parser_return_statement(njs_vm_t *vm njs_token_ttoken; njs_parser_node_t *node; +if (parser->scope == NJS_SCOPE_GLOBAL) { +nxt_alert(>trace, NXT_LEVEL_ERROR, + "SyntaxError: Illegal return statement"); + +return NXT_ERROR; +} + node = njs_parser_node_alloc(vm); if (nxt_slow_path(node == NULL)) { return NJS_TOKEN_ERROR; diff -r 0c9a771b7664 -r e6e192a55774 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Aug 11 13:57:36 2016 +0300 +++ b/njs/test/njs_unit_test.c Mon Aug 15 11:33:37 2016 +0300 @@ -3290,6 +3290,9 @@ static njs_unit_test_t njs_test[] = /* Functions. */ +{ nxt_string("return"), + nxt_string("SyntaxError: Illegal return statement in 1") }, + { nxt_string("function () { } f()"), nxt_string("SyntaxError: Unexpected token \"(\" in 1") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Style fixes.
details: http://hg.nginx.org/njs/rev/dcd8a105b5e7 branches: changeset: 156:dcd8a105b5e7 user: Igor Sysoev <i...@sysoev.ru> date: Tue Aug 16 18:09:35 2016 +0300 description: Style fixes. diffstat: njs/njs_array.c | 84 +++ njs/njs_string.c | 20 ++ njs/njs_vm.h | 2 +- nxt/nxt_djb_hash.h | 2 +- nxt/nxt_lvlhsh.c | 46 +- nxt/nxt_lvlhsh.h | 36 ++-- nxt/nxt_mem_cache_pool.c | 6 +- nxt/nxt_rbtree.c | 2 +- nxt/nxt_rbtree.h | 4 +- 9 files changed, 102 insertions(+), 100 deletions(-) diffs (606 lines): diff -r e6e192a55774 -r dcd8a105b5e7 njs/njs_array.c --- a/njs/njs_array.c Mon Aug 15 11:33:37 2016 +0300 +++ b/njs/njs_array.c Tue Aug 16 18:09:35 2016 +0300 @@ -79,28 +79,26 @@ typedef struct { } njs_array_sort_t; -static njs_ret_t -njs_array_prototype_to_string_continuation(njs_vm_t *vm, njs_value_t *args, -nxt_uint_t nargs, njs_index_t retval); +static njs_ret_t njs_array_prototype_to_string_continuation(njs_vm_t *vm, +njs_value_t *args, nxt_uint_t nargs, njs_index_t retval); static njs_ret_t njs_array_prototype_join_continuation(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); -static nxt_noinline njs_value_t *njs_array_copy(njs_value_t *dst, -njs_value_t *src); +static njs_value_t *njs_array_copy(njs_value_t *dst, njs_value_t *src); static njs_ret_t njs_array_index_of(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, nxt_bool_t first); -static nxt_noinline njs_ret_t njs_array_prototype_for_each_cont(njs_vm_t *vm, -njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); -static nxt_noinline njs_ret_t njs_array_prototype_some_cont(njs_vm_t *vm, -njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); -static nxt_noinline njs_ret_t njs_array_prototype_every_cont(njs_vm_t *vm, +static njs_ret_t njs_array_prototype_for_each_continuation(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); -static njs_ret_t njs_array_prototype_filter_cont(njs_vm_t *vm, +static njs_ret_t njs_array_prototype_some_continuation(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); -static njs_ret_t njs_array_prototype_map_cont(njs_vm_t *vm, njs_value_t *args, -nxt_uint_t nargs, njs_index_t unused); -static njs_ret_t njs_array_prototype_reduce_cont(njs_vm_t *vm, +static njs_ret_t njs_array_prototype_every_continuation(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); -static njs_ret_t njs_array_prototype_reduce_right_cont(njs_vm_t *vm, +static njs_ret_t njs_array_prototype_filter_continuation(njs_vm_t *vm, +njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +static njs_ret_t njs_array_prototype_map_continuation(njs_vm_t *vm, +njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +static njs_ret_t njs_array_prototype_reduce_continuation(njs_vm_t *vm, +njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +static njs_ret_t njs_array_prototype_reduce_right_continuation(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); static nxt_noinline njs_ret_t njs_array_iterator_args(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs); @@ -109,8 +107,8 @@ static nxt_noinline uint32_t njs_array_i static nxt_noinline njs_ret_t njs_array_iterator_apply(njs_vm_t *vm, njs_array_iter_t *iter, njs_value_t *args, nxt_uint_t nargs); static uint32_t njs_array_reduce_right_next(njs_array_t *array, int32_t n); -static njs_ret_t njs_array_prototype_sort_cont(njs_vm_t *vm, njs_value_t *args, -nxt_uint_t nargs, njs_index_t unused); +static njs_ret_t njs_array_prototype_sort_continuation(njs_vm_t *vm, +njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); nxt_noinline njs_array_t * @@ -932,7 +930,7 @@ njs_array_prototype_concat(njs_vm_t *vm, } -static nxt_noinline njs_value_t * +static njs_value_t * njs_array_copy(njs_value_t *dst, njs_value_t *src) { nxt_uint_t n; @@ -1031,14 +1029,14 @@ njs_array_prototype_for_each(njs_vm_t *v } iter = njs_continuation(vm->frame); -iter->u.cont.function = njs_array_prototype_for_each_cont; +iter->u.cont.function = njs_array_prototype_for_each_continuation; -return njs_array_prototype_for_each_cont(vm, args, nargs, unused); +return njs_array_prototype_for_each_continuation(vm, args, nargs, unused); } static njs_ret_t -njs_array_prototype_for_each_cont(njs_vm_t *vm, njs_value_t *args, +njs_array_prototype_for_each_continuation(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { njs_array_iter_t *iter; @@ -1067,15 +1065,15 @@ njs_array_prototype_some(njs_vm_t *vm, n } iter = njs_continuation(vm->frame); -iter->u.cont.function = njs_array_prototype_some_cont; +
[njs] String.match() fixes.
details: http://hg.nginx.org/njs/rev/5d9e4adf25c2 branches: changeset: 157:5d9e4adf25c2 user: Igor Sysoev <i...@sysoev.ru> date: Tue Aug 16 18:58:30 2016 +0300 description: String.match() fixes. diffstat: njs/njs_regexp.c | 69 +-- njs/njs_regexp.h |2 + njs/njs_string.c | 133 +- njs/njs_vm.h |1 + njs/test/njs_unit_test.c |9 +++ 5 files changed, 112 insertions(+), 102 deletions(-) diffs (331 lines): diff -r dcd8a105b5e7 -r 5d9e4adf25c2 njs/njs_regexp.c --- a/njs/njs_regexp.c Tue Aug 16 18:09:35 2016 +0300 +++ b/njs/njs_regexp.c Tue Aug 16 18:58:30 2016 +0300 @@ -65,7 +65,8 @@ njs_regexp_init(njs_vm_t *vm) vm->regex_context->trace = >trace; -return NXT_OK; +return njs_regexp_create(vm, >empty_regexp, (u_char *) "(?:)", + sizeof("(?:)") - 1, 0); } @@ -87,20 +88,22 @@ njs_ret_t njs_regexp_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { -size_tlength; -njs_regexp_t *regexp; -njs_string_prop_t string; -njs_regexp_flags_tflags; -njs_regexp_pattern_t *pattern; +njs_string_prop_t string; +njs_regexp_flags_t flags; flags = 0; switch (nargs) { +case 1: +string.start = NULL; +string.size = 0; +break; + default: -length = njs_string_prop(, [2]); +(void) njs_string_prop(, [2]); -flags = njs_regexp_flags(, string.start + length, 1); +flags = njs_regexp_flags(, string.start + string.size, 1); if (nxt_slow_path(flags < 0)) { return NXT_ERROR; } @@ -108,36 +111,42 @@ njs_regexp_constructor(njs_vm_t *vm, njs /* Fall through. */ case 2: -string.length = njs_string_prop(, [1]); - -if (string.length != 0) { -break; -} - -/* Fall through. */ - -case 1: -string.start = (u_char *) "(?:)"; -string.length = sizeof("(?:)") - 1; +(void) njs_string_prop(, [1]); break; } -pattern = njs_regexp_pattern_create(vm, string.start, string.length, flags); - -if (nxt_fast_path(pattern != NULL)) { - -regexp = njs_regexp_alloc(vm, pattern); +return njs_regexp_create(vm, >retval, string.start, string.size, flags); +} -if (nxt_fast_path(regexp != NULL)) { -vm->retval.data.u.regexp = regexp; -vm->retval.type = NJS_REGEXP; -vm->retval.data.truth = 1; -return NXT_OK; +nxt_int_t +njs_regexp_create(njs_vm_t *vm, njs_value_t *value, u_char *start, +size_t length, njs_regexp_flags_t flags) +{ +njs_regexp_t *regexp; +njs_regexp_pattern_t *pattern; + +if (length != 0) { +pattern = njs_regexp_pattern_create(vm, start, length, flags); + +if (nxt_fast_path(pattern != NULL)) { +regexp = njs_regexp_alloc(vm, pattern); + +if (nxt_fast_path(regexp != NULL)) { +value->data.u.regexp = regexp; +value->type = NJS_REGEXP; +value->data.truth = 1; + +return NXT_OK; +} } + +return NXT_ERROR; } -return NXT_ERROR; +*value = vm->empty_regexp; + +return NXT_OK; } diff -r dcd8a105b5e7 -r 5d9e4adf25c2 njs/njs_regexp.h --- a/njs/njs_regexp.h Tue Aug 16 18:09:35 2016 +0300 +++ b/njs/njs_regexp.h Tue Aug 16 18:58:30 2016 +0300 @@ -35,6 +35,8 @@ struct njs_regexp_s { njs_ret_t njs_regexp_init(njs_vm_t *vm); njs_ret_t njs_regexp_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +nxt_int_t njs_regexp_create(njs_vm_t *vm, njs_value_t *value, u_char *start, +size_t length, njs_regexp_flags_t flags); njs_token_t njs_regexp_literal(njs_vm_t *vm, njs_parser_t *parser, njs_value_t *value); njs_regexp_pattern_t *njs_regexp_pattern_create(njs_vm_t *vm, diff -r dcd8a105b5e7 -r 5d9e4adf25c2 njs/njs_string.c --- a/njs/njs_string.c Tue Aug 16 18:09:35 2016 +0300 +++ b/njs/njs_string.c Tue Aug 16 18:58:30 2016 +0300 @@ -41,6 +41,8 @@ static njs_ret_t njs_string_from_char_co njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); static nxt_noinline ssize_t njs_string_index_of(njs_vm_t *vm, njs_value_t *src, njs_value_t *search_string, size_t index); +static njs_ret_t njs_string_match_multiple(njs_vm_t *vm, njs_value_t *args, +njs_regexp_pattern_t *pattern); static njs_ret_t njs_string_split_part_add(njs_vm_t *vm, njs_array_t *array, u_char *start, size_t size, nxt_uint_t utf8); @@ -1429,26 +1431,27 @@ njs_string_prototype_search(njs_vm_t *vm switch (args[1].type) { -case NJS_VOID: -goto done; +case NJS_REGEXP: +pat
[njs] Array iterator functions optimizations.
details: http://hg.nginx.org/njs/rev/0c9a771b7664 branches: changeset: 154:0c9a771b7664 user: Igor Sysoev <i...@sysoev.ru> date: Thu Aug 11 13:57:36 2016 +0300 description: Array iterator functions optimizations. diffstat: njs/njs_array.c | 126 ++- 1 files changed, 69 insertions(+), 57 deletions(-) diffs (262 lines): diff -r 87df6b787943 -r 0c9a771b7664 njs/njs_array.c --- a/njs/njs_array.c Thu Aug 11 13:21:46 2016 +0300 +++ b/njs/njs_array.c Thu Aug 11 13:57:36 2016 +0300 @@ -43,12 +43,23 @@ typedef struct { */ njs_value_t retval; +uint32_tnext_index; +uint32_tlength; +} njs_array_iter_t; + + +typedef struct { +njs_array_iter_titer; njs_value_t value; njs_array_t *array; -uint32_tnext_index; -uint32_tlength; +} njs_array_filter_t; + + +typedef struct { +njs_array_iter_titer; +njs_array_t *array; uint32_tindex; -} njs_array_iter_t; +} njs_array_map_t; typedef struct { @@ -1137,20 +1148,20 @@ static njs_ret_t njs_array_prototype_filter(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { -nxt_int_t ret; -njs_array_iter_t *iter; +nxt_int_t ret; +njs_array_filter_t *filter; ret = njs_array_iterator_args(vm, args, nargs); if (nxt_slow_path(ret != NXT_OK)) { return ret; } -iter = njs_continuation(vm->frame); -iter->u.cont.function = njs_array_prototype_filter_cont; -iter->retval.data.truth = 0; +filter = njs_continuation(vm->frame); +filter->iter.u.cont.function = njs_array_prototype_filter_cont; +filter->iter.retval.data.truth = 0; -iter->array = njs_array_alloc(vm, 0, NJS_ARRAY_SPARE); -if (nxt_slow_path(iter->array == NULL)) { +filter->array = njs_array_alloc(vm, 0, NJS_ARRAY_SPARE); +if (nxt_slow_path(filter->array == NULL)) { return NXT_ERROR; } @@ -1162,27 +1173,33 @@ static njs_ret_t njs_array_prototype_filter_cont(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { -nxt_int_t ret; -njs_array_iter_t *iter; +nxt_int_t ret; +njs_array_t *array; +njs_array_filter_t *filter; -iter = njs_continuation(vm->frame); +filter = njs_continuation(vm->frame); -if (njs_is_true(>retval)) { -ret = njs_array_add(vm, iter->array, >value); +if (njs_is_true(>iter.retval)) { +ret = njs_array_add(vm, filter->array, >value); if (nxt_slow_path(ret != NXT_OK)) { return ret; } } -if (iter->next_index >= args[0].data.u.array->length) { -vm->retval.data.u.array = iter->array; +array = args[0].data.u.array; + +if (filter->iter.next_index >= array->length) { +vm->retval.data.u.array = filter->array; vm->retval.type = NJS_ARRAY; vm->retval.data.truth = 1; return NXT_OK; } -return njs_array_iterator_apply(vm, iter, args, nargs); +/* GC: filter->value */ +filter->value = array->start[filter->iter.next_index]; + +return njs_array_iterator_apply(vm, >iter, args, nargs); } @@ -1190,29 +1207,29 @@ static njs_ret_t njs_array_prototype_map(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { -size_tsize; -nxt_int_t ret; -njs_value_t *value; -njs_array_t *array; -njs_array_iter_t *iter; +size_t size; +nxt_int_tret; +njs_value_t *value; +njs_array_t *array; +njs_array_map_t *map; ret = njs_array_iterator_args(vm, args, nargs); if (nxt_slow_path(ret != NXT_OK)) { return ret; } -iter = njs_continuation(vm->frame); -iter->u.cont.function = njs_array_prototype_map_cont; -njs_set_invalid(>retval); +map = njs_continuation(vm->frame); +map->iter.u.cont.function = njs_array_prototype_map_cont; +njs_set_invalid(>iter.retval); array = args[0].data.u.array; -iter->array = njs_array_alloc(vm, array->length, 0); -if (nxt_slow_path(iter->array == NULL)) { +map->array = njs_array_alloc(vm, array->length, 0); +if (nxt_slow_path(map->array == NULL)) { return NXT_ERROR; } -value = iter->array->start; +value = map->array->start; size = array->length; while (size != 0) { @@ -1229,23 +1246,25 @@ static njs_ret_t njs_array_prototype_map_cont(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { -njs_array_iter_t *iter; +njs_array_map_t *map; -iter = njs_continuation(vm-&
[njs] Array.join() now treats "null" and "undefined" as empty va...
details: http://hg.nginx.org/njs/rev/87df6b787943 branches: changeset: 153:87df6b787943 user: Igor Sysoev <i...@sysoev.ru> date: Thu Aug 11 13:21:46 2016 +0300 description: Array.join() now treats "null" and "undefined" as empty values. diffstat: njs/njs_array.c | 14 ++ njs/test/njs_unit_test.c | 11 +++ 2 files changed, 21 insertions(+), 4 deletions(-) diffs (66 lines): diff -r 18ac628bcb6c -r 87df6b787943 njs/njs_array.c --- a/njs/njs_array.c Thu Aug 11 10:58:29 2016 +0300 +++ b/njs/njs_array.c Thu Aug 11 13:21:46 2016 +0300 @@ -734,7 +734,10 @@ njs_array_prototype_join(njs_vm_t *vm, n for (i = 0; i < array->length; i++) { value = >start[i]; -if (njs_is_valid(value) && !njs_is_string(value)) { +if (!njs_is_string(value) +&& njs_is_valid(value) +&& !njs_is_null_or_void(value)) +{ max++; } } @@ -755,7 +758,10 @@ njs_array_prototype_join(njs_vm_t *vm, n for (i = 0; i < array->length; i++) { value = >start[i]; -if (njs_is_valid(value) && !njs_is_string(value)) { +if (!njs_is_string(value) +&& njs_is_valid(value) +&& !njs_is_null_or_void(value)) +{ values[n++] = *value; if (n >= max) { @@ -802,7 +808,7 @@ njs_array_prototype_join_continuation(nj for (i = 0; i < array->length; i++) { value = >start[i]; -if (njs_is_valid(value)) { +if (njs_is_valid(value) && !njs_is_null_or_void(value)) { if (!njs_is_string(value)) { value = [n++]; @@ -849,7 +855,7 @@ njs_array_prototype_join_continuation(nj for (i = 0; i < array->length; i++) { value = >start[i]; -if (njs_is_valid(value)) { +if (njs_is_valid(value) && !njs_is_null_or_void(value)) { if (!njs_is_string(value)) { value = [n++]; } diff -r 18ac628bcb6c -r 87df6b787943 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Aug 11 10:58:29 2016 +0300 +++ b/njs/test/njs_unit_test.c Thu Aug 11 13:21:46 2016 +0300 @@ -2124,6 +2124,17 @@ static njs_unit_test_t njs_test[] = { nxt_string("a = []; a[5] = 5; a.join()"), nxt_string(",5") }, +{ nxt_string("var a = [,null,undefined,false,true,0,1]; a.join()"), + nxt_string(",,,false,true,0,1") }, + +{ nxt_string("var o = { toString: function() { return null } };" + "[o].join()"), + nxt_string("null") }, + +{ nxt_string("var o = { toString: function() { return undefined } };" + "[o].join()"), + nxt_string("undefined") }, + { nxt_string("a = []; a[5] = 5; a"), nxt_string(",5") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Array.splice() function.
details: http://hg.nginx.org/njs/rev/3dc4385c805c branches: changeset: 151:3dc4385c805c user: Igor Sysoev <i...@sysoev.ru> date: Wed Aug 10 18:03:54 2016 +0300 description: Array.splice() function. diffstat: njs/njs_array.c | 88 njs/test/njs_unit_test.c | 15 2 files changed, 103 insertions(+), 0 deletions(-) diffs (130 lines): diff -r 050db82b0d46 -r 3dc4385c805c njs/njs_array.c --- a/njs/njs_array.c Wed Aug 10 15:52:25 2016 +0300 +++ b/njs/njs_array.c Wed Aug 10 18:03:54 2016 +0300 @@ -530,6 +530,87 @@ njs_array_prototype_shift(njs_vm_t *vm, static njs_ret_t +njs_array_prototype_splice(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, +njs_index_t unused) +{ +njs_ret_tret; +nxt_int_titems, delta; +nxt_uint_t i, n, start, delete, length; +njs_array_t *array, *deleted; + +array = NULL; +start = 0; +delete = 0; + +if (njs_is_array([0])) { +array = args[0].data.u.array; + +if (nargs > 1) { +start = args[1].data.u.number; + +if (nargs > 2) { +delete = args[2].data.u.number; + +} else { +delete = array->length - start; +} +} +} + +deleted = njs_array_alloc(vm, delete, 0); +if (nxt_slow_path(deleted == NULL)) { +return NXT_ERROR; +} + +if (array != NULL && (delete != 0 || nargs > 3)) { +length = array->length; + +/* Move deleted items to a new array to return. */ +for (i = 0, n = start; i < delete && n < length; i++, n++) { +/* No retention required. */ +deleted->start[i] = array->start[n]; +} + +items = nargs - 3; +items = items >= 0 ? items : 0; +delta = items - delete; + +if (delta != 0) { +/* + * Relocate the rest of items. + * Index of the first item is in "n". + */ +if (delta > 0) { +ret = njs_array_realloc(vm, array, 0, array->size + delta); +if (nxt_slow_path(ret != NXT_OK)) { +return ret; +} +} + +memmove(>start[start + items], >start[n], +(array->length - n) * sizeof(njs_value_t)); + +array->length += delta; +} + +/* Copy new items. */ +n = start; + +for (i = 3; i < nargs; i++) { +/* GC: njs_retain([i]); */ +array->start[n++] = args[i]; +} +} + +vm->retval.data.u.array = deleted; +vm->retval.type = NJS_ARRAY; +vm->retval.data.truth = 1; + +return NXT_OK; +} + + +static njs_ret_t njs_array_prototype_reverse(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { @@ -1437,6 +1518,13 @@ static const njs_object_prop_t njs_arra { .type = NJS_METHOD, +.name = njs_string("splice"), +.value = njs_native_function(njs_array_prototype_splice, 0, +NJS_OBJECT_ARG, NJS_INTEGER_ARG, NJS_INTEGER_ARG), +}, + +{ +.type = NJS_METHOD, .name = njs_string("reverse"), .value = njs_native_function(njs_array_prototype_reverse, 0, NJS_OBJECT_ARG), diff -r 050db82b0d46 -r 3dc4385c805c njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Wed Aug 10 15:52:25 2016 +0300 +++ b/njs/test/njs_unit_test.c Wed Aug 10 18:03:54 2016 +0300 @@ -2256,6 +2256,21 @@ static njs_unit_test_t njs_test[] = "len +' '+ a +' '+ a.shift()"), nxt_string("5 3,4,5,1,2 3") }, +{ nxt_string("var a = []; a.splice()"), + nxt_string("") }, + +{ nxt_string("var a = [0,1,2,3,4,5,6,7];" + "a.splice(3).join(':') + '|' + a"), + nxt_string("3:4:5:6:7|0,1,2") }, + +{ nxt_string("var a = [0,1,2,3,4,5,6,7];" + "a.splice(3, 2).join(':') + '|' + a"), + nxt_string("3:4|0,1,2,5,6,7") }, + +{ nxt_string("var a = [0,1,2,3,4,5,6,7];" + "a.splice(3, 2, 8, 9, 10, 11 ).join(':') + '|' + a"), + nxt_string("3:4|0,1,2,8,9,10,11,5,6,7") }, + { nxt_string("var a = []; a.reverse()"), nxt_string("") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Array.map() function.
details: http://hg.nginx.org/njs/rev/43b3a67ee1f1 branches: changeset: 146:43b3a67ee1f1 user: Igor Sysoev <i...@sysoev.ru> date: Tue Aug 09 14:10:31 2016 +0300 description: Array.map() function. diffstat: njs/njs_array.c | 74 njs/test/njs_unit_test.c | 20 2 files changed, 94 insertions(+), 0 deletions(-) diffs (142 lines): diff -r 6e212d387b88 -r 43b3a67ee1f1 njs/njs_array.c --- a/njs/njs_array.c Tue Aug 09 14:10:29 2016 +0300 +++ b/njs/njs_array.c Tue Aug 09 14:10:31 2016 +0300 @@ -47,6 +47,7 @@ typedef struct { njs_array_t *array; uint32_tnext_index; uint32_tlength; +uint32_tindex; } njs_array_iter_t; @@ -65,6 +66,8 @@ static nxt_noinline njs_ret_t njs_array_ njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); static njs_ret_t njs_array_prototype_filter_cont(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +static njs_ret_t njs_array_prototype_map_cont(njs_vm_t *vm, njs_value_t *args, +nxt_uint_t nargs, njs_index_t unused); static nxt_noinline njs_ret_t njs_array_iterator_args(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs); static nxt_noinline uint32_t njs_array_iterator_next(njs_array_t *array, @@ -980,6 +983,69 @@ njs_array_prototype_filter_cont(njs_vm_t } +static njs_ret_t +njs_array_prototype_map(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, +njs_index_t unused) +{ +size_tsize; +nxt_int_t ret; +njs_value_t *value; +njs_array_t *array; +njs_array_iter_t *iter; + +ret = njs_array_iterator_args(vm, args, nargs); +if (nxt_slow_path(ret != NXT_OK)) { +return ret; +} + +iter = njs_continuation(vm->frame); +iter->u.cont.function = njs_array_prototype_map_cont; +njs_set_invalid(>retval); + +array = args[0].data.u.array; + +iter->array = njs_array_alloc(vm, array->length, 0); +if (nxt_slow_path(iter->array == NULL)) { +return NXT_ERROR; +} + +value = iter->array->start; +size = array->length; + +while (size != 0) { +njs_set_invalid(value); +value++; +size--; +} + +return njs_array_prototype_map_cont(vm, args, nargs, unused); +} + + +static njs_ret_t +njs_array_prototype_map_cont(njs_vm_t *vm, njs_value_t *args, +nxt_uint_t nargs, njs_index_t unused) +{ +njs_array_iter_t *iter; + +iter = njs_continuation(vm->frame); + +if (njs_is_valid(>retval)) { +iter->array->start[iter->index] = iter->retval; +} + +if (iter->next_index >= args[0].data.u.array->length) { +vm->retval.data.u.array = iter->array; +vm->retval.type = NJS_ARRAY; +vm->retval.data.truth = 1; + +return NXT_OK; +} + +return njs_array_iterator_apply(vm, iter, args, nargs); +} + + static nxt_noinline njs_ret_t njs_array_iterator_args(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs) { @@ -1042,6 +1108,7 @@ njs_array_iterator_apply(njs_vm_t *vm, n */ array = args[0].data.u.array; n = iter->next_index; +iter->index = n; iter->value = array->start[n]; arguments[1] = array->start[n]; @@ -1150,6 +1217,13 @@ static const njs_object_prop_t njs_arra .value = njs_native_function(njs_array_prototype_filter, njs_continuation_size(njs_array_iter_t), 0), }, + +{ +.type = NJS_METHOD, +.name = njs_string("map"), +.value = njs_native_function(njs_array_prototype_map, + njs_continuation_size(njs_array_iter_t), 0), +}, }; diff -r 6e212d387b88 -r 43b3a67ee1f1 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Tue Aug 09 14:10:29 2016 +0300 +++ b/njs/test/njs_unit_test.c Tue Aug 09 14:10:31 2016 +0300 @@ -2365,6 +2365,26 @@ static njs_unit_test_t njs_test[] = "a.filter(function(v, i, a) { a[i+1] = v+10; return true })"), nxt_string("1,11,21,31,41,51,61") }, +{ nxt_string("var a = [];" + "a.map(function(v, i, a) { return v + 1 })"), + nxt_string("") }, + +{ nxt_string("var a = [,,,];" + "a.map(function(v, i, a) { return v + 1 })"), + nxt_string(",,") }, + +{ nxt_string("var a = [,,,1];" + "a.map(function(v, i, a) { return v + 1 })"), + nxt_string(",,,2") }, + +{ nxt_string("var a = [1,2,3];" + "a.map(function(v, i, a) { return v + 1 })"), + nxt_string("2,3,4") }, + +{ nxt_string("var a = [1,2,3,4,5,6];" + "a.map(function(v, i, a) { a.pop(); return v + 1 })"), + nxt_string("2,3,4,,,") }, + /* Strings. */ { nxt_string("var a = '0123456789' + '012345'" ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Array.reduce() function.
details: http://hg.nginx.org/njs/rev/5bd9c6bea8a6 branches: changeset: 147:5bd9c6bea8a6 user: Igor Sysoev <i...@sysoev.ru> date: Tue Aug 09 14:10:32 2016 +0300 description: Array.reduce() function. diffstat: njs/njs_array.c | 90 njs/test/njs_unit_test.c | 36 +++ 2 files changed, 126 insertions(+), 0 deletions(-) diffs (160 lines): diff -r 43b3a67ee1f1 -r 5bd9c6bea8a6 njs/njs_array.c --- a/njs/njs_array.c Tue Aug 09 14:10:31 2016 +0300 +++ b/njs/njs_array.c Tue Aug 09 14:10:32 2016 +0300 @@ -68,6 +68,8 @@ static njs_ret_t njs_array_prototype_fil njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); static njs_ret_t njs_array_prototype_map_cont(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +static njs_ret_t njs_array_prototype_reduce_cont(njs_vm_t *vm, +njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); static nxt_noinline njs_ret_t njs_array_iterator_args(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs); static nxt_noinline uint32_t njs_array_iterator_next(njs_array_t *array, @@ -1046,6 +1048,87 @@ njs_array_prototype_map_cont(njs_vm_t *v } +static njs_ret_t +njs_array_prototype_reduce(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, +njs_index_t unused) +{ +uint32_t n; +nxt_int_t ret; +njs_array_t *array; +njs_array_iter_t *iter; + +ret = njs_array_iterator_args(vm, args, nargs); +if (nxt_slow_path(ret != NXT_OK)) { +return ret; +} + +iter = njs_continuation(vm->frame); +iter->u.cont.function = njs_array_prototype_reduce_cont; + +if (nargs > 2) { +iter->retval = args[2]; + +} else { +array = args[0].data.u.array; +n = iter->next_index; + +if (n >= array->length) { +vm->exception = _exception_type_error; +return NXT_ERROR; +} + +iter->retval = array->start[n]; + +iter->next_index = njs_array_iterator_next(array, n + 1, array->length); +} + +return njs_array_prototype_reduce_cont(vm, args, nargs, unused); +} + + +static njs_ret_t +njs_array_prototype_reduce_cont(njs_vm_t *vm, njs_value_t *args, +nxt_uint_t nargs, njs_index_t unused) +{ +nxt_int_t n; +njs_array_t *array; +njs_value_t arguments[5]; +njs_array_iter_t *iter; + +iter = njs_continuation(vm->frame); + +if (iter->next_index >= args[0].data.u.array->length) { +vm->retval = iter->retval; +return NXT_OK; +} + +arguments[0] = njs_value_void; + +/* GC: array elt, array */ +arguments[1] = iter->retval; + +/* + * All array iterators functions call njs_array_iterator_args() + * function which set a correct iter->next_index value. A large + * value of iter->next_index must be checked before calling + * njs_array_iterator_apply(). + */ +array = args[0].data.u.array; +n = iter->next_index; + +arguments[2] = array->start[n]; + +njs_number_set([3], n); + +arguments[4] = args[0]; + +iter->next_index = njs_array_iterator_next(array, n + 1, iter->length); + +return njs_function_apply(vm, args[1].data.u.function, arguments, 5, + (njs_index_t) >retval); +} + + static nxt_noinline njs_ret_t njs_array_iterator_args(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs) { @@ -1224,6 +1307,13 @@ static const njs_object_prop_t njs_arra .value = njs_native_function(njs_array_prototype_map, njs_continuation_size(njs_array_iter_t), 0), }, + +{ +.type = NJS_METHOD, +.name = njs_string("reduce"), +.value = njs_native_function(njs_array_prototype_reduce, + njs_continuation_size(njs_array_iter_t), 0), +}, }; diff -r 43b3a67ee1f1 -r 5bd9c6bea8a6 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Tue Aug 09 14:10:31 2016 +0300 +++ b/njs/test/njs_unit_test.c Tue Aug 09 14:10:32 2016 +0300 @@ -2385,6 +2385,42 @@ static njs_unit_test_t njs_test[] = "a.map(function(v, i, a) { a.pop(); return v + 1 })"), nxt_string("2,3,4,,,") }, +{ nxt_string("var a = [];" + "a.reduce(function(p, v, i, a) { return p + v })"), + nxt_string("TypeError") }, + +{ nxt_string("var a = [];" + "a.reduce(function(p, v, i, a) { return p + v }, 10)"), + nxt_string("10") }, + +{ nxt_string("var a = [,,];" + "a.reduce(function(p, v, i, a) { return p + v })"), + nxt_string("TypeError") }, + +{ nxt_string("var a = [,,];" + "a.reduce(function(p, v, i, a) { return p + v }, 10)"), +
[njs] Array.filter() function.
details: http://hg.nginx.org/njs/rev/6e212d387b88 branches: changeset: 145:6e212d387b88 user: Igor Sysoev <i...@sysoev.ru> date: Tue Aug 09 14:10:29 2016 +0300 description: Array.filter() function. diffstat: njs/njs_array.c | 84 njs/test/njs_unit_test.c | 32 ++ 2 files changed, 116 insertions(+), 0 deletions(-) diffs (171 lines): diff -r 2f40b153a7c1 -r 6e212d387b88 njs/njs_array.c --- a/njs/njs_array.c Tue Aug 09 14:10:21 2016 +0300 +++ b/njs/njs_array.c Tue Aug 09 14:10:29 2016 +0300 @@ -43,6 +43,8 @@ typedef struct { */ njs_value_t retval; +njs_value_t value; +njs_array_t *array; uint32_tnext_index; uint32_tlength; } njs_array_iter_t; @@ -61,6 +63,8 @@ static nxt_noinline njs_ret_t njs_array_ njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); static nxt_noinline njs_ret_t njs_array_prototype_every_cont(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +static njs_ret_t njs_array_prototype_filter_cont(njs_vm_t *vm, +njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); static nxt_noinline njs_ret_t njs_array_iterator_args(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs); static nxt_noinline uint32_t njs_array_iterator_next(njs_array_t *array, @@ -100,6 +104,25 @@ njs_array_alloc(njs_vm_t *vm, uint32_t l } +static njs_ret_t +njs_array_add(njs_vm_t *vm, njs_array_t *array, njs_value_t *value) +{ +njs_ret_t ret; + +if (array->size == array->length) { +ret = njs_array_realloc(vm, array, 0, array->size + 1); +if (nxt_slow_path(ret != NXT_OK)) { +return ret; +} +} + +/* GC: retain value. */ +array->start[array->length++] = *value; + +return NXT_OK; +} + + njs_ret_t njs_array_string_add(njs_vm_t *vm, njs_array_t *array, u_char *start, size_t size, size_t length) @@ -904,6 +927,59 @@ njs_array_prototype_every_cont(njs_vm_t } +static njs_ret_t +njs_array_prototype_filter(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, +njs_index_t unused) +{ +nxt_int_t ret; +njs_array_iter_t *iter; + +ret = njs_array_iterator_args(vm, args, nargs); +if (nxt_slow_path(ret != NXT_OK)) { +return ret; +} + +iter = njs_continuation(vm->frame); +iter->u.cont.function = njs_array_prototype_filter_cont; +iter->retval.data.truth = 0; + +iter->array = njs_array_alloc(vm, 0, NJS_ARRAY_SPARE); +if (nxt_slow_path(iter->array == NULL)) { +return NXT_ERROR; +} + +return njs_array_prototype_filter_cont(vm, args, nargs, unused); +} + + +static njs_ret_t +njs_array_prototype_filter_cont(njs_vm_t *vm, njs_value_t *args, +nxt_uint_t nargs, njs_index_t unused) +{ +nxt_int_t ret; +njs_array_iter_t *iter; + +iter = njs_continuation(vm->frame); + +if (njs_is_true(>retval)) { +ret = njs_array_add(vm, iter->array, >value); +if (nxt_slow_path(ret != NXT_OK)) { +return ret; +} +} + +if (iter->next_index >= args[0].data.u.array->length) { +vm->retval.data.u.array = iter->array; +vm->retval.type = NJS_ARRAY; +vm->retval.data.truth = 1; + +return NXT_OK; +} + +return njs_array_iterator_apply(vm, iter, args, nargs); +} + + static nxt_noinline njs_ret_t njs_array_iterator_args(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs) { @@ -966,6 +1042,7 @@ njs_array_iterator_apply(njs_vm_t *vm, n */ array = args[0].data.u.array; n = iter->next_index; +iter->value = array->start[n]; arguments[1] = array->start[n]; njs_number_set([2], n); @@ -1066,6 +1143,13 @@ static const njs_object_prop_t njs_arra .value = njs_native_function(njs_array_prototype_every, njs_continuation_size(njs_array_iter_t), 0), }, + +{ +.type = NJS_METHOD, +.name = njs_string("filter"), +.value = njs_native_function(njs_array_prototype_filter, + njs_continuation_size(njs_array_iter_t), 0), +}, }; diff -r 2f40b153a7c1 -r 6e212d387b88 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Tue Aug 09 14:10:21 2016 +0300 +++ b/njs/test/njs_unit_test.c Tue Aug 09 14:10:29 2016 +0300 @@ -2333,6 +2333,38 @@ static njs_unit_test_t njs_test[] = "a.every(function(v, i, a) { return v > 0 })"), nxt_string("true") }, +{ nxt_string("var a = [];" + "a.filter(function(v, i, a) { return v > 1 })"), + nxt_string("") }, + +{ nxt_string("var a = [1,2,3,-1,5];" + "a.filter(function(v, i, a) { return v > 1 })"), + nx
[njs] Array.reduceRight() function.
details: http://hg.nginx.org/njs/rev/f23c723cf833 branches: changeset: 148:f23c723cf833 user: Igor Sysoev <i...@sysoev.ru> date: Tue Aug 09 14:10:33 2016 +0300 description: Array.reduceRight() function. diffstat: njs/njs_array.c | 105 +++ njs/test/njs_unit_test.c | 42 ++ 2 files changed, 147 insertions(+), 0 deletions(-) diffs (187 lines): diff -r 5bd9c6bea8a6 -r f23c723cf833 njs/njs_array.c --- a/njs/njs_array.c Tue Aug 09 14:10:32 2016 +0300 +++ b/njs/njs_array.c Tue Aug 09 14:10:33 2016 +0300 @@ -70,12 +70,15 @@ static njs_ret_t njs_array_prototype_map nxt_uint_t nargs, njs_index_t unused); static njs_ret_t njs_array_prototype_reduce_cont(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +static njs_ret_t njs_array_prototype_reduce_right_cont(njs_vm_t *vm, +njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); static nxt_noinline njs_ret_t njs_array_iterator_args(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs); static nxt_noinline uint32_t njs_array_iterator_next(njs_array_t *array, uint32_t n, uint32_t length); static nxt_noinline njs_ret_t njs_array_iterator_apply(njs_vm_t *vm, njs_array_iter_t *iter, njs_value_t *args, nxt_uint_t nargs); +static uint32_t njs_array_reduce_right_next(njs_array_t *array, int32_t n); nxt_noinline njs_array_t * @@ -1206,6 +1209,101 @@ njs_array_iterator_apply(njs_vm_t *vm, n } +static njs_ret_t +njs_array_prototype_reduce_right(njs_vm_t *vm, njs_value_t *args, +nxt_uint_t nargs, njs_index_t unused) +{ +int32_t n; +njs_array_t *array; +njs_array_iter_t *iter; + +if (nargs > 1 && njs_is_array([0]) && njs_is_function([1])) { +array = args[0].data.u.array; +iter = njs_continuation(vm->frame); +iter->next_index = njs_array_reduce_right_next(array, array->length); + +} else { +vm->exception = _exception_type_error; +return NXT_ERROR; +} + +iter = njs_continuation(vm->frame); +iter->u.cont.function = njs_array_prototype_reduce_right_cont; + +if (nargs > 2) { +iter->retval = args[2]; + +} else { +array = args[0].data.u.array; +n = iter->next_index; + +if (n < 0) { +vm->exception = _exception_type_error; +return NXT_ERROR; +} + +iter->retval = array->start[n]; + +iter->next_index = njs_array_reduce_right_next(array, n); +} + +return njs_array_prototype_reduce_right_cont(vm, args, nargs, unused); +} + + +static njs_ret_t +njs_array_prototype_reduce_right_cont(njs_vm_t *vm, njs_value_t *args, +nxt_uint_t nargs, njs_index_t unused) +{ +nxt_int_t n; +njs_array_t *array; +njs_value_t arguments[5]; +njs_array_iter_t *iter; + +iter = njs_continuation(vm->frame); + +if ((int32_t) iter->next_index < 0) { +vm->retval = iter->retval; +return NXT_OK; +} + +arguments[0] = njs_value_void; + +/* GC: array elt, array */ +arguments[1] = iter->retval; + +array = args[0].data.u.array; +n = iter->next_index; +arguments[2] = array->start[n]; + +njs_number_set([3], n); + +arguments[4] = args[0]; + +iter->next_index = njs_array_reduce_right_next(array, n); + +return njs_function_apply(vm, args[1].data.u.function, arguments, 5, + (njs_index_t) >retval); +} + + +static nxt_noinline uint32_t +njs_array_reduce_right_next(njs_array_t *array, int32_t n) +{ +n = nxt_min(n, (int32_t) array->length) - 1; + +while (n >= 0) { +if (njs_is_valid(>start[n])) { +return n; +} + +n--; +} + +return n; +} + + static const njs_object_prop_t njs_array_prototype_properties[] = { { @@ -1314,6 +1412,13 @@ static const njs_object_prop_t njs_arra .value = njs_native_function(njs_array_prototype_reduce, njs_continuation_size(njs_array_iter_t), 0), }, + +{ +.type = NJS_METHOD, +.name = njs_string("reduceRight"), +.value = njs_native_function(njs_array_prototype_reduce_right, + njs_continuation_size(njs_array_iter_t), 0), +}, }; diff -r 5bd9c6bea8a6 -r f23c723cf833 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Tue Aug 09 14:10:32 2016 +0300 +++ b/njs/test/njs_unit_test.c Tue Aug 09 14:10:33 2016 +0300 @@ -2421,6 +2421,48 @@ static njs_unit_test_t njs_test[] = " { return a.concat(b) }, [])"), nxt_string("0,1,2,3,4,5") }, +{ nxt_string("var a = [];" + "a.reduceRight(function(p, v, i, a) { return p + v })"), + nxt_string("TypeError") }
[njs] Array iterator functions update.
details: http://hg.nginx.org/njs/rev/2f40b153a7c1 branches: changeset: 144:2f40b153a7c1 user: Igor Sysoev <i...@sysoev.ru> date: Tue Aug 09 14:10:21 2016 +0300 description: Array iterator functions update. diffstat: njs/njs_array.c | 108 ++ njs/test/njs_unit_test.c |8 +++ 2 files changed, 70 insertions(+), 46 deletions(-) diffs (290 lines): diff -r 73b0fd4c2ea6 -r 2f40b153a7c1 njs/njs_array.c --- a/njs/njs_array.c Thu Aug 04 16:59:15 2016 +0300 +++ b/njs/njs_array.c Tue Aug 09 14:10:21 2016 +0300 @@ -37,10 +37,15 @@ typedef struct { njs_continuation_t cont; u_char padding[NJS_CONTINUATION_SIZE]; } u; +/* + * This retval value must be aligned so the continuation is padded + * to aligned size. + */ njs_value_t retval; -int32_t index; + +uint32_tnext_index; uint32_tlength; -} njs_array_next_t; +} njs_array_iter_t; static njs_ret_t @@ -57,11 +62,11 @@ static nxt_noinline njs_ret_t njs_array_ static nxt_noinline njs_ret_t njs_array_prototype_every_cont(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); static nxt_noinline njs_ret_t njs_array_iterator_args(njs_vm_t *vm, -njs_value_t * args, nxt_uint_t nargs); -static nxt_noinline nxt_int_t njs_array_iterator_next(njs_value_t *value, -nxt_uint_t n, nxt_uint_t length); +njs_value_t *args, nxt_uint_t nargs); +static nxt_noinline uint32_t njs_array_iterator_next(njs_array_t *array, +uint32_t n, uint32_t length); static nxt_noinline njs_ret_t njs_array_iterator_apply(njs_vm_t *vm, -njs_array_next_t *next, njs_value_t *args, nxt_uint_t nargs); +njs_array_iter_t *iter, njs_value_t *args, nxt_uint_t nargs); nxt_noinline njs_array_t * @@ -778,15 +783,15 @@ njs_array_prototype_for_each(njs_vm_t *v njs_index_t unused) { nxt_int_t ret; -njs_array_next_t *next; +njs_array_iter_t *iter; ret = njs_array_iterator_args(vm, args, nargs); if (nxt_slow_path(ret != NXT_OK)) { return ret; } -next = njs_continuation(vm->frame); -next->u.cont.function = njs_array_prototype_for_each_cont; +iter = njs_continuation(vm->frame); +iter->u.cont.function = njs_array_prototype_for_each_cont; return njs_array_prototype_for_each_cont(vm, args, nargs, unused); } @@ -796,16 +801,16 @@ static njs_ret_t njs_array_prototype_for_each_cont(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { -njs_array_next_t *next; +njs_array_iter_t *iter; -next = njs_continuation(vm->frame); +iter = njs_continuation(vm->frame); -if (next->index < 0) { +if (iter->next_index >= args[0].data.u.array->length) { vm->retval = njs_value_void; return NXT_OK; } -return njs_array_iterator_apply(vm, next, args, nargs); +return njs_array_iterator_apply(vm, iter, args, nargs); } @@ -814,16 +819,16 @@ njs_array_prototype_some(njs_vm_t *vm, n njs_index_t unused) { nxt_int_t ret; -njs_array_next_t *next; +njs_array_iter_t *iter; ret = njs_array_iterator_args(vm, args, nargs); if (nxt_slow_path(ret != NXT_OK)) { return ret; } -next = njs_continuation(vm->frame); -next->u.cont.function = njs_array_prototype_some_cont; -next->retval.data.truth = 0; +iter = njs_continuation(vm->frame); +iter->u.cont.function = njs_array_prototype_some_cont; +iter->retval.data.truth = 0; return njs_array_prototype_some_cont(vm, args, nargs, unused); } @@ -833,19 +838,19 @@ static njs_ret_t njs_array_prototype_some_cont(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { -njs_array_next_t *next; +njs_array_iter_t *iter; const njs_value_t *retval; -next = njs_continuation(vm->frame); +iter = njs_continuation(vm->frame); -if (njs_is_true(>retval)) { +if (njs_is_true(>retval)) { retval = _value_true; -} else if (next->index < 0) { +} else if (iter->next_index >= args[0].data.u.array->length) { retval = _value_false; } else { -return njs_array_iterator_apply(vm, next, args, nargs); +return njs_array_iterator_apply(vm, iter, args, nargs); } vm->retval = *retval; @@ -859,16 +864,16 @@ njs_array_prototype_every(njs_vm_t *vm, njs_index_t unused) { nxt_int_t ret; -njs_array_next_t *next; +njs_array_iter_t *iter; ret = njs_array_iterator_args(vm, args, nargs); if (nxt_slow_path(ret != NXT_OK)) { return ret; } -next = njs_continuation(vm->frame); -next->u.cont.function = njs_array_prototype_every_cont; -next->retval.data.truth = 1; +
[njs] nxt_trace.o has been added to the libnjs.
details: http://hg.nginx.org/njs/rev/73b0fd4c2ea6 branches: changeset: 143:73b0fd4c2ea6 user: Igor Sysoev <i...@sysoev.ru> date: Thu Aug 04 16:59:15 2016 +0300 description: nxt_trace.o has been added to the libnjs. diffstat: Makefile | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diffs (27 lines): diff -r 19175c06b532 -r 73b0fd4c2ea6 Makefile --- a/Makefile Thu Aug 04 16:31:48 2016 +0300 +++ b/Makefile Thu Aug 04 16:59:15 2016 +0300 @@ -41,6 +41,7 @@ main: $(NXT_BUILDDIR)/libnjs.a $(NXT_BUILDDIR)/nxt_array.o \ $(NXT_BUILDDIR)/nxt_rbtree.o \ $(NXT_BUILDDIR)/nxt_lvlhsh.o \ + $(NXT_BUILDDIR)/nxt_trace.o \ $(NXT_BUILDDIR)/nxt_random.o \ $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ @@ -73,6 +74,7 @@ main: $(NXT_BUILDDIR)/libnjs.a $(NXT_BUILDDIR)/nxt_array.o \ $(NXT_BUILDDIR)/nxt_rbtree.o \ $(NXT_BUILDDIR)/nxt_lvlhsh.o \ + $(NXT_BUILDDIR)/nxt_trace.o \ $(NXT_BUILDDIR)/nxt_random.o \ $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ @@ -405,7 +407,6 @@ dist: -I$(NXT_LIB) -Injs \ njs/test/njs_unit_test.c \ $(NXT_BUILDDIR)/libnjs.a \ - $(NXT_BUILDDIR)/libnxt.a \ -lm $(NXT_PCRE_LIB) include $(NXT_LIB)/Makefile ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] nxt_trace files have been missed in the previous commit.
details: http://hg.nginx.org/njs/rev/b33ba39a1108 branches: changeset: 141:b33ba39a1108 user: Igor Sysoev <i...@sysoev.ru> date: Thu Aug 04 16:27:38 2016 +0300 description: nxt_trace files have been missed in the previous commit. diffstat: nxt/nxt_trace.c | 57 +++ nxt/nxt_trace.h | 68 + 2 files changed, 125 insertions(+), 0 deletions(-) diffs (133 lines): diff -r 23598cfcfd15 -r b33ba39a1108 nxt/nxt_trace.c --- /dev/null Thu Jan 01 00:00:00 1970 + +++ b/nxt/nxt_trace.c Thu Aug 04 16:27:38 2016 +0300 @@ -0,0 +1,57 @@ + +/* + * Copyright (C) Igor Sysoev + * Copyright (C) NGINX, Inc. + */ + +#include +#include +#include +#include +#include +#include + + +static u_char * +nxt_last_handler(nxt_trace_t *trace, nxt_trace_data_t *td, u_char *start) +{ +int n; +ssize_t size; + +size = td->end - start; +n = vsnprintf((char *) start, size, td->fmt, td->args); + +if (n < size) { +start += n; +} + +return start; +} + + +void +nxt_trace_handler(nxt_trace_t *trace, uint32_t level, const char *fmt, ...) +{ +u_char*start; +nxt_trace_t last; +nxt_trace_data_t td; + +td.level = level; +td.fmt = fmt; + +va_start(td.args, fmt); + +start = alloca(trace->size); +td.end = start + trace->size; + +last.handler = nxt_last_handler; +trace->next = + +while (trace->prev != NULL) { +trace = trace->prev; +} + +(void) trace->handler(trace, , start); + +va_end(td.args); +} diff -r 23598cfcfd15 -r b33ba39a1108 nxt/nxt_trace.h --- /dev/null Thu Jan 01 00:00:00 1970 + +++ b/nxt/nxt_trace.h Thu Aug 04 16:27:38 2016 +0300 @@ -0,0 +1,68 @@ + +/* + * Copyright (C) Igor Sysoev + * Copyright (C) NGINX, Inc. + */ + +#ifndef _NXT_TRACE_H_INCLUDED_ +#define _NXT_TRACE_H_INCLUDED_ + + +typedef enum { +NXT_LEVEL_CRIT = 0, +NXT_LEVEL_ERROR, +NXT_LEVEL_WARN, +NXT_LEVEL_INFO, +NXT_LEVEL_TRACE, +} nxt_trace_level_t; + + +typedef struct { +uint32_t level; +u_char *end; +const char *fmt; +va_list args; +} nxt_trace_data_t; + + +typedef struct nxt_trace_s nxt_trace_t; + +typedef u_char *(*nxt_trace_handler_t)(nxt_trace_t *trace, nxt_trace_data_t *td, +u_char *start); + +struct nxt_trace_s { +uint32_t level; +uint32_t size; +nxt_trace_handler_t handler; +void *data; +nxt_trace_t *prev; +nxt_trace_t *next; +}; + + +#define nxt_alert(_trace, _level, ...)\ +do { \ +nxt_trace_t *_trace_ = _trace; \ +uint32_t _level_ = _level;\ + \ +if (nxt_slow_path(_trace_->level >= _level_)) { \ +nxt_trace_handler(_trace_, _level_, __VA_ARGS__); \ +} \ +} while (0) + + +#define nxt_trace(_trace, ...)\ +do { \ +nxt_trace_t *_trace_ = _trace; \ + \ +if (nxt_slow_path(_trace_->level == NXT_LEVEL_TRACE)) { \ +nxt_trace_handler(_trace_, NXT_LEVEL_TRACE, __VA_ARGS__); \ +} \ +} while (0) + + +NXT_EXPORT void nxt_trace_handler(nxt_trace_t *trace, uint32_t level, +const char *fmt, ...); + + +#endif /* _NXT_TRACE_H_INCLUDED_ */ ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] The lvlhsh unit test has been updated after nxt_str_t chan...
details: http://hg.nginx.org/njs/rev/19175c06b532 branches: changeset: 142:19175c06b532 user: Igor Sysoev <i...@sysoev.ru> date: Thu Aug 04 16:31:48 2016 +0300 description: The lvlhsh unit test has been updated after nxt_str_t changes. diffstat: nxt/test/lvlhsh_unit_test.c | 15 --- 1 files changed, 8 insertions(+), 7 deletions(-) diffs (53 lines): diff -r b33ba39a1108 -r 19175c06b532 nxt/test/lvlhsh_unit_test.c --- a/nxt/test/lvlhsh_unit_test.c Thu Aug 04 16:27:38 2016 +0300 +++ b/nxt/test/lvlhsh_unit_test.c Thu Aug 04 16:31:48 2016 +0300 @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -19,7 +20,7 @@ static nxt_int_t lvlhsh_unit_test_key_test(nxt_lvlhsh_query_t *lhq, void *data) { -if (*(uintptr_t *) lhq->key.data == (uintptr_t) data) { +if (*(uintptr_t *) lhq->key.start == (uintptr_t) data) { return NXT_OK; } @@ -58,8 +59,8 @@ lvlhsh_unit_test_add(nxt_lvlhsh_t *lh, c lhq.key_hash = key; lhq.replace = 0; -lhq.key.len = sizeof(uintptr_t); -lhq.key.data = (u_char *) +lhq.key.length = sizeof(uintptr_t); +lhq.key.start = (u_char *) lhq.value = (void *) key; lhq.proto = proto; lhq.pool = pool; @@ -86,8 +87,8 @@ lvlhsh_unit_test_get(nxt_lvlhsh_t *lh, c nxt_lvlhsh_query_t lhq; lhq.key_hash = key; -lhq.key.len = sizeof(uintptr_t); -lhq.key.data = (u_char *) +lhq.key.length = sizeof(uintptr_t); +lhq.key.start = (u_char *) lhq.proto = proto; if (nxt_lvlhsh_find(lh, ) == NXT_OK) { @@ -112,8 +113,8 @@ lvlhsh_unit_test_delete(nxt_lvlhsh_t *lh nxt_lvlhsh_query_t lhq; lhq.key_hash = key; -lhq.key.len = sizeof(uintptr_t); -lhq.key.data = (u_char *) +lhq.key.length = sizeof(uintptr_t); +lhq.key.start = (u_char *) lhq.proto = proto; lhq.pool = pool; ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] njs_parser_is_lvalue().
details: http://hg.nginx.org/njs/rev/f171ddad457e branches: changeset: 138:f171ddad457e user: Igor Sysoev <i...@sysoev.ru> date: Thu Aug 04 14:43:20 2016 +0300 description: njs_parser_is_lvalue(). diffstat: njs/njs_parser.h| 7 ++- njs/njs_parser_expression.c | 12 +++- 2 files changed, 5 insertions(+), 14 deletions(-) diffs (53 lines): diff -r e4f1fda52fe8 -r f171ddad457e njs/njs_parser.h --- a/njs/njs_parser.h Tue Jul 26 16:25:58 2016 +0300 +++ b/njs/njs_parser.h Thu Aug 04 14:43:20 2016 +0300 @@ -213,11 +213,8 @@ typedef enum { } njs_variable_node_state_t; -typedef enum { -NJS_LVALUE_NONE = 0, -NJS_LVALUE_ENABLED, -NJS_LVALUE_ASSIGNED, -} njs_lvalue_state_t; +#define njs_parser_is_lvalue(node)\ +((node)->token == NJS_TOKEN_NAME || (node)->token == NJS_TOKEN_PROPERTY) typedef struct njs_parser_node_snjs_parser_node_t; diff -r e4f1fda52fe8 -r f171ddad457e njs/njs_parser_expression.c --- a/njs/njs_parser_expression.c Tue Jul 26 16:25:58 2016 +0300 +++ b/njs/njs_parser_expression.c Thu Aug 04 14:43:20 2016 +0300 @@ -437,9 +437,7 @@ njs_parser_assignment_expression(njs_vm_ node = parser->node; -if (parser->node->token != NJS_TOKEN_NAME -&& parser->node->token != NJS_TOKEN_PROPERTY) -{ +if (!njs_parser_is_lvalue(parser->node)) { return njs_parser_invalid_lvalue(vm, parser, "assignment"); } @@ -811,9 +809,7 @@ njs_parser_inc_dec_expression(njs_vm_t * return next; } -if (parser->node->token != NJS_TOKEN_NAME -&& parser->node->token != NJS_TOKEN_PROPERTY) -{ +if (!njs_parser_is_lvalue(parser->node)) { return njs_parser_invalid_lvalue(vm, parser, "prefix operation"); } @@ -865,9 +861,7 @@ njs_parser_post_inc_dec_expression(njs_v return token; } -if (parser->node->token != NJS_TOKEN_NAME -&& parser->node->token != NJS_TOKEN_PROPERTY) -{ +if (!njs_parser_is_lvalue(parser->node)) { return njs_parser_invalid_lvalue(vm, parser, "postfix operation"); } ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] nxt_str_t changes.
details: http://hg.nginx.org/njs/rev/016339472304 branches: changeset: 139:016339472304 user: Igor Sysoev <i...@sysoev.ru> date: Thu Aug 04 14:45:27 2016 +0300 description: nxt_str_t changes. diffstat: nginx/ngx_http_js_module.c| 73 ++ nginx/ngx_stream_js_module.c | 23 +++-- njs/njs_array.c | 4 +- njs/njs_boolean.c | 1 + njs/njs_builtin.c | 1 + njs/njs_date.c| 4 +- njs/njs_disassembler.c| 10 +++-- njs/njs_extern.c | 13 --- njs/njs_function.c| 1 + njs/njs_generator.c | 1 + njs/njs_lexer.c | 21 ++- njs/njs_lexer_keyword.c | 3 +- njs/njs_math.c| 1 + njs/njs_nonrecursive_parser.c | 1 + njs/njs_number.c | 1 + njs/njs_object.c | 25 +++--- njs/njs_parser.c | 28 --- njs/njs_parser_expression.c | 1 + njs/njs_regexp.c | 23 ++--- njs/njs_string.c | 13 --- njs/njs_variable.c| 17 + njs/njs_vm.c | 39 +++--- njs/njscript.c| 1 + njs/test/njs_unit_test.c | 49 ++-- nxt/Makefile | 1 + nxt/nxt_djb_hash.c| 1 + nxt/nxt_lvlhsh.c | 1 + nxt/nxt_lvlhsh.h | 6 +-- nxt/nxt_string.h | 48 nxt/nxt_stub.h| 45 -- 30 files changed, 240 insertions(+), 216 deletions(-) diffs (truncated from 1428 to 1000 lines): diff -r f171ddad457e -r 016339472304 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.cThu Aug 04 14:43:20 2016 +0300 +++ b/nginx/ngx_http_js_module.cThu Aug 04 14:45:27 2016 +0300 @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -432,8 +433,8 @@ ngx_http_js_handler(ngx_http_request_t * ctx = ngx_http_get_module_ctx(r, ngx_http_js_module); -name.data = jlcf->content.data; -name.len = jlcf->content.len; +name.start = jlcf->content.data; +name.length = jlcf->content.len; func = njs_vm_function(ctx->vm, ); if (func == NULL) { @@ -446,7 +447,7 @@ ngx_http_js_handler(ngx_http_request_t * njs_vm_exception(ctx->vm, ); ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "js exception: %*s", exception.len, exception.data); + "js exception: %*s", exception.length, exception.start); return NGX_ERROR; } @@ -482,8 +483,8 @@ ngx_http_js_variable(ngx_http_request_t ctx = ngx_http_get_module_ctx(r, ngx_http_js_module); -name.data = fname->data; -name.len = fname->len; +name.start = fname->data; +name.length = fname->len; func = njs_vm_function(ctx->vm, ); if (func == NULL) { @@ -497,7 +498,7 @@ ngx_http_js_variable(ngx_http_request_t njs_vm_exception(ctx->vm, ); ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "js exception: %*s", exception.len, exception.data); + "js exception: %*s", exception.length, exception.start); v->not_found = 1; return NGX_OK; @@ -507,11 +508,11 @@ ngx_http_js_variable(ngx_http_request_t return NGX_ERROR; } -v->len = value.len; +v->len = value.length; v->valid = 1; v->no_cacheable = 0; v->not_found = 0; -v->data = value.data; +v->data = value.start; return NGX_OK; } @@ -640,14 +641,14 @@ ngx_http_js_ext_set_string(njs_vm_t *vm, r = (ngx_http_request_t *) obj; field = (ngx_str_t *) (p + data); -field->len = value->len; +field->len = value->length; -field->data = ngx_pnalloc(r->pool, value->len); +field->data = ngx_pnalloc(r->pool, value->length); if (field->data == NULL) { return NJS_ERROR; } -ngx_memcpy(field->data, value->data, value->len); +ngx_memcpy(field->data, value->start, value->length); return NJS_OK; } @@ -757,7 +758,8 @@ ngx_http_js_ext_get_header_out(njs_vm_t r = (ngx_http_request_t *) obj; v = (nxt_str_t *) data; -h = ngx_http_js_get_header(>headers_out.headers.part, v->data, v->len); +h = ngx_http_js_get_header(>headers_out.headers.part, v->start, + v->length); if (h == NULL) { return njs_string_create(vm, value, NULL, 0, 0); } @@ -778,7 +780,8 @@ ngx_http_js_ext_set_header_out(njs_vm_t r = (ngx_http_request_t *) obj; v = (nxt_str_t *) data; -h = ngx_http_js_get_header(>headers_out.headers.part, v->d
[njs] nxt_trace interface. nxt_regex, RegExp, and parser use it ...
details: http://hg.nginx.org/njs/rev/23598cfcfd15 branches: changeset: 140:23598cfcfd15 user: Igor Sysoev <i...@sysoev.ru> date: Thu Aug 04 16:05:38 2016 +0300 description: nxt_trace interface. nxt_regex, RegExp, and parser use it now. diffstat: Makefile|2 + njs/njs_generator.c | 41 ++- njs/njs_parser.c| 158 +++ njs/njs_parser.h| 14 +--- njs/njs_parser_expression.c | 37 +++-- njs/njs_regexp.c| 136 +++-- njs/njs_regexp.h|3 +- njs/njs_string.c| 19 ++-- njs/njs_variable.c |4 +- njs/njs_vm.c| 19 ++--- njs/njs_vm.h|7 +- njs/njscript.c | 10 ++ njs/test/njs_unit_test.c|3 + nxt/Makefile| 15 nxt/nxt_clang.h |1 + nxt/nxt_pcre.c | 63 - nxt/nxt_regex.h |2 +- 17 files changed, 263 insertions(+), 271 deletions(-) diffs (truncated from 1095 to 1000 lines): diff -r 016339472304 -r 23598cfcfd15 Makefile --- a/Makefile Thu Aug 04 14:45:27 2016 +0300 +++ b/Makefile Thu Aug 04 16:05:38 2016 +0300 @@ -169,6 +169,7 @@ dist: njs/njs_object_hash.h \ njs/njs_array.h \ njs/njs_function.h \ + njs/njs_regexp.h \ njs/njs_parser.h \ njs/njs_string.c \ @@ -404,6 +405,7 @@ dist: -I$(NXT_LIB) -Injs \ njs/test/njs_unit_test.c \ $(NXT_BUILDDIR)/libnjs.a \ + $(NXT_BUILDDIR)/libnxt.a \ -lm $(NXT_PCRE_LIB) include $(NXT_LIB)/Makefile diff -r 016339472304 -r 23598cfcfd15 njs/njs_generator.c --- a/njs/njs_generator.c Thu Aug 04 14:45:27 2016 +0300 +++ b/njs/njs_generator.c Thu Aug 04 16:05:38 2016 +0300 @@ -21,13 +21,6 @@ #include #include #include -#include - - -typedef enum { -NJS_GENERATOR_ERROR_ILLEGAL_CONTINUE = 0, -NJS_GENERATOR_ERROR_ILLEGAL_BREAK, -} njs_generator_error_t; static nxt_int_t njs_generator(njs_vm_t *vm, njs_parser_t *parser, @@ -125,8 +118,6 @@ static nxt_noinline nxt_int_t njs_genera static nxt_noinline nxt_int_t njs_generator_index_release(njs_vm_t *vm, njs_parser_t *parser, njs_index_t index); nxt_inline nxt_bool_t njs_generator_is_constant(njs_parser_node_t *node); -static nxt_int_t njs_generator_error(njs_vm_t *vm, njs_parser_node_t *node, -njs_generator_error_t err); static const nxt_str_t no_label = { 0, NULL }; @@ -1085,7 +1076,10 @@ njs_generate_continue_statement(njs_vm_t } } -return njs_generator_error(vm, node, NJS_GENERATOR_ERROR_ILLEGAL_CONTINUE); +nxt_alert(>trace, NXT_LEVEL_ERROR, + "SyntaxError: Illegal continue statement"); + +return NXT_ERROR; found: @@ -1126,7 +1120,10 @@ njs_generate_break_statement(njs_vm_t *v } } -return njs_generator_error(vm, node, NJS_GENERATOR_ERROR_ILLEGAL_BREAK); +nxt_alert(>trace, NXT_LEVEL_ERROR, + "SyntaxError: Illegal break statement"); + +return NXT_ERROR; found: @@ -2476,25 +2473,3 @@ njs_generator_is_constant(njs_parser_nod return (node->token >= NJS_TOKEN_FIRST_CONST && node->token <= NJS_TOKEN_LAST_CONST); } - - -static nxt_int_t -njs_generator_error(njs_vm_t *vm, njs_parser_node_t *node, -njs_generator_error_t err) -{ -uint32_t size; -const char *msg; -u_char buf[NJS_EXCEPTION_BUF_LENGTH]; - -static const char *errors[] = { -"SyntaxError: Illegal continue statement in %u", -"SyntaxError: Illegal break statement in %u", -}; - -msg = errors[err]; - -size = snprintf((char *) buf, NJS_EXCEPTION_BUF_LENGTH, -msg, node->token_line); - -return njs_vm_throw_exception(vm, buf, size); -} diff -r 016339472304 -r 23598cfcfd15 njs/njs_parser.c --- a/njs/njs_parser.c Thu Aug 04 14:45:27 2016 +0300 +++ b/njs/njs_parser.c Thu Aug 04 16:05:38 2016 +0300 @@ -54,8 +54,6 @@ static njs_token_t njs_parser_var_statem static njs_token_t njs_parser_if_statement(njs_vm_t *vm, njs_parser_t *parser); static njs_token_t njs_parser_switch_statement(njs_vm_t *vm, njs_parser_t *parser); -static njs_token_t njs_parser_duplicate_default_branch(njs_vm_t *vm, -njs_parser_t *parser); static njs_token_t njs_parser_while_statement(njs_vm_t *vm, njs_parser_t *parser); static njs_token_t njs_parser_do_while_statement(njs_vm_t *vm, @@ -68,8 +66,6 @@ static njs_token_t njs_parser_continue_s static njs_token_t njs_parser_break_statement(njs_vm_t *vm, njs_parser_t *parser); static njs_token_t njs_parser_try_statement(njs_vm_t *vm, njs_parser_t *parser); -static njs_token_t njs_parser_missing_catch_or_finally(njs_vm_t *vm, -njs_parser_t *parser); static nj
[njs] A dist target in Makefile.
details: http://hg.nginx.org/njs/rev/44e1a8aaa04e branches: changeset: 136:44e1a8aaa04e user: Igor Sysoev <i...@sysoev.ru> date: Tue Jul 26 15:09:07 2016 +0300 description: A dist target in Makefile. diffstat: Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (19 lines): diff -r 1792ce945acf -r 44e1a8aaa04e Makefile --- a/Makefile Mon Jul 25 15:34:53 2016 +0300 +++ b/Makefile Tue Jul 26 15:09:07 2016 +0300 @@ -1,5 +1,5 @@ -NJS_VER = 20150922 +NJS_VER = 0.1.0 NXT_LIB = nxt @@ -89,7 +89,7 @@ clean: rm -rf $(NXT_BUILDDIR) rm -f $(NXT_LIB)/Makefile.conf $(NXT_LIB)/nxt_auto_config.h -tarball: +dist: make clean mkdir njs-$(NJS_VER) cp -rp configure Makefile LICENSE README $(NXT_LIB) njs nginx \ ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Segfaults have been fixed when incorrect operands were used
details: http://hg.nginx.org/njs/rev/e4f1fda52fe8 branches: changeset: 137:e4f1fda52fe8 user: Igor Sysoev <i...@sysoev.ru> date: Tue Jul 26 16:25:58 2016 +0300 description: Segfaults have been fixed when incorrect operands were used in left-hand side expressions. diffstat: njs/njs_generator.c | 4 njs/njs_nonrecursive_parser.c | 1 - njs/njs_parser.c | 2 -- njs/njs_parser.h | 1 - njs/njs_parser_expression.c | 15 ++- njs/test/njs_unit_test.c | 13 +++-- 6 files changed, 21 insertions(+), 15 deletions(-) diffs (145 lines): diff -r 44e1a8aaa04e -r e4f1fda52fe8 njs/njs_generator.c --- a/njs/njs_generator.c Tue Jul 26 15:09:07 2016 +0300 +++ b/njs/njs_generator.c Tue Jul 26 16:25:58 2016 +0300 @@ -1263,7 +1263,6 @@ njs_generate_assignment(njs_vm_t *vm, nj } if (lvalue->state == NJS_VARIABLE_FIRST_ASSIGNMENT) { -lvalue->lvalue = NJS_LVALUE_ASSIGNED; value = njs_variable_value(parser, lvalue->index); *value = expr->u.value; node->index = expr->index; @@ -2336,8 +2335,6 @@ njs_generator_dest_index(njs_vm_t *vm, n dest = node->dest; if (dest != NULL && dest->index != NJS_INDEX_NONE) { -dest->lvalue = NJS_LVALUE_ASSIGNED; - return dest->index; } @@ -2363,7 +2360,6 @@ njs_generator_object_dest_index(njs_pars if (node->left == NULL) { /* Assign empty object directly to variable */ -dest->lvalue = NJS_LVALUE_ASSIGNED; return index; } } diff -r 44e1a8aaa04e -r e4f1fda52fe8 njs/njs_nonrecursive_parser.c --- a/njs/njs_nonrecursive_parser.c Tue Jul 26 15:09:07 2016 +0300 +++ b/njs/njs_nonrecursive_parser.c Tue Jul 26 16:25:58 2016 +0300 @@ -569,7 +569,6 @@ njs_parser_name_expression(njs_vm_t *vm, break; } -node->lvalue = NJS_LVALUE_ENABLED; node->u.variable = var; } } diff -r 44e1a8aaa04e -r e4f1fda52fe8 njs/njs_parser.c --- a/njs/njs_parser.c Tue Jul 26 15:09:07 2016 +0300 +++ b/njs/njs_parser.c Tue Jul 26 16:25:58 2016 +0300 @@ -681,7 +681,6 @@ njs_parser_var_statement(njs_vm_t *vm, n } name->token = NJS_TOKEN_NAME; -name->lvalue = NJS_LVALUE_ENABLED; name->u.variable = var; if (first) { @@ -1535,7 +1534,6 @@ njs_parser_terminal(njs_vm_t *vm, njs_pa } parser->code_size += sizeof(njs_vmcode_object_copy_t); -node->lvalue = NJS_LVALUE_ENABLED; node->u.variable = var; break; diff -r 44e1a8aaa04e -r e4f1fda52fe8 njs/njs_parser.h --- a/njs/njs_parser.h Tue Jul 26 15:09:07 2016 +0300 +++ b/njs/njs_parser.h Tue Jul 26 16:25:58 2016 +0300 @@ -225,7 +225,6 @@ typedef struct njs_parser_node_snjs_ struct njs_parser_node_s { njs_token_t token:8; njs_variable_node_state_t state:8;/* 2 bits */ -njs_lvalue_state_t lvalue:2; /* 2 bits */ uint8_t ctor:1; /* 1 bit */ uint8_t temporary; /* 1 bit */ uint32_ttoken_line; diff -r 44e1a8aaa04e -r e4f1fda52fe8 njs/njs_parser_expression.c --- a/njs/njs_parser_expression.c Tue Jul 26 15:09:07 2016 +0300 +++ b/njs/njs_parser_expression.c Tue Jul 26 16:25:58 2016 +0300 @@ -292,7 +292,7 @@ njs_parser_var_expression(njs_vm_t *vm, node = parser->node; -if (node->lvalue == NJS_LVALUE_NONE) { +if (parser->node->token != NJS_TOKEN_NAME) { return njs_parser_invalid_lvalue(vm, parser, "assignment"); } @@ -437,7 +437,9 @@ njs_parser_assignment_expression(njs_vm_ node = parser->node; -if (node->lvalue == NJS_LVALUE_NONE) { +if (parser->node->token != NJS_TOKEN_NAME +&& parser->node->token != NJS_TOKEN_PROPERTY) +{ return njs_parser_invalid_lvalue(vm, parser, "assignment"); } @@ -809,7 +811,9 @@ njs_parser_inc_dec_expression(njs_vm_t * return next; } -if (parser->node->lvalue == NJS_LVALUE_NONE) { +if (parser->node->token != NJS_TOKEN_NAME +&& parser->node->token != NJS_TOKEN_PROPERTY) +{ return njs_parser_invalid_lvalue(vm, parser, "prefix operation"); } @@ -861,7 +865,9 @@ njs_parser_post_inc_dec_expression(njs_v return token; } -if (parser->node->lvalue == NJS_LVALUE_NONE) { +if (parser->node->token != NJS_TOKEN_NAME +&& parser->node->token != NJS_TOKEN_PROPERTY) +{ return njs_parser_invalid_lvalue(vm, parser, "postfix
[njs] Removed tag help from .hgtags
details: http://hg.nginx.org/njs/rev/1792ce945acf branches: changeset: 135:1792ce945acf user: Igor Sysoev <i...@sysoev.ru> date: Mon Jul 25 15:34:53 2016 +0300 description: Removed tag help from .hgtags diffstat: .hgtags | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) diffs (8 lines): diff -r be657808a12b -r 1792ce945acf .hgtags --- a/.hgtags Mon Jul 25 15:17:51 2016 +0300 +++ b/.hgtags Mon Jul 25 15:34:53 2016 +0300 @@ -1,4 +1,1 @@ -cdb8d20935ee96f1fa0c99d994d4b11cefcbc119 help cdb8d20935ee96f1fa0c99d994d4b11cefcbc119 0.1.0 -cdb8d20935ee96f1fa0c99d994d4b11cefcbc119 help - help ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Removed tag help
details: http://hg.nginx.org/njs/rev/be657808a12b branches: changeset: 134:be657808a12b user: Igor Sysoev <i...@sysoev.ru> date: Mon Jul 25 15:17:51 2016 +0300 description: Removed tag help diffstat: .hgtags | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diffs (8 lines): diff -r 37373519f505 -r be657808a12b .hgtags --- a/.hgtags Fri Jul 22 17:00:05 2016 +0300 +++ b/.hgtags Mon Jul 25 15:17:51 2016 +0300 @@ -1,2 +1,4 @@ cdb8d20935ee96f1fa0c99d994d4b11cefcbc119 help cdb8d20935ee96f1fa0c99d994d4b11cefcbc119 0.1.0 +cdb8d20935ee96f1fa0c99d994d4b11cefcbc119 help + help ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Added tag 0.1.0 for changeset cdb8d20935ee
details: http://hg.nginx.org/njs/rev/37373519f505 branches: changeset: 133:37373519f505 user: Igor Sysoev <i...@sysoev.ru> date: Fri Jul 22 17:00:05 2016 +0300 description: Added tag 0.1.0 for changeset cdb8d20935ee diffstat: .hgtags | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diffs (6 lines): diff -r cdb8d20935ee -r 37373519f505 .hgtags --- /dev/null Thu Jan 01 00:00:00 1970 + +++ b/.hgtags Fri Jul 22 17:00:05 2016 +0300 @@ -0,0 +1,2 @@ +cdb8d20935ee96f1fa0c99d994d4b11cefcbc119 help +cdb8d20935ee96f1fa0c99d994d4b11cefcbc119 0.1.0 ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] A fix of code generation of logical operations.
details: http://hg.nginx.org/njs/rev/41689f60372a branches: changeset: 129:41689f60372a user: Igor Sysoev <i...@sysoev.ru> date: Thu Jul 21 21:37:46 2016 +0300 description: A fix of code generation of logical operations. diffstat: njs/njs_generator.c | 5 - njs/test/njs_unit_test.c | 3 +++ 2 files changed, 3 insertions(+), 5 deletions(-) diffs (28 lines): diff -r f59ab0fccecb -r 41689f60372a njs/njs_generator.c --- a/njs/njs_generator.c Thu Jul 21 20:51:22 2016 +0300 +++ b/njs/njs_generator.c Thu Jul 21 21:37:46 2016 +0300 @@ -1666,11 +1666,6 @@ njs_generate_test_jump_expression(njs_vm test_jump->code.retval = NJS_VMCODE_RETVAL; test_jump->value = node->left->index; -ret = njs_generator_node_index_release(vm, parser, node->left); -if (nxt_slow_path(ret != NXT_OK)) { -return ret; -} - node->index = njs_generator_dest_index(vm, parser, node); if (nxt_slow_path(node->index == NJS_INDEX_ERROR)) { return node->index; diff -r f59ab0fccecb -r 41689f60372a njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Jul 21 20:51:22 2016 +0300 +++ b/njs/test/njs_unit_test.c Thu Jul 21 21:37:46 2016 +0300 @@ -1476,6 +1476,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("var a = 3; if (true) if (false); else; a = 2; a"), nxt_string("2") }, +{ nxt_string("var a = [3], b; if (1==1||2==2) { b = '1'+'2'+a[0] }; b }"), + nxt_string("123") }, + /* do while. */ { nxt_string("do { break } if (false)"), ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] A line number in error messages was incorrect if a script
details: http://hg.nginx.org/njs/rev/eae6c48ff5c1 branches: changeset: 130:eae6c48ff5c1 user: Igor Sysoev <i...@sysoev.ru> date: Thu Jul 21 21:42:58 2016 +0300 description: A line number in error messages was incorrect if a script has comments. diffstat: njs/njs_lexer.c | 8 +++- njs/test/njs_unit_test.c | 6 ++ 2 files changed, 13 insertions(+), 1 deletions(-) diffs (42 lines): diff -r 41689f60372a -r eae6c48ff5c1 njs/njs_lexer.c --- a/njs/njs_lexer.c Thu Jul 21 21:37:46 2016 +0300 +++ b/njs/njs_lexer.c Thu Jul 21 21:42:58 2016 +0300 @@ -636,8 +636,9 @@ njs_lexer_division(njs_lexer_t *lexer, n for (p = lexer->start; p < lexer->end; p++) { -if (*p == '\r' || *p == '\n') { +if (*p == '\n') { lexer->start = p + 1; +lexer->line++; return NJS_TOKEN_LINE_END; } } @@ -647,6 +648,11 @@ njs_lexer_division(njs_lexer_t *lexer, n for (p = lexer->start; p < lexer->end; p++) { +if (*p == '\n') { +lexer->line++; +continue; +} + if (*p == '*') { p++; diff -r 41689f60372a -r eae6c48ff5c1 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Jul 21 21:37:46 2016 +0300 +++ b/njs/test/njs_unit_test.c Thu Jul 21 21:42:58 2016 +0300 @@ -52,6 +52,12 @@ static njs_unit_test_t njs_test[] = { nxt_string("var + a"), nxt_string("SyntaxError: Unexpected token \"+\" in 1") }, +{ nxt_string("//\r\n; var + a"), + nxt_string("SyntaxError: Unexpected token \"+\" in 2") }, + +{ nxt_string("/*\n*/; var + a"), + nxt_string("SyntaxError: Unexpected token \"+\" in 2") }, + { nxt_string("var \n a \n = 1; a"), nxt_string("1") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Now a make command does not fail for obscure reason at
details: http://hg.nginx.org/njs/rev/f0c94dd2bdb3 branches: changeset: 131:f0c94dd2bdb3 user: Igor Sysoev <i...@sysoev.ru> date: Fri Jul 22 14:15:54 2016 +0300 description: Now a make command does not fail for obscure reason at the very start or after "make clean" command but it offers to run the ./configure command instead. This change is not compatible with BSD PMake which does not support both "-include" and "sinclude" directives but only ".sinclude" directive so GNU Make should be used. diffstat: Makefile | 10 -- nxt/auto/configure | 7 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diffs (44 lines): diff -r eae6c48ff5c1 -r f0c94dd2bdb3 Makefile --- a/Makefile Thu Jul 21 21:42:58 2016 +0300 +++ b/Makefile Fri Jul 22 14:15:54 2016 +0300 @@ -3,10 +3,16 @@ NJS_VER = 20150922 NXT_LIB = nxt -include $(NXT_LIB)/Makefile.conf +-include $(NXT_LIB)/Makefile.conf NXT_BUILDDIR = build +unconfigured: + @echo + @echo " Please run ./configure before make" + @echo + +main: $(NXT_BUILDDIR)/libnjs.a $(NXT_BUILDDIR)/libnjs.a: \ $(NXT_BUILDDIR)/njscript.o \ @@ -81,7 +87,7 @@ test: \ clean: rm -rf $(NXT_BUILDDIR) - rm $(NXT_LIB)/Makefile.conf $(NXT_LIB)/nxt_auto_config.h + rm -f $(NXT_LIB)/Makefile.conf $(NXT_LIB)/nxt_auto_config.h tarball: make clean diff -r eae6c48ff5c1 -r f0c94dd2bdb3 nxt/auto/configure --- a/nxt/auto/configureThu Jul 21 21:42:58 2016 +0300 +++ b/nxt/auto/configureFri Jul 22 14:15:54 2016 +0300 @@ -55,3 +55,10 @@ END . ${NXT_AUTO}memalign . ${NXT_AUTO}getrandom . ${NXT_AUTO}pcre + + +cat << END >> $NXT_MAKEFILE_CONF + +target:main + +END ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Duplicate function names are disabled.
details: http://hg.nginx.org/njs/rev/cdb8d20935ee branches: changeset: 132:cdb8d20935ee user: Igor Sysoev <i...@sysoev.ru> date: Fri Jul 22 14:38:06 2016 +0300 description: Duplicate function names are disabled. diffstat: njs/njs_parser.c | 4 ++-- njs/njs_parser.h | 1 + njs/njs_variable.c | 31 +++ njs/njs_variable.h | 1 + njs/test/njs_unit_test.c | 9 + 5 files changed, 44 insertions(+), 2 deletions(-) diffs (110 lines): diff -r f0c94dd2bdb3 -r cdb8d20935ee njs/njs_parser.c --- a/njs/njs_parser.c Fri Jul 22 14:15:54 2016 +0300 +++ b/njs/njs_parser.c Fri Jul 22 14:38:06 2016 +0300 @@ -290,7 +290,6 @@ njs_parser_match(njs_vm_t *vm, njs_parse static njs_token_t njs_parser_function_declaration(njs_vm_t *vm, njs_parser_t *parser) { -nxt_uint_t level; njs_token_ttoken; njs_value_t*value; njs_variable_t *var; @@ -313,7 +312,7 @@ njs_parser_function_declaration(njs_vm_t return NJS_TOKEN_ILLEGAL; } -var = njs_parser_variable(vm, parser, ); +var = njs_parser_name_alloc(vm, parser); if (nxt_slow_path(var == NULL)) { return NJS_TOKEN_ERROR; } @@ -2241,6 +2240,7 @@ njs_parser_error(njs_vm_t *vm, njs_parse "SyntaxError: Invalid Unicode code point \"%.*s\" in %u", "SyntaxError: Unterminated RegExp \"%.*s\" in %u", "SyntaxError: Invalid RegExp flags \"%.*s\" in %u", +"SyntaxError: Duplicate declaration \"%.*s\" in %u", }; msg = errors[err]; diff -r f0c94dd2bdb3 -r cdb8d20935ee njs/njs_parser.h --- a/njs/njs_parser.h Fri Jul 22 14:15:54 2016 +0300 +++ b/njs/njs_parser.h Fri Jul 22 14:38:06 2016 +0300 @@ -324,6 +324,7 @@ typedef enum { NJS_PARSER_ERROR_UNICODE, NJS_PARSER_ERROR_UNTERMINATED_REGEXP, NJS_PARSER_ERROR_REGEXP_FLAGS, +NJS_PARSER_ERROR_DUPLICATE_DECLARATION, } njs_parser_error_t; diff -r f0c94dd2bdb3 -r cdb8d20935ee njs/njs_variable.c --- a/njs/njs_variable.cFri Jul 22 14:15:54 2016 +0300 +++ b/njs/njs_variable.cFri Jul 22 14:38:06 2016 +0300 @@ -54,6 +54,37 @@ static const nxt_lvlhsh_proto_t njs_var njs_variable_t * +njs_parser_name_alloc(njs_vm_t *vm, njs_parser_t *parser) +{ +nxt_int_t ret; +njs_variable_t *var; +nxt_lvlhsh_query_t lhq; + +var = njs_variable_alloc(vm, parser, >lexer->text); +if (nxt_slow_path(var == NULL)) { +return NULL; +} + +lhq.key_hash = parser->lexer->key_hash; +lhq.key = parser->lexer->text; +lhq.replace = 0; +lhq.value = var; +lhq.proto = _variables_hash_proto; +lhq.pool = vm->mem_cache_pool; + +ret = nxt_lvlhsh_insert(>variables_hash, ); + +if (nxt_fast_path(ret == NXT_OK)) { +return var; +} + +(void) njs_parser_error(vm, parser, NJS_PARSER_ERROR_DUPLICATE_DECLARATION); + +return NULL; +} + + +njs_variable_t * njs_parser_variable(njs_vm_t *vm, njs_parser_t *parser, nxt_uint_t *level) { nxt_int_t ret; diff -r f0c94dd2bdb3 -r cdb8d20935ee njs/njs_variable.h --- a/njs/njs_variable.hFri Jul 22 14:15:54 2016 +0300 +++ b/njs/njs_variable.hFri Jul 22 14:38:06 2016 +0300 @@ -26,6 +26,7 @@ typedef struct { } njs_variable_t; +njs_variable_t *njs_parser_name_alloc(njs_vm_t *vm, njs_parser_t *parser); njs_variable_t *njs_parser_variable(njs_vm_t *vm, njs_parser_t *parser, nxt_uint_t *level); njs_value_t *njs_variable_value(njs_parser_t *parser, njs_index_t index); diff -r f0c94dd2bdb3 -r cdb8d20935ee njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Fri Jul 22 14:15:54 2016 +0300 +++ b/njs/test/njs_unit_test.c Fri Jul 22 14:38:06 2016 +0300 @@ -67,6 +67,15 @@ static njs_unit_test_t njs_test[] = { nxt_string("var a = 1; var b; a"), nxt_string("1") }, +{ nxt_string("function f(){} function f(){}"), + nxt_string("SyntaxError: Duplicate declaration \"f\" in 1") }, + +{ nxt_string("var f = 1; function f() {}"), + nxt_string("SyntaxError: Duplicate declaration \"f\" in 1") }, + +{ nxt_string("function f() {} var f = 1; f"), + nxt_string("1") }, + /* Numbers. */ { nxt_string("9"), ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] njs_vm_function() must return only function.
details: http://hg.nginx.org/njs/rev/f59ab0fccecb branches: changeset: 128:f59ab0fccecb user: Igor Sysoev <i...@sysoev.ru> date: Thu Jul 21 20:51:22 2016 +0300 description: njs_vm_function() must return only function. diffstat: njs/njs_variable.c | 6 +- 1 files changed, 5 insertions(+), 1 deletions(-) diffs (16 lines): diff -r 1cfc38ab7ba1 -r f59ab0fccecb njs/njs_variable.c --- a/njs/njs_variable.cThu Jul 21 11:39:00 2016 +0300 +++ b/njs/njs_variable.cThu Jul 21 20:51:22 2016 +0300 @@ -139,7 +139,11 @@ njs_vm_function(njs_vm_t *vm, nxt_str_t value = (njs_value_t *) ((u_char *) vm->global_scope + njs_offset(var->index) - NJS_INDEX_GLOBAL_OFFSET); -return value->data.u.function; +if (njs_is_function(value)) { +return value->data.u.function; +} + +return NULL; } ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] njs_vm_function() and njs_vm_external() functions name and
details: http://hg.nginx.org/njs/rev/a3e7ebdf9fa7 branches: changeset: 122:a3e7ebdf9fa7 user: Igor Sysoev <i...@sysoev.ru> date: Fri Jul 15 15:50:13 2016 +0300 description: njs_vm_function() and njs_vm_external() functions name and behavior unification. The function can be used with both original compiled VM and its clones. diffstat: nginx/ngx_http_js_module.c | 8 njs/njs_extern.c | 6 +++--- njs/njs_variable.c | 4 ++-- njs/njscript.c | 1 + njs/njscript.h | 4 ++-- njs/test/njs_unit_test.c | 6 +++--- 6 files changed, 15 insertions(+), 14 deletions(-) diffs (126 lines): diff -r 74246210aa9d -r a3e7ebdf9fa7 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.cThu Jul 14 19:24:51 2016 +0300 +++ b/nginx/ngx_http_js_module.cFri Jul 15 15:50:13 2016 +0300 @@ -1152,8 +1152,8 @@ ngx_http_js_compile(ngx_conf_t *cf, ngx_ nxt_lvlhsh_init(); -if (njs_add_external(, mcp, 0, ngx_http_js_externals, - nxt_nitems(ngx_http_js_externals)) +if (njs_vm_external_add(, mcp, 0, ngx_http_js_externals, +nxt_nitems(ngx_http_js_externals)) != NJS_OK) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "could not add js externals"); @@ -1191,7 +1191,7 @@ ngx_http_js_compile(ngx_conf_t *cf, ngx_ if (function) { ngx_str_set(, "$r"); -rc = njs_external_get(vm, NULL, , >args[0]); +rc = njs_vm_external(vm, NULL, , >args[0]); if (rc != NXT_OK) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "could not get $r external"); @@ -1200,7 +1200,7 @@ ngx_http_js_compile(ngx_conf_t *cf, ngx_ ngx_str_set(, "response"); -rc = njs_external_get(vm, >args[0], , >args[1]); +rc = njs_vm_external(vm, >args[0], , >args[1]); if (rc != NXT_OK) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "could not get $r.response external"); diff -r 74246210aa9d -r a3e7ebdf9fa7 njs/njs_extern.c --- a/njs/njs_extern.c Thu Jul 14 19:24:51 2016 +0300 +++ b/njs/njs_extern.c Fri Jul 15 15:50:13 2016 +0300 @@ -51,7 +51,7 @@ const nxt_lvlhsh_proto_t njs_extern_has nxt_int_t -njs_add_external(nxt_lvlhsh_t *hash, nxt_mem_cache_pool_t *mcp, +njs_vm_external_add(nxt_lvlhsh_t *hash, nxt_mem_cache_pool_t *mcp, uintptr_t object, njs_external_t *external, nxt_uint_t n) { nxt_int_t ret; @@ -111,7 +111,7 @@ njs_add_external(nxt_lvlhsh_t *hash, nxt } if (external->properties != NULL) { -ret = njs_add_external(>hash, mcp, object, +ret = njs_vm_external_add(>hash, mcp, object, external->properties, external->nproperties); if (nxt_slow_path(ret != NXT_OK)) { return ret; @@ -128,7 +128,7 @@ njs_add_external(nxt_lvlhsh_t *hash, nxt nxt_int_t -njs_external_get(njs_vm_t *vm, njs_opaque_value_t *obj, nxt_str_t *property, +njs_vm_external(njs_vm_t *vm, njs_opaque_value_t *obj, nxt_str_t *property, njs_opaque_value_t *value) { uint32_t(*key_hash)(const void *, size_t); diff -r 74246210aa9d -r a3e7ebdf9fa7 njs/njs_variable.c --- a/njs/njs_variable.cThu Jul 14 19:24:51 2016 +0300 +++ b/njs/njs_variable.cFri Jul 15 15:50:13 2016 +0300 @@ -136,8 +136,8 @@ njs_vm_function(njs_vm_t *vm, nxt_str_t var = lhq.value; -value = (njs_value_t *) ((u_char *) vm->scopes[NJS_SCOPE_GLOBAL] - + njs_offset(var->index)); +value = (njs_value_t *) ((u_char *) vm->global_scope + + njs_offset(var->index) - NJS_INDEX_GLOBAL_OFFSET); return value->data.u.function; } diff -r 74246210aa9d -r a3e7ebdf9fa7 njs/njscript.c --- a/njs/njscript.cThu Jul 14 19:24:51 2016 +0300 +++ b/njs/njscript.cFri Jul 15 15:50:13 2016 +0300 @@ -280,6 +280,7 @@ njs_vm_clone(njs_vm_t *vm, nxt_mem_cache nvm->variables_hash = vm->variables_hash; nvm->values_hash = vm->values_hash; +nvm->externals_hash = vm->externals_hash; nvm->retval = njs_value_void; nvm->current = vm->current; diff -r 74246210aa9d -r a3e7ebdf9fa7 njs/njscript.h --- a/njs/njscript.hThu Jul 14 19:24:51 2016 +0300 +++ b/njs/njscript.hFri Jul 15 15:50:13 2016 +0300 @@ -73,10 +73,10 @@ struct njs_external_s { #define NJS_DONENXT_DONE -NXT_EXPORT nxt_int_t njs_add_external(nxt_lvlhsh_t *hash, +NXT_EXPORT nxt_int_t njs_vm_external_add(nxt_lvlhsh_t *hash, nxt_mem_cache_pool_t *mcp, uintptr_t object, njs_external_t *external, nxt_uint_t n); -NXT_EXPORT nxt_int_t njs_external_get(njs_vm_t *vm, njs_opaque_value_t *object, +NXT_EXPORT nxt_int_t njs_vm_external(nj
[njs] njs_vm_function() interface to get a function by name.
details: http://hg.nginx.org/njs/rev/74246210aa9d branches: changeset: 121:74246210aa9d user: Igor Sysoev <i...@sysoev.ru> date: Thu Jul 14 19:24:51 2016 +0300 description: njs_vm_function() interface to get a function by name. diffstat: njs/njs_variable.c | 24 njs/njscript.h | 1 + 2 files changed, 25 insertions(+), 0 deletions(-) diffs (45 lines): diff -r 07d2be75a7db -r 74246210aa9d njs/njs_variable.c --- a/njs/njs_variable.cWed Jul 13 13:56:12 2016 +0300 +++ b/njs/njs_variable.cThu Jul 14 19:24:51 2016 +0300 @@ -119,6 +119,30 @@ njs_parser_variable(njs_vm_t *vm, njs_pa } +njs_function_t * +njs_vm_function(njs_vm_t *vm, nxt_str_t *name) +{ +njs_value_t *value; +njs_variable_t *var; +nxt_lvlhsh_query_t lhq; + +lhq.key_hash = nxt_djb_hash(name->data, name->len); +lhq.key = *name; +lhq.proto = _variables_hash_proto; + +if (nxt_slow_path(nxt_lvlhsh_find(>variables_hash, ) != NXT_OK)) { +return NULL; +} + +var = lhq.value; + +value = (njs_value_t *) ((u_char *) vm->scopes[NJS_SCOPE_GLOBAL] + + njs_offset(var->index)); + +return value->data.u.function; +} + + static njs_variable_t * njs_variable_alloc(njs_vm_t *vm, njs_parser_t *parser, nxt_str_t *name) { diff -r 07d2be75a7db -r 74246210aa9d njs/njscript.h --- a/njs/njscript.hWed Jul 13 13:56:12 2016 +0300 +++ b/njs/njscript.hThu Jul 14 19:24:51 2016 +0300 @@ -91,6 +91,7 @@ NXT_EXPORT nxt_int_t njs_vm_call(njs_vm_ njs_opaque_value_t *args, nxt_uint_t nargs); NXT_EXPORT nxt_int_t njs_vm_run(njs_vm_t *vm); +NXT_EXPORT njs_function_t *njs_vm_function(njs_vm_t *vm, nxt_str_t *name); NXT_EXPORT njs_ret_t njs_vm_return_string(njs_vm_t *vm, u_char *start, size_t size); NXT_EXPORT nxt_int_t njs_vm_retval(njs_vm_t *vm, nxt_str_t *retval); ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Syntax error messages are more verbose and have line number.
details: http://hg.nginx.org/njs/rev/07d2be75a7db branches: changeset: 120:07d2be75a7db user: Igor Sysoev <i...@sysoev.ru> date: Wed Jul 13 13:56:12 2016 +0300 description: Syntax error messages are more verbose and have line number. diffstat: njs/njs_builtin.c |2 + njs/njs_generator.c | 66 +++-- njs/njs_lexer.c | 23 - njs/njs_nonrecursive_parser.c |2 +- njs/njs_parser.c | 187 - njs/njs_parser.h | 16 +++ njs/njs_parser_expression.c | 35 ++- njs/njs_regexp.c | 89 +++ njs/njs_regexp.h |3 +- njs/njs_string.c | 60 + njs/njs_string.h |2 - njs/njs_vm.c | 24 +- njs/njs_vm.h |7 +- njs/njscript.c|3 +- njs/test/njs_unit_test.c | 100 +- 15 files changed, 442 insertions(+), 177 deletions(-) diffs (truncated from 1568 to 1000 lines): diff -r 5e7e498eb90d -r 07d2be75a7db njs/njs_builtin.c --- a/njs/njs_builtin.c Mon Jul 11 15:24:29 2016 +0300 +++ b/njs/njs_builtin.c Wed Jul 13 13:56:12 2016 +0300 @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include diff -r 5e7e498eb90d -r 07d2be75a7db njs/njs_generator.c --- a/njs/njs_generator.c Mon Jul 11 15:24:29 2016 +0300 +++ b/njs/njs_generator.c Wed Jul 13 13:56:12 2016 +0300 @@ -20,6 +20,13 @@ #include #include #include +#include + + +typedef enum { +NJS_GENERATOR_ERROR_ILLEGAL_CONTINUE = 0, +NJS_GENERATOR_ERROR_ILLEGAL_BREAK, +} njs_generator_error_t; static nxt_int_t njs_generator(njs_vm_t *vm, njs_parser_t *parser, @@ -117,6 +124,8 @@ static nxt_noinline nxt_int_t njs_genera static nxt_noinline nxt_int_t njs_generator_index_release(njs_vm_t *vm, njs_parser_t *parser, njs_index_t index); nxt_inline nxt_bool_t njs_generator_is_constant(njs_parser_node_t *node); +static nxt_int_t njs_generator_error(njs_vm_t *vm, njs_parser_node_t *node, +njs_generator_error_t err); static const nxt_str_t no_label = { 0, NULL }; @@ -1067,19 +1076,20 @@ njs_generate_continue_statement(njs_vm_t { njs_vmcode_jump_t *jump; njs_parser_patch_t *patch; - -if (parser->block == NULL) { -vm->exception = _exception_syntax_error; -return NXT_ERROR; +njs_parser_block_t *block; + +for (block = parser->block; block != NULL; block = block->next) { +if (block->type == NJS_PARSER_LOOP) { +goto found; +} } +return njs_generator_error(vm, node, NJS_GENERATOR_ERROR_ILLEGAL_CONTINUE); + +found: + /* TODO: LABEL */ -if (parser->block->type != NJS_PARSER_LOOP) { -vm->exception = _exception_syntax_error; -return NXT_ERROR; -} - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_parser_patch_t)); if (nxt_fast_path(patch != NULL)) { @@ -1105,12 +1115,20 @@ njs_generate_break_statement(njs_vm_t *v { njs_vmcode_jump_t *jump; njs_parser_patch_t *patch; - -if (parser->block == NULL) { -vm->exception = _exception_syntax_error; -return NXT_ERROR; +njs_parser_block_t *block; + +for (block = parser->block; block != NULL; block = block->next) { +if (block->type == NJS_PARSER_LOOP +|| block->type == NJS_PARSER_SWITCH) +{ +goto found; +} } +return njs_generator_error(vm, node, NJS_GENERATOR_ERROR_ILLEGAL_BREAK); + +found: + /* TODO: LABEL: loop and switch may have label, block must have label. */ patch = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_parser_patch_t)); @@ -2466,3 +2484,25 @@ njs_generator_is_constant(njs_parser_nod return (node->token >= NJS_TOKEN_FIRST_CONST && node->token <= NJS_TOKEN_LAST_CONST); } + + +static nxt_int_t +njs_generator_error(njs_vm_t *vm, njs_parser_node_t *node, +njs_generator_error_t err) +{ +uint32_t size; +const char *msg; +u_char buf[NJS_EXCEPTION_BUF_LENGTH]; + +static const char *errors[] = { +"SyntaxError: Illegal continue statement in %u", +"SyntaxError: Illegal break statement in %u", +}; + +msg = errors[err]; + +size = snprintf((char *) buf, NJS_EXCEPTION_BUF_LENGTH, +msg, node->token_line); + +return njs_vm_throw_exception(vm, buf, size); +} diff -r 5e7e498eb90d -r 07d2be75a7db njs/njs_lexer.c --- a/njs/njs_lexer.c Mon Jul 11 15:24:29 2016 +0300 +++ b/njs/njs_lexer.c Wed Jul 13 13:56:12 2016 +0300 @@ -47,7 +47,7 @@ static const uint8_t njs_tokens[256] n NJS_TOKEN_ILLEGAL, NJS_TOKEN_ILLEGAL, /* \t */NJS_TOKEN_ILLEGAL, NJS_TOKEN_SPACE,
[njs] Fixed building by modern GCC versions.
details: http://hg.nginx.org/njs/rev/5e7e498eb90d branches: changeset: 119:5e7e498eb90d user: Igor Sysoev <i...@sysoev.ru> date: Mon Jul 11 15:24:29 2016 +0300 description: Fixed building by modern GCC versions. diffstat: njs/njs_string.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diffs (30 lines): diff -r e4a0f80610b2 -r 5e7e498eb90d njs/njs_string.c --- a/njs/njs_string.c Fri Jul 08 18:13:00 2016 +0300 +++ b/njs/njs_string.c Mon Jul 11 15:24:29 2016 +0300 @@ -1657,7 +1657,7 @@ njs_string_prototype_split(njs_vm_t *vm, { int ret, *captures; u_char*p, *start, *next; -size_tsize, length; +size_tsize; uint32_t limit; nxt_uint_tn, utf8; njs_array_t *array; @@ -1683,7 +1683,7 @@ njs_string_prototype_split(njs_vm_t *vm, limit = (uint32_t) -1; } -length = njs_string_prop(, [0]); +(void) njs_string_prop(, [0]); if (string.size == 0) { goto single; @@ -1818,7 +1818,7 @@ static njs_ret_t njs_string_split_part_add(njs_vm_t *vm, njs_array_t *array, u_char *start, size_t size, nxt_uint_t utf8) { -uint32_t length; +ssize_t length; switch (utf8) { case 0: ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Needless argument checkers for String.toLowerCase()
details: http://hg.nginx.org/njs/rev/e4a0f80610b2 branches: changeset: 118:e4a0f80610b2 user: Igor Sysoev <i...@sysoev.ru> date: Fri Jul 08 18:13:00 2016 +0300 description: Needless argument checkers for String.toLowerCase() and String.toUpperCase() have been removed. diffstat: njs/njs_string.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (20 lines): diff -r 6888c62477a0 -r e4a0f80610b2 njs/njs_string.c --- a/njs/njs_string.c Fri Jul 08 18:07:57 2016 +0300 +++ b/njs/njs_string.c Fri Jul 08 18:13:00 2016 +0300 @@ -2075,14 +2075,14 @@ static const njs_object_prop_t njs_stri .type = NJS_METHOD, .name = njs_string("toLowerCase"), .value = njs_native_function(njs_string_prototype_to_lower_case, 0, - NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG), + NJS_STRING_OBJECT_ARG), }, { .type = NJS_METHOD, .name = njs_string("toUpperCase"), .value = njs_native_function(njs_string_prototype_to_upper_case, 0, - NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG), + NJS_STRING_OBJECT_ARG), }, { ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Now ASCII strings use UTF8 variant of PCRE code.
details: http://hg.nginx.org/njs/rev/6888c62477a0 branches: changeset: 117:6888c62477a0 user: Igor Sysoev <i...@sysoev.ru> date: Fri Jul 08 18:07:57 2016 +0300 description: Now ASCII strings use UTF8 variant of PCRE code. diffstat: njs/njs_regexp.c | 5 - njs/njs_string.c | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diffs (55 lines): diff -r 73dc069a08c0 -r 6888c62477a0 njs/njs_regexp.c --- a/njs/njs_regexp.c Thu Jul 07 20:49:57 2016 +0300 +++ b/njs/njs_regexp.c Fri Jul 08 18:07:57 2016 +0300 @@ -476,7 +476,7 @@ njs_regexp_prototype_test(njs_vm_t *vm, (void) njs_string_prop(, value); -n = (string.length != 0 && string.length != string.size); +n = (string.length != 0); pattern = args[0].data.u.regexp->pattern; @@ -527,14 +527,17 @@ njs_regexp_prototype_exec(njs_vm_t *vm, (void) njs_string_prop(, value); +/* Byte string. */ utf8 = 0; n = 0; if (string.length != 0) { +/* ASCII string. */ utf8 = 1; n = 1; if (string.length != string.size) { +/* UTF-8 string. */ utf8 = 2; } } diff -r 73dc069a08c0 -r 6888c62477a0 njs/njs_string.c --- a/njs/njs_string.c Thu Jul 07 20:49:57 2016 +0300 +++ b/njs/njs_string.c Fri Jul 08 18:07:57 2016 +0300 @@ -1450,7 +1450,7 @@ njs_string_prototype_search(njs_vm_t *vm (void) njs_string_prop(, [0]); -n = (string.length != 0 && string.length != string.size); +n = (string.length != 0); if (nxt_regex_is_valid(>regex[n])) { ret = nxt_regex_match(>regex[n], string.start, string.size, @@ -1696,11 +1696,11 @@ njs_string_prototype_split(njs_vm_t *vm, if (string.length != 0) { /* ASCII string. */ utf8 = 1; -n = 1; if (string.length != string.size) { /* UTF-8 string. */ utf8 = 2; +n = 1; } } ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Byte string processing was fixed in String.split(),
details: http://hg.nginx.org/njs/rev/73dc069a08c0 branches: changeset: 116:73dc069a08c0 user: Igor Sysoev <i...@sysoev.ru> date: Thu Jul 07 20:49:57 2016 +0300 description: Byte string processing was fixed in String.split(), the issue has been found by Coverity Scan. diffstat: njs/njs_string.c | 69 ++- njs/test/njs_unit_test.c | 3 ++ 2 files changed, 59 insertions(+), 13 deletions(-) diffs (139 lines): diff -r ef2b708510b1 -r 73dc069a08c0 njs/njs_string.c --- a/njs/njs_string.c Wed Jun 29 13:38:20 2016 +0300 +++ b/njs/njs_string.c Thu Jul 07 20:49:57 2016 +0300 @@ -40,6 +40,8 @@ static njs_ret_t njs_string_prototype_fr njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); static nxt_noinline ssize_t njs_string_index_of(njs_vm_t *vm, njs_value_t *src, njs_value_t *search_string, size_t index); +static njs_ret_t njs_string_split_part_add(njs_vm_t *vm, njs_array_t *array, +u_char *start, size_t size, nxt_uint_t utf8); njs_ret_t @@ -1657,7 +1659,7 @@ njs_string_prototype_split(njs_vm_t *vm, u_char*p, *start, *next; size_tsize, length; uint32_t limit; -nxt_uint_tn; +nxt_uint_tn, utf8; njs_array_t *array; const u_char *end; njs_string_prop_t string, split; @@ -1681,13 +1683,32 @@ njs_string_prototype_split(njs_vm_t *vm, limit = (uint32_t) -1; } +length = njs_string_prop(, [0]); + +if (string.size == 0) { +goto single; +} + +/* Byte string. */ +utf8 = 0; +n = 0; + +if (string.length != 0) { +/* ASCII string. */ +utf8 = 1; +n = 1; + +if (string.length != string.size) { +/* UTF-8 string. */ +utf8 = 2; +} +} + switch (args[1].type) { case NJS_STRING: (void) njs_string_prop(, [1]); -length = njs_string_prop(, [0]); - if (string.size < split.size) { goto single; } @@ -1711,9 +1732,8 @@ njs_string_prototype_split(njs_vm_t *vm, } size = p - start; -length = nxt_utf8_length(start, size); - -ret = njs_array_string_add(vm, array, start, size, length); + +ret = njs_string_split_part_add(vm, array, start, size, utf8); if (nxt_slow_path(ret != NXT_OK)) { return ret; } @@ -1728,10 +1748,6 @@ njs_string_prototype_split(njs_vm_t *vm, case NJS_REGEXP: pattern = args[1].data.u.regexp->pattern; -(void) njs_string_prop(, [0]); - -n = (string.length != 0 && string.length != string.size); - if (!nxt_regex_is_valid(>regex[n])) { goto single; } @@ -1764,9 +1780,8 @@ njs_string_prototype_split(njs_vm_t *vm, } size = p - start; -length = nxt_utf8_length(start, size); - -ret = njs_array_string_add(vm, array, start, size, length); + +ret = njs_string_split_part_add(vm, array, start, size, utf8); if (nxt_slow_path(ret != NXT_OK)) { return ret; } @@ -1799,6 +1814,34 @@ done: } +static njs_ret_t +njs_string_split_part_add(njs_vm_t *vm, njs_array_t *array, u_char *start, +size_t size, nxt_uint_t utf8) +{ +uint32_t length; + +switch (utf8) { +case 0: +length = 0; +break; + +case 1: +length = size; +break; + +default: +length = nxt_utf8_length(start, size); + +if (nxt_slow_path(length < 0)) { +vm->exception = _exception_internal_error; +return NXT_ERROR; +} +} + +return njs_array_string_add(vm, array, start, size, length); +} + + njs_ret_t njs_primitive_value_to_string(njs_vm_t *vm, njs_value_t *dst, const njs_value_t *src) diff -r ef2b708510b1 -r 73dc069a08c0 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Wed Jun 29 13:38:20 2016 +0300 +++ b/njs/test/njs_unit_test.c Thu Jul 07 20:49:57 2016 +0300 @@ -2951,6 +2951,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("'abc'.split('')"), nxt_string("a,b,c") }, +{ nxt_string("'abc'.split('abc')"), + nxt_string(",") }, + { nxt_string("'a bc def'.split(' ')"), nxt_string("a,bc,def") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Array.reverse() method.
details: http://hg.nginx.org/njs/rev/ef2b708510b1 branches: changeset: 115:ef2b708510b1 user: Igor Sysoev <i...@sysoev.ru> date: Wed Jun 29 13:38:20 2016 +0300 description: Array.reverse() method. diffstat: njs/njs_array.c | 40 njs/test/njs_unit_test.c | 18 ++ 2 files changed, 58 insertions(+), 0 deletions(-) diffs (92 lines): diff -r 41404eee5063 -r ef2b708510b1 njs/njs_array.c --- a/njs/njs_array.c Tue Jun 28 19:28:00 2016 +0300 +++ b/njs/njs_array.c Wed Jun 29 13:38:20 2016 +0300 @@ -464,6 +464,39 @@ njs_array_prototype_shift(njs_vm_t *vm, } +static njs_ret_t +njs_array_prototype_reverse(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, +njs_index_t unused) +{ +nxt_uint_t i, n, length; +njs_value_t value; +njs_array_t *array; + +if (njs_is_array([0])) { +array = args[0].data.u.array; +length = array->length; + +if (length > 1) { +for (i = 0, n = length - 1; i < n; i++, n--) { +value = array->start[i]; +array->start[i] = array->start[n]; +array->start[n] = value; +} +} + +vm->retval.data.u.array = array; +vm->retval.type = NJS_ARRAY; +vm->retval.data.truth = 1; + +} else { +/* STUB */ +vm->retval = args[0]; +} + +return NXT_OK; +} + + /* * ECMAScript 5.1: try first to use object method "join", then * use the standard built-in method Object.prototype.toString(). @@ -971,6 +1004,13 @@ static const njs_object_prop_t njs_arra { .type = NJS_METHOD, +.name = njs_string("reverse"), +.value = njs_native_function(njs_array_prototype_reverse, 0, +NJS_OBJECT_ARG), +}, + +{ +.type = NJS_METHOD, .name = njs_string("toString"), .value = njs_native_function(njs_array_prototype_to_string, NJS_CONTINUATION_SIZE, 0), diff -r 41404eee5063 -r ef2b708510b1 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Tue Jun 28 19:28:00 2016 +0300 +++ b/njs/test/njs_unit_test.c Wed Jun 29 13:38:20 2016 +0300 @@ -2186,6 +2186,21 @@ static njs_unit_test_t njs_test[] = "len +' '+ a +' '+ a.shift()"), nxt_string("5 3,4,5,1,2 3") }, +{ nxt_string("var a = []; a.reverse()"), + nxt_string("") }, + +{ nxt_string("var a = [1]; a.reverse()"), + nxt_string("1") }, + +{ nxt_string("var a = [1,2]; a.reverse()"), + nxt_string("2,1") }, + +{ nxt_string("var a = [1,2,3]; a.reverse()"), + nxt_string("3,2,1") }, + +{ nxt_string("var a = [1,2,3,4]; a.reverse()"), + nxt_string("4,3,2,1") }, + { nxt_string("var a = []; var s = { sum: 0 };" "a.forEach(function(v, i, a) { this.sum += v }, s); s.sum"), nxt_string("0") }, @@ -2966,6 +2981,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("'abc'.split(/abc/)"), nxt_string(",") }, +{ nxt_string("'0123456789'.split('').reverse().join('')"), + nxt_string("9876543210") }, + /* Functions. */ { nxt_string("function f() { } f()"), ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] String.split() method.
details: http://hg.nginx.org/njs/rev/41404eee5063 branches: changeset: 114:41404eee5063 user: Igor Sysoev <i...@sysoev.ru> date: Tue Jun 28 19:28:00 2016 +0300 description: String.split() method. diffstat: njs/njs_array.c | 62 + njs/njs_array.h |2 + njs/njs_string.c | 161 +++ njs/njscript.h |3 - njs/test/njs_unit_test.c | 42 5 files changed, 223 insertions(+), 47 deletions(-) diffs (333 lines): diff -r c72fd0d1fabc -r 41404eee5063 njs/njs_array.c --- a/njs/njs_array.c Wed Jun 01 15:31:34 2016 +0300 +++ b/njs/njs_array.c Tue Jun 28 19:28:00 2016 +0300 @@ -63,50 +63,6 @@ static nxt_noinline njs_ret_t njs_array_ njs_array_next_t *next, njs_value_t *args, nxt_uint_t nargs); -njs_value_t * -njs_array_add(njs_vm_t *vm, njs_value_t *value, u_char *start, size_t size) -{ -njs_ret_tret; -njs_array_t *array; - -if (value != NULL) { -array = value->data.u.array; - -if (array->size == array->length) { -ret = njs_array_realloc(vm, array, 0, array->size + 1); -if (nxt_slow_path(ret != NXT_OK)) { -return NULL; -} -} - -} else { -value = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), -sizeof(njs_value_t)); - -if (nxt_slow_path(value == NULL)) { -return NULL; -} - -array = njs_array_alloc(vm, 0, NJS_ARRAY_SPARE); -if (nxt_slow_path(array == NULL)) { -return NULL; -} - -value->data.u.array = array; -value->type = NJS_ARRAY; -value->data.truth = 1; -} - -ret = njs_string_create(vm, >start[array->length++], start, size, 0); - -if (nxt_fast_path(ret == NXT_OK)) { -return value; -} - -return NULL; -} - - nxt_noinline njs_array_t * njs_array_alloc(njs_vm_t *vm, uint32_t length, uint32_t spare) { @@ -139,6 +95,24 @@ njs_array_alloc(njs_vm_t *vm, uint32_t l njs_ret_t +njs_array_string_add(njs_vm_t *vm, njs_array_t *array, u_char *start, +size_t size, size_t length) +{ +njs_ret_t ret; + +if (array->size == array->length) { +ret = njs_array_realloc(vm, array, 0, array->size + 1); +if (nxt_slow_path(ret != NXT_OK)) { +return ret; +} +} + +return njs_string_create(vm, >start[array->length++], +start, size, length); +} + + +njs_ret_t njs_array_realloc(njs_vm_t *vm, njs_array_t *array, uint32_t prepend, uint32_t size) { diff -r c72fd0d1fabc -r 41404eee5063 njs/njs_array.h --- a/njs/njs_array.h Wed Jun 01 15:31:34 2016 +0300 +++ b/njs/njs_array.h Tue Jun 28 19:28:00 2016 +0300 @@ -21,6 +21,8 @@ struct njs_array_s { njs_array_t *njs_array_alloc(njs_vm_t *vm, uint32_t length, uint32_t spare); +njs_ret_t njs_array_string_add(njs_vm_t *vm, njs_array_t *array, u_char *start, +size_t size, size_t length); njs_ret_t njs_array_realloc(njs_vm_t *vm, njs_array_t *array, uint32_t prepend, uint32_t size); njs_ret_t njs_array_constructor(njs_vm_t *vm, njs_value_t *args, diff -r c72fd0d1fabc -r 41404eee5063 njs/njs_string.c --- a/njs/njs_string.c Wed Jun 01 15:31:34 2016 +0300 +++ b/njs/njs_string.c Tue Jun 28 19:28:00 2016 +0300 @@ -1645,6 +1645,160 @@ empty: } +/* + * String.split([string|regexp[, limit]]) + */ + +static njs_ret_t +njs_string_prototype_split(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, +njs_index_t unused) +{ +int ret, *captures; +u_char*p, *start, *next; +size_tsize, length; +uint32_t limit; +nxt_uint_tn; +njs_array_t *array; +const u_char *end; +njs_string_prop_t string, split; +njs_regexp_pattern_t *pattern; + +array = njs_array_alloc(vm, 0, NJS_ARRAY_SPARE); +if (nxt_slow_path(array == NULL)) { +return NXT_ERROR; +} + +if (nargs > 1) { + +if (nargs > 2) { +limit = args[2].data.u.number; + +if (limit == 0) { +goto done; +} + +} else { +limit = (uint32_t) -1; +} + +switch (args[1].type) { + +case NJS_STRING: +(void) njs_string_prop(, [1]); + +length = njs_string_prop(, [0]); + +if (string.size < split.size) { +goto single; +} + +start = string.start; +end = string.start + string.size; + +do { +for (p = start; p < end; p++) { +if (memcmp(p, split.start, split.size) == 0) { +break; +} +} + +next = p + split.size; + +
[njs] Using nxt_regex interface in nJSVM.
details: http://hg.nginx.org/njs/rev/c72fd0d1fabc branches: changeset: 113:c72fd0d1fabc user: Igor Sysoev <i...@sysoev.ru> date: Wed Jun 01 15:31:34 2016 +0300 description: Using nxt_regex interface in nJSVM. diffstat: Makefile |2 + njs/njs_disassembler.c |1 - njs/njs_lexer_keyword.c |1 - njs/njs_regexp.c | 238 -- njs/njs_regexp.h |3 +- njs/njs_regexp_pattern.h |4 +- njs/njs_string.c | 91 + njs/njs_string.h |2 + njs/njs_vm.h | 13 ++- njs/njscript.c | 15 +- njs/test/njs_unit_test.c |3 + 11 files changed, 205 insertions(+), 168 deletions(-) diffs (773 lines): diff -r b8084a72d667 -r c72fd0d1fabc Makefile --- a/Makefile Wed Jun 01 15:30:50 2016 +0300 +++ b/Makefile Wed Jun 01 15:31:34 2016 +0300 @@ -36,6 +36,7 @@ NXT_BUILDDIR =build $(NXT_BUILDDIR)/nxt_rbtree.o \ $(NXT_BUILDDIR)/nxt_lvlhsh.o \ $(NXT_BUILDDIR)/nxt_random.o \ + $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ @@ -67,6 +68,7 @@ NXT_BUILDDIR =build $(NXT_BUILDDIR)/nxt_rbtree.o \ $(NXT_BUILDDIR)/nxt_lvlhsh.o \ $(NXT_BUILDDIR)/nxt_random.o \ + $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ diff -r b8084a72d667 -r c72fd0d1fabc njs/njs_disassembler.c --- a/njs/njs_disassembler.cWed Jun 01 15:30:50 2016 +0300 +++ b/njs/njs_disassembler.cWed Jun 01 15:31:34 2016 +0300 @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff -r b8084a72d667 -r c72fd0d1fabc njs/njs_lexer_keyword.c --- a/njs/njs_lexer_keyword.c Wed Jun 01 15:30:50 2016 +0300 +++ b/njs/njs_lexer_keyword.c Wed Jun 01 15:31:34 2016 +0300 @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include diff -r b8084a72d667 -r c72fd0d1fabc njs/njs_regexp.c --- a/njs/njs_regexp.c Wed Jun 01 15:30:50 2016 +0300 +++ b/njs/njs_regexp.c Wed Jun 01 15:31:34 2016 +0300 @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -30,17 +31,51 @@ #include +static void *njs_regexp_malloc(size_t size, void *memory_data); +static void njs_regexp_free(void *p, void *memory_data); static njs_regexp_flags_t njs_regexp_flags(u_char **start, u_char *end, nxt_bool_t bound); -static int njs_regexp_pattern_compile(pcre **code, pcre_extra **extra, +static int njs_regexp_pattern_compile(njs_vm_t *vm, nxt_regex_t *regex, u_char *source, int options); static njs_ret_t njs_regexp_exec_result(njs_vm_t *vm, njs_regexp_t *regexp, -u_char *string, int *captures, nxt_uint_t utf8); +u_char *string, nxt_regex_match_data_t *match_data, nxt_uint_t utf8); static njs_ret_t njs_regexp_string_create(njs_vm_t *vm, njs_value_t *value, u_char *start, uint32_t size, int32_t length); njs_ret_t +njs_regexp_init(njs_vm_t *vm) +{ +vm->regex_context = nxt_regex_context_create(njs_regexp_malloc, + njs_regexp_free, vm->mem_cache_pool); +if (nxt_slow_path(vm->regex_context == NULL)) { +return NXT_ERROR; +} + +vm->single_match_data = nxt_regex_match_data(NULL, vm->regex_context); +if (nxt_slow_path(vm->single_match_data == NULL)) { +return NXT_ERROR; +} + +return NXT_OK; +} + + +static void * +njs_regexp_malloc(size_t size, void *memory_data) +{ +return nxt_mem_cache_alloc(memory_data, size); +} + + +static void +njs_regexp_free(void *p, void *memory_data) +{ +nxt_mem_cache_free(memory_data, p); +} + + +njs_ret_t njs_regexp_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { @@ -205,18 +240,14 @@ njs_regexp_pattern_create(njs_vm_t *vm, size += ((flags & NJS_REGEXP_IGNORE_CASE) != 0); size += ((flags & NJS_REGEXP_MULTILINE) != 0); -pattern = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_regexp_pattern_t) - + 1 + length + size + 1); +pattern = nxt_mem_cache_zalloc(vm->mem_cache_pool, + sizeof(njs_regexp_pattern_t) + + 1 + length + size + 1); if (nxt_slow_path(pattern == NULL)) { return NULL; } pattern->flags = size; -pattern->code[0] = NULL; -pattern->code[1] = NULL; -pattern->extra[0] = NULL; -pattern->extra[1] = NULL; pattern->next = NULL; p = (u_char *) pattern + sizeof(njs_regexp_pattern_t); @@ -254,18 +285,16 @@ njs_regexp_pattern_create(njs_vm_t *vm, *p++ = '\0'; -ret = njs_regexp_pattern_compile(>code[0], &g
[njs] PCRE code is available via nxt_regex interface.
details: http://hg.nginx.org/njs/rev/b8084a72d667 branches: changeset: 112:b8084a72d667 user: Igor Sysoev <i...@sysoev.ru> date: Wed Jun 01 15:30:50 2016 +0300 description: PCRE code is available via nxt_regex interface. diffstat: nxt/Makefile| 35 +-- nxt/nxt_pcre.c | 259 nxt/nxt_pcre.h | 34 +++ nxt/nxt_regex.h | 42 + 4 files changed, 359 insertions(+), 11 deletions(-) diffs (414 lines): diff -r 1c96b24bcdd2 -r b8084a72d667 nxt/Makefile --- a/nxt/Makefile Fri Apr 29 17:02:52 2016 +0300 +++ b/nxt/Makefile Wed Jun 01 15:30:50 2016 +0300 @@ -10,6 +10,7 @@ NXT_LIB = nxt $(NXT_BUILDDIR)/nxt_rbtree.o \ $(NXT_BUILDDIR)/nxt_lvlhsh.o \ $(NXT_BUILDDIR)/nxt_random.o \ + $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ @@ -19,8 +20,9 @@ NXT_LIB = nxt $(NXT_BUILDDIR)/nxt_array.o \ $(NXT_BUILDDIR)/nxt_rbtree.o \ $(NXT_BUILDDIR)/nxt_lvlhsh.o \ + $(NXT_BUILDDIR)/nxt_random.o \ + $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ - $(NXT_BUILDDIR)/nxt_random.o \ $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ $(NXT_BUILDDIR)/nxt_murmur_hash.o: \ @@ -95,6 +97,27 @@ NXT_LIB =nxt -I$(NXT_LIB) \ $(NXT_LIB)/nxt_lvlhsh.c +$(NXT_BUILDDIR)/nxt_random.o: \ + $(NXT_LIB)/nxt_types.h \ + $(NXT_LIB)/nxt_clang.h \ + $(NXT_LIB)/nxt_random.h \ + $(NXT_LIB)/nxt_random.c \ + + $(NXT_CC) -c -o $(NXT_BUILDDIR)/nxt_random.o $(NXT_CFLAGS) \ + -I$(NXT_LIB) \ + $(NXT_LIB)/nxt_random.c + +$(NXT_BUILDDIR)/nxt_pcre.o: \ + $(NXT_LIB)/nxt_types.h \ + $(NXT_LIB)/nxt_clang.h \ + $(NXT_LIB)/nxt_regex.h \ + $(NXT_LIB)/nxt_pcre.h \ + $(NXT_LIB)/nxt_pcre.c \ + + $(NXT_CC) -c -o $(NXT_BUILDDIR)/nxt_pcre.o $(NXT_CFLAGS) \ + -I$(NXT_LIB) $(NXT_PCRE_CFLAGS) \ + $(NXT_LIB)/nxt_pcre.c + $(NXT_BUILDDIR)/nxt_malloc.o: \ $(NXT_LIB)/nxt_auto_config.h \ $(NXT_LIB)/nxt_types.h \ @@ -106,16 +129,6 @@ NXT_LIB = nxt -I$(NXT_LIB) \ $(NXT_LIB)/nxt_malloc.c -$(NXT_BUILDDIR)/nxt_random.o: \ - $(NXT_LIB)/nxt_types.h \ - $(NXT_LIB)/nxt_clang.h \ - $(NXT_LIB)/nxt_random.h \ - $(NXT_LIB)/nxt_random.c \ - - $(NXT_CC) -c -o $(NXT_BUILDDIR)/nxt_random.o $(NXT_CFLAGS) \ - -I$(NXT_LIB) \ - $(NXT_LIB)/nxt_random.c - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o: \ $(NXT_LIB)/nxt_types.h \ $(NXT_LIB)/nxt_clang.h \ diff -r 1c96b24bcdd2 -r b8084a72d667 nxt/nxt_pcre.c --- /dev/null Thu Jan 01 00:00:00 1970 + +++ b/nxt/nxt_pcre.cWed Jun 01 15:30:50 2016 +0300 @@ -0,0 +1,259 @@ + +/* + * Copyright (C) Igor Sysoev + * Copyright (C) NGINX, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include + + +static void *nxt_pcre_malloc(size_t size); +static void nxt_pcre_free(void *p); +static void *nxt_pcre_default_malloc(size_t size, void *memory_data); +static void nxt_pcre_default_free(void *p, void *memory_data); + + +static nxt_regex_context_t *regex_context; + + +nxt_regex_context_t * +nxt_regex_context_create(nxt_pcre_malloc_t private_malloc, +nxt_pcre_free_t private_free, void *memory_data) +{ +nxt_regex_context_t *ctx; + +if (private_malloc == NULL) { +private_malloc = nxt_pcre_default_malloc; +private_free = nxt_pcre_default_free; +} + +ctx = private_malloc(sizeof(nxt_regex_context_t), memory_data); + +if (nxt_fast_path(ctx != NULL)) { +ctx->private_malloc = private_malloc; +ctx->private_free = private_free; +ctx->memory_data = memory_data; +} + +return ctx; +} + + +nxt_int_t +nxt_regex_compile(nxt_regex_t *regex, u_char *source, size_t len, +nxt_uint_t options, nxt_regex_context_t *ctx) +{ +int ret, err, erroff; +char*pattern, *error; +void*(*saved_malloc)(size_t size); +void(*saved_free)(void *p); +size_t size; +const char *errstr; + +ret = NXT_ERROR; + +saved_malloc = pcre_malloc; +pcre_malloc = nxt_pcre_malloc; +saved_free = pcre_free; +pcre_free = nxt_pcre_free; +regex_context = ctx; + +if (len == 0) { +pattern = (char *) source; + +} else { +pattern = ctx->private_malloc(len + 1, ctx->memory_data); +if (nxt_slow_path(pattern == NULL)) { +goto done; +} + +memcpy(pattern, source, len); +pattern[len] = '\0'; +} + +regex->code = pcre_compile(pattern, options, , , NULL); + +if (nxt_slow_path(regex->code == NULL)) { +error = pattern + erroff; + +
[njs] parseInt() function.
details: http://hg.nginx.org/njs/rev/ffe9a5658450 branches: changeset: 109:ffe9a5658450 user: Igor Sysoev <i...@sysoev.ru> date: Mon Apr 25 17:28:34 2016 +0300 description: parseInt() function. diffstat: njs/njs_builtin.c| 3 + njs/njs_generator.c | 1 + njs/njs_lexer_keyword.c | 1 + njs/njs_number.c | 99 ++- njs/njs_number.h | 5 +- njs/njs_parser.c | 3 +- njs/njs_parser.h | 1 + njs/njs_vm.h | 3 +- njs/test/njs_unit_test.c | 18 9 files changed, 119 insertions(+), 15 deletions(-) diffs (267 lines): diff -r fd72dd7112c2 -r ffe9a5658450 njs/njs_builtin.c --- a/njs/njs_builtin.c Thu Apr 21 18:23:16 2016 +0300 +++ b/njs/njs_builtin.c Mon Apr 25 17:28:34 2016 +0300 @@ -83,6 +83,7 @@ njs_builtin_objects_create(njs_vm_t *vm) NULL, NULL, NULL, +NULL, }; static const njs_function_init_t native_functions[] = { @@ -91,6 +92,8 @@ njs_builtin_objects_create(njs_vm_t *vm) { njs_object_prototype_to_string, { 0 } }, { njs_number_is_nan, { NJS_SKIP_ARG, NJS_NUMBER_ARG } }, { njs_number_is_finite,{ NJS_SKIP_ARG, NJS_NUMBER_ARG } }, +{ njs_number_parse_int, + { NJS_SKIP_ARG, NJS_STRING_ARG, NJS_INTEGER_ARG } }, }; static const njs_object_prop_tnull_proto_property = { diff -r fd72dd7112c2 -r ffe9a5658450 njs/njs_generator.c --- a/njs/njs_generator.c Thu Apr 21 18:23:16 2016 +0300 +++ b/njs/njs_generator.c Mon Apr 25 17:28:34 2016 +0300 @@ -297,6 +297,7 @@ njs_generator(njs_vm_t *vm, njs_parser_t case NJS_TOKEN_TO_STRING: case NJS_TOKEN_IS_NAN: case NJS_TOKEN_IS_FINITE: +case NJS_TOKEN_PARSE_INT: return njs_generate_builtin_object(vm, parser, node); case NJS_TOKEN_FUNCTION: diff -r fd72dd7112c2 -r ffe9a5658450 njs/njs_lexer_keyword.c --- a/njs/njs_lexer_keyword.c Thu Apr 21 18:23:16 2016 +0300 +++ b/njs/njs_lexer_keyword.c Mon Apr 25 17:28:34 2016 +0300 @@ -91,6 +91,7 @@ static const njs_keyword_t njs_keywords { nxt_string("toString"), NJS_TOKEN_TO_STRING, 0 }, { nxt_string("isNaN"), NJS_TOKEN_IS_NAN, 0 }, { nxt_string("isFinite"), NJS_TOKEN_IS_FINITE, 0 }, +{ nxt_string("parseInt"), NJS_TOKEN_PARSE_INT, 0 }, /* Reserved words. */ diff -r fd72dd7112c2 -r ffe9a5658450 njs/njs_number.c --- a/njs/njs_number.c Thu Apr 21 18:23:16 2016 +0300 +++ b/njs/njs_number.c Mon Apr 25 17:28:34 2016 +0300 @@ -121,22 +121,22 @@ njs_number_parse(const u_char **start, c int64_t -njs_hex_number_parse(u_char *p, u_char *end) +njs_number_radix_parse(u_char *p, u_char *end, uint8_t radix, nxt_bool_t exact) { -int8_td; -uint32_t n; +uint8_t d; +uint64_t n; -static const int8_t hex[256] +static const int8_t digits[256] nxt_aligned(32) = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, --1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, --1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, +25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, +-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, +25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, @@ -150,13 +150,13 @@ njs_hex_number_parse(u_char *p, u_char * n = 0; while (p < end) { -d = hex[*p++]; +d = digits[*p++]; -if (nxt_slow_path(d < 0)) { -return -1; +if (nxt_slow_path(d >= radix)) { +return (exact) ? -1 : (int64_t) n; } -n = (n << 4) + d; +n = (n * radix) + d; } return n; @@ -474,3 +474,78 @@ njs_number_is_finite(njs_vm_t *vm, njs_v return NXT_OK; } + + +njs_ret_t +njs_number_parse_int(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, +njs_index_t unused) +{ +double num; +u_char *p, *end; +int64_tn; +uint8_tradix; +nxt_bool_t minus; +njs_string_prop_t string; + +num = NJS_NAN; + +if (nargs > 1) { +(void) n
[njs] Fix in String.indexOf() and String.lastIndexOf() functions.
details: http://hg.nginx.org/njs/rev/1c96b24bcdd2 branches: changeset: 111:1c96b24bcdd2 user: Igor Sysoev <i...@sysoev.ru> date: Fri Apr 29 17:02:52 2016 +0300 description: Fix in String.indexOf() and String.lastIndexOf() functions. diffstat: njs/njs_string.c | 37 - 1 files changed, 24 insertions(+), 13 deletions(-) diffs (53 lines): diff -r 169958fd3f70 -r 1c96b24bcdd2 njs/njs_string.c --- a/njs/njs_string.c Mon Apr 25 19:30:27 2016 +0300 +++ b/njs/njs_string.c Fri Apr 29 17:02:52 2016 +0300 @@ -1192,25 +1192,36 @@ njs_string_index_of(njs_vm_t *vm, njs_va if (index < length) { -p = string.start; -end = p + string.size; - if (string.size == length) { /* Byte or ASCII string. */ -p += index; +p = string.start + index; +end = (string.start + string.size) - (search.size - 1); + +while (p < end) { +if (memcmp(p, search.start, search.size) == 0) { +return index; +} + +index++; +p++; +} } else { /* UTF-8 string. */ -p = njs_string_offset(p, end, index); -} - -while (p < end) { -if (memcmp(p, search.start, search.size) == 0) { -return index; +end = string.start + string.size; + +p = njs_string_offset(string.start, end, index); + +end -= search.size - 1; + +while (p < end) { +if (memcmp(p, search.start, search.size) == 0) { +return index; +} + +index++; +p = nxt_utf8_next(p, end); } - -index++; -p = nxt_utf8_next(p, end); } } else if (search.size == 0) { ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] parseFloat() function.
details: http://hg.nginx.org/njs/rev/169958fd3f70 branches: changeset: 110:169958fd3f70 user: Igor Sysoev <i...@sysoev.ru> date: Mon Apr 25 19:30:27 2016 +0300 description: parseFloat() function. diffstat: njs/njs_builtin.c| 2 ++ njs/njs_generator.c | 1 + njs/njs_lexer_keyword.c | 1 + njs/njs_number.c | 20 +++- njs/njs_number.h | 2 ++ njs/njs_parser.c | 1 + njs/njs_parser.h | 1 + njs/njs_string.c | 14 -- njs/njs_string.h | 2 +- njs/njs_vm.c | 4 ++-- njs/njs_vm.h | 3 ++- njs/test/njs_unit_test.c | 3 +++ 12 files changed, 43 insertions(+), 11 deletions(-) diffs (200 lines): diff -r ffe9a5658450 -r 169958fd3f70 njs/njs_builtin.c --- a/njs/njs_builtin.c Mon Apr 25 17:28:34 2016 +0300 +++ b/njs/njs_builtin.c Mon Apr 25 19:30:27 2016 +0300 @@ -84,6 +84,7 @@ njs_builtin_objects_create(njs_vm_t *vm) NULL, NULL, NULL, +NULL, }; static const njs_function_init_t native_functions[] = { @@ -94,6 +95,7 @@ njs_builtin_objects_create(njs_vm_t *vm) { njs_number_is_finite,{ NJS_SKIP_ARG, NJS_NUMBER_ARG } }, { njs_number_parse_int, { NJS_SKIP_ARG, NJS_STRING_ARG, NJS_INTEGER_ARG } }, +{ njs_number_parse_float, { NJS_SKIP_ARG, NJS_STRING_ARG } }, }; static const njs_object_prop_tnull_proto_property = { diff -r ffe9a5658450 -r 169958fd3f70 njs/njs_generator.c --- a/njs/njs_generator.c Mon Apr 25 17:28:34 2016 +0300 +++ b/njs/njs_generator.c Mon Apr 25 19:30:27 2016 +0300 @@ -298,6 +298,7 @@ njs_generator(njs_vm_t *vm, njs_parser_t case NJS_TOKEN_IS_NAN: case NJS_TOKEN_IS_FINITE: case NJS_TOKEN_PARSE_INT: +case NJS_TOKEN_PARSE_FLOAT: return njs_generate_builtin_object(vm, parser, node); case NJS_TOKEN_FUNCTION: diff -r ffe9a5658450 -r 169958fd3f70 njs/njs_lexer_keyword.c --- a/njs/njs_lexer_keyword.c Mon Apr 25 17:28:34 2016 +0300 +++ b/njs/njs_lexer_keyword.c Mon Apr 25 19:30:27 2016 +0300 @@ -92,6 +92,7 @@ static const njs_keyword_t njs_keywords { nxt_string("isNaN"), NJS_TOKEN_IS_NAN, 0 }, { nxt_string("isFinite"), NJS_TOKEN_IS_FINITE, 0 }, { nxt_string("parseInt"), NJS_TOKEN_PARSE_INT, 0 }, +{ nxt_string("parseFloat"),NJS_TOKEN_PARSE_FLOAT, 0 }, /* Reserved words. */ diff -r ffe9a5658450 -r 169958fd3f70 njs/njs_number.c --- a/njs/njs_number.c Mon Apr 25 17:28:34 2016 +0300 +++ b/njs/njs_number.c Mon Apr 25 19:30:27 2016 +0300 @@ -36,7 +36,7 @@ njs_value_to_number(njs_value_t *value) } if (njs_is_string(value)) { -return njs_string_to_number(value); +return njs_string_to_number(value, 1); } if (njs_is_array(value)) { @@ -549,3 +549,21 @@ done: return NXT_OK; } + + +njs_ret_t +njs_number_parse_float(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, +njs_index_t unused) +{ +double num; + +num = NJS_NAN; + +if (nargs > 1) { +num = njs_string_to_number([1], 0); +} + +njs_number_set(>retval, num); + +return NXT_OK; +} diff -r ffe9a5658450 -r 169958fd3f70 njs/njs_number.h --- a/njs/njs_number.h Mon Apr 25 17:28:34 2016 +0300 +++ b/njs/njs_number.h Mon Apr 25 19:30:27 2016 +0300 @@ -37,6 +37,8 @@ njs_ret_t njs_number_is_finite(njs_vm_t nxt_uint_t nargs, njs_index_t unused); njs_ret_t njs_number_parse_int(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +njs_ret_t njs_number_parse_float(njs_vm_t *vm, njs_value_t *args, +nxt_uint_t nargs, njs_index_t unused); extern const njs_object_init_t njs_number_constructor_init; diff -r ffe9a5658450 -r 169958fd3f70 njs/njs_parser.c --- a/njs/njs_parser.c Mon Apr 25 17:28:34 2016 +0300 +++ b/njs/njs_parser.c Mon Apr 25 19:30:27 2016 +0300 @@ -1648,6 +1648,7 @@ njs_parser_terminal(njs_vm_t *vm, njs_pa case NJS_TOKEN_IS_NAN: case NJS_TOKEN_IS_FINITE: case NJS_TOKEN_PARSE_INT: +case NJS_TOKEN_PARSE_FLOAT: return njs_parser_builtin_function(vm, parser, node); default: diff -r ffe9a5658450 -r 169958fd3f70 njs/njs_parser.h --- a/njs/njs_parser.h Mon Apr 25 17:28:34 2016 +0300 +++ b/njs/njs_parser.h Mon Apr 25 19:30:27 2016 +0300 @@ -179,6 +179,7 @@ typedef enum { NJS_TOKEN_IS_NAN, NJS_TOKEN_IS_FINITE, NJS_TOKEN_PARSE_INT, +NJS_TOKEN_PARSE_FLOAT, NJS_TOKEN_RESERVED, } njs_token_t; diff -r ffe9a5658450 -r 169958fd3f70 njs/njs_string.c --- a/njs/njs_string.c Mon Apr 25 17:28:34 2016 +0300 +++ b/njs/njs_string.c Mon Apr 25 19:30:27 2016 +0300 @@ -1678,7 +1678,7 @@ njs_primitive_value_to_string(njs_vm_t * double -njs_string_to_number(njs_value_t *value) +njs_string_to_number(njs_value_t *value, nxt_bool_t exact) { doublenum; size_t
[njs] isNaN() function.
details: http://hg.nginx.org/njs/rev/a61f70d8874a branches: changeset: 107:a61f70d8874a user: Igor Sysoev <i...@sysoev.ru> date: Thu Apr 21 18:23:12 2016 +0300 description: isNaN() function. diffstat: njs/njs_builtin.c| 2 ++ njs/njs_generator.c | 1 + njs/njs_lexer_keyword.c | 1 + njs/njs_number.c | 18 ++ njs/njs_number.h | 3 +++ njs/njs_parser.c | 1 + njs/njs_parser.h | 1 + njs/njs_string.c | 13 - njs/njs_vm.h | 3 ++- njs/test/njs_unit_test.c | 18 ++ 10 files changed, 59 insertions(+), 2 deletions(-) diffs (175 lines): diff -r a69b4eaebdcf -r a61f70d8874a njs/njs_builtin.c --- a/njs/njs_builtin.c Thu Apr 21 15:57:05 2016 +0300 +++ b/njs/njs_builtin.c Thu Apr 21 18:23:12 2016 +0300 @@ -81,12 +81,14 @@ njs_builtin_objects_create(njs_vm_t *vm) static const njs_object_init_t*function_init[] = { _eval_function_init, NULL, +NULL, }; static const njs_function_init_t native_functions[] = { /* SunC does not allow empty array initialization. */ { njs_eval_function, { 0 } }, { njs_object_prototype_to_string, { 0 } }, +{ njs_number_is_nan, { NJS_SKIP_ARG, NJS_NUMBER_ARG } }, }; static const njs_object_prop_tnull_proto_property = { diff -r a69b4eaebdcf -r a61f70d8874a njs/njs_generator.c --- a/njs/njs_generator.c Thu Apr 21 15:57:05 2016 +0300 +++ b/njs/njs_generator.c Thu Apr 21 18:23:12 2016 +0300 @@ -295,6 +295,7 @@ njs_generator(njs_vm_t *vm, njs_parser_t case NJS_TOKEN_MATH: case NJS_TOKEN_EVAL: case NJS_TOKEN_TO_STRING: +case NJS_TOKEN_IS_NAN: return njs_generate_builtin_object(vm, parser, node); case NJS_TOKEN_FUNCTION: diff -r a69b4eaebdcf -r a61f70d8874a njs/njs_lexer_keyword.c --- a/njs/njs_lexer_keyword.c Thu Apr 21 15:57:05 2016 +0300 +++ b/njs/njs_lexer_keyword.c Thu Apr 21 18:23:12 2016 +0300 @@ -89,6 +89,7 @@ static const njs_keyword_t njs_keywords { nxt_string("eval"), NJS_TOKEN_EVAL, 0 }, { nxt_string("toString"), NJS_TOKEN_TO_STRING, 0 }, +{ nxt_string("isNaN"), NJS_TOKEN_IS_NAN, 0 }, /* Reserved words. */ diff -r a69b4eaebdcf -r a61f70d8874a njs/njs_number.c --- a/njs/njs_number.c Thu Apr 21 15:57:05 2016 +0300 +++ b/njs/njs_number.c Thu Apr 21 18:23:12 2016 +0300 @@ -433,3 +433,21 @@ const njs_object_init_t njs_number_prot njs_number_prototype_properties, nxt_nitems(njs_number_prototype_properties), }; + + +njs_ret_t +njs_number_is_nan(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, +njs_index_t unused) +{ +const njs_value_t *value; + +value = _value_true; + +if (nargs > 1 && !njs_is_nan(args[1].data.u.number)) { +value = _value_false; +} + +vm->retval = *value; + +return NXT_OK; +} diff -r a69b4eaebdcf -r a61f70d8874a njs/njs_number.h --- a/njs/njs_number.h Thu Apr 21 15:57:05 2016 +0300 +++ b/njs/njs_number.h Thu Apr 21 18:23:12 2016 +0300 @@ -30,6 +30,9 @@ njs_ret_t njs_number_to_string(njs_vm_t const njs_value_t *number); njs_ret_t njs_number_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +njs_ret_t njs_number_is_nan(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, +njs_index_t unused); + extern const njs_object_init_t njs_number_constructor_init; extern const njs_object_init_t njs_number_prototype_init; diff -r a69b4eaebdcf -r a61f70d8874a njs/njs_parser.c --- a/njs/njs_parser.c Thu Apr 21 15:57:05 2016 +0300 +++ b/njs/njs_parser.c Thu Apr 21 18:23:12 2016 +0300 @@ -1645,6 +1645,7 @@ njs_parser_terminal(njs_vm_t *vm, njs_pa case NJS_TOKEN_EVAL: case NJS_TOKEN_TO_STRING: +case NJS_TOKEN_IS_NAN: return njs_parser_builtin_function(vm, parser, node); default: diff -r a69b4eaebdcf -r a61f70d8874a njs/njs_parser.h --- a/njs/njs_parser.h Thu Apr 21 15:57:05 2016 +0300 +++ b/njs/njs_parser.h Thu Apr 21 18:23:12 2016 +0300 @@ -176,6 +176,7 @@ typedef enum { NJS_TOKEN_EVAL, NJS_TOKEN_TO_STRING, +NJS_TOKEN_IS_NAN, NJS_TOKEN_RESERVED, } njs_token_t; diff -r a69b4eaebdcf -r a61f70d8874a njs/njs_string.c --- a/njs/njs_string.c Thu Apr 21 15:57:05 2016 +0300 +++ b/njs/njs_string.c Thu Apr 21 18:23:12 2016 +0300 @@ -1685,6 +1685,8 @@ njs_string_to_number(njs_value_t *value) nxt_bool_tminus; const u_char *p, *end; +const size_t infinity = sizeof("Infinity") - 1; + size = value->short_string.size; if (size != NJS_STRING_LONG) { @@ -1719,11 +1721,20 @@ njs_string_to_number(njs_value_t *value) minus = 1; } +if (p == end) { +return NJS_NAN; +} + if (*p >= '0' && *p <= '9') { num = njs_number_parse(, e
[njs] isFinite() function.
details: http://hg.nginx.org/njs/rev/fd72dd7112c2 branches: changeset: 108:fd72dd7112c2 user: Igor Sysoev <i...@sysoev.ru> date: Thu Apr 21 18:23:16 2016 +0300 description: isFinite() function. diffstat: njs/njs_builtin.c| 2 ++ njs/njs_generator.c | 1 + njs/njs_lexer_keyword.c | 1 + njs/njs_number.c | 23 +++ njs/njs_number.h | 2 ++ njs/njs_parser.c | 1 + njs/njs_parser.h | 1 + njs/njs_vm.h | 3 ++- njs/test/njs_unit_test.c | 18 ++ 9 files changed, 51 insertions(+), 1 deletions(-) diffs (146 lines): diff -r a61f70d8874a -r fd72dd7112c2 njs/njs_builtin.c --- a/njs/njs_builtin.c Thu Apr 21 18:23:12 2016 +0300 +++ b/njs/njs_builtin.c Thu Apr 21 18:23:16 2016 +0300 @@ -82,6 +82,7 @@ njs_builtin_objects_create(njs_vm_t *vm) _eval_function_init, NULL, NULL, +NULL, }; static const njs_function_init_t native_functions[] = { @@ -89,6 +90,7 @@ njs_builtin_objects_create(njs_vm_t *vm) { njs_eval_function, { 0 } }, { njs_object_prototype_to_string, { 0 } }, { njs_number_is_nan, { NJS_SKIP_ARG, NJS_NUMBER_ARG } }, +{ njs_number_is_finite,{ NJS_SKIP_ARG, NJS_NUMBER_ARG } }, }; static const njs_object_prop_tnull_proto_property = { diff -r a61f70d8874a -r fd72dd7112c2 njs/njs_generator.c --- a/njs/njs_generator.c Thu Apr 21 18:23:12 2016 +0300 +++ b/njs/njs_generator.c Thu Apr 21 18:23:16 2016 +0300 @@ -296,6 +296,7 @@ njs_generator(njs_vm_t *vm, njs_parser_t case NJS_TOKEN_EVAL: case NJS_TOKEN_TO_STRING: case NJS_TOKEN_IS_NAN: +case NJS_TOKEN_IS_FINITE: return njs_generate_builtin_object(vm, parser, node); case NJS_TOKEN_FUNCTION: diff -r a61f70d8874a -r fd72dd7112c2 njs/njs_lexer_keyword.c --- a/njs/njs_lexer_keyword.c Thu Apr 21 18:23:12 2016 +0300 +++ b/njs/njs_lexer_keyword.c Thu Apr 21 18:23:16 2016 +0300 @@ -90,6 +90,7 @@ static const njs_keyword_t njs_keywords { nxt_string("eval"), NJS_TOKEN_EVAL, 0 }, { nxt_string("toString"), NJS_TOKEN_TO_STRING, 0 }, { nxt_string("isNaN"), NJS_TOKEN_IS_NAN, 0 }, +{ nxt_string("isFinite"), NJS_TOKEN_IS_FINITE, 0 }, /* Reserved words. */ diff -r a61f70d8874a -r fd72dd7112c2 njs/njs_number.c --- a/njs/njs_number.c Thu Apr 21 18:23:12 2016 +0300 +++ b/njs/njs_number.c Thu Apr 21 18:23:16 2016 +0300 @@ -451,3 +451,26 @@ njs_number_is_nan(njs_vm_t *vm, njs_valu return NXT_OK; } + + +njs_ret_t +njs_number_is_finite(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, +njs_index_t unused) +{ +double num; +const njs_value_t *value; + +value = _value_false; + +if (nargs > 1) { +num = args[1].data.u.number; + +if (!njs_is_nan(num) && !njs_is_infinity(num)) { +value = _value_true; +} +} + +vm->retval = *value; + +return NXT_OK; +} diff -r a61f70d8874a -r fd72dd7112c2 njs/njs_number.h --- a/njs/njs_number.h Thu Apr 21 18:23:12 2016 +0300 +++ b/njs/njs_number.h Thu Apr 21 18:23:16 2016 +0300 @@ -32,6 +32,8 @@ njs_ret_t njs_number_constructor(njs_vm_ nxt_uint_t nargs, njs_index_t unused); njs_ret_t njs_number_is_nan(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +njs_ret_t njs_number_is_finite(njs_vm_t *vm, njs_value_t *args, +nxt_uint_t nargs, njs_index_t unused); extern const njs_object_init_t njs_number_constructor_init; diff -r a61f70d8874a -r fd72dd7112c2 njs/njs_parser.c --- a/njs/njs_parser.c Thu Apr 21 18:23:12 2016 +0300 +++ b/njs/njs_parser.c Thu Apr 21 18:23:16 2016 +0300 @@ -1646,6 +1646,7 @@ njs_parser_terminal(njs_vm_t *vm, njs_pa case NJS_TOKEN_EVAL: case NJS_TOKEN_TO_STRING: case NJS_TOKEN_IS_NAN: +case NJS_TOKEN_IS_FINITE: return njs_parser_builtin_function(vm, parser, node); default: diff -r a61f70d8874a -r fd72dd7112c2 njs/njs_parser.h --- a/njs/njs_parser.h Thu Apr 21 18:23:12 2016 +0300 +++ b/njs/njs_parser.h Thu Apr 21 18:23:16 2016 +0300 @@ -177,6 +177,7 @@ typedef enum { NJS_TOKEN_EVAL, NJS_TOKEN_TO_STRING, NJS_TOKEN_IS_NAN, +NJS_TOKEN_IS_FINITE, NJS_TOKEN_RESERVED, } njs_token_t; diff -r a61f70d8874a -r fd72dd7112c2 njs/njs_vm.h --- a/njs/njs_vm.h Thu Apr 21 18:23:12 2016 +0300 +++ b/njs/njs_vm.h Thu Apr 21 18:23:16 2016 +0300 @@ -703,7 +703,8 @@ enum njs_function_e { NJS_FUNCTION_EVAL =0, NJS_FUNCTION_TO_STRING = 1, NJS_FUNCTION_IS_NAN = 2, -#define NJS_FUNCTION_MAX (NJS_FUNCTION_IS_NAN + 1) +NJS_FUNCTION_IS_FINITE = 3, +#define NJS_FUNCTION_MAX (NJS_FUNCTION_IS_FINITE + 1) }; diff -r a61f70d8874a -r fd72dd7112c2 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c T
[njs] eval() placeholder has been moved from the constructor table
details: http://hg.nginx.org/njs/rev/3f2480c38f8e branches: changeset: 104:3f2480c38f8e user: Igor Sysoev <i...@sysoev.ru> date: Tue Apr 19 16:08:32 2016 +0300 description: eval() placeholder has been moved from the constructor table to the shared function table. diffstat: njs/njs_builtin.c | 90 njs/njs_generator.c | 2 +- njs/njs_lexer_keyword.c | 1 + njs/njs_object.c| 2 +- njs/njs_parser.c| 35 +- njs/njs_parser.h| 3 + njs/njs_vm.h| 69 - 7 files changed, 135 insertions(+), 67 deletions(-) diffs (421 lines): diff -r f720a6378a2f -r 3f2480c38f8e njs/njs_builtin.c --- a/njs/njs_builtin.c Tue Apr 19 16:07:33 2016 +0300 +++ b/njs/njs_builtin.c Tue Apr 19 16:08:32 2016 +0300 @@ -34,10 +34,10 @@ typedef struct { nxt_int_t njs_builtin_objects_create(njs_vm_t *vm) { -nxt_int_t ret; -nxt_uint_ti; -njs_object_t *objects, *prototypes; -njs_function_t*functions; +nxt_int_t ret; +nxt_uint_t i; +njs_object_t*objects, *prototypes; +njs_function_t *functions, *constructors; static const njs_object_init_t*prototype_init[] = { _object_prototype_init, @@ -50,7 +50,7 @@ njs_builtin_objects_create(njs_vm_t *vm) _date_prototype_init, }; -static const njs_object_init_t*function_init[] = { +static const njs_object_init_t*constructor_init[] = { _object_constructor_init, _array_constructor_init, _boolean_constructor_init, @@ -59,11 +59,9 @@ njs_builtin_objects_create(njs_vm_t *vm) _function_constructor_init, _regexp_constructor_init, _date_constructor_init, - -_eval_function_init, }; -static const njs_function_init_t native_functions[] = { +static const njs_function_init_t native_constructors[] = { /* SunC does not allow empty array initialization. */ { njs_object_constructor, { 0 } }, { njs_array_constructor,{ 0 } }, @@ -74,14 +72,21 @@ njs_builtin_objects_create(njs_vm_t *vm) { njs_regexp_constructor, { NJS_SKIP_ARG, NJS_STRING_ARG, NJS_STRING_ARG } }, { njs_date_constructor, { 0 } }, - -{ njs_eval_function,{ 0 } }, }; -static const njs_object_init_t*objects_init[] = { +static const njs_object_init_t*object_init[] = { _math_object_init, }; +static const njs_object_init_t*function_init[] = { +_eval_function_init, +}; + +static const njs_function_init_t native_functions[] = { +/* SunC does not allow empty array initialization. */ +{ njs_eval_function,{ 0 } }, +}; + static const njs_object_prop_tnull_proto_property = { .type = NJS_WHITEOUT, .name = njs_string("__proto__"), @@ -110,8 +115,8 @@ njs_builtin_objects_create(njs_vm_t *vm) for (i = NJS_OBJECT_MATH; i < NJS_OBJECT_MAX; i++) { ret = njs_object_hash_create(vm, [i].shared_hash, - objects_init[i]->properties, - objects_init[i]->items); + object_init[i]->properties, + object_init[i]->items); if (nxt_slow_path(ret != NXT_OK)) { return NXT_ERROR; } @@ -119,6 +124,27 @@ njs_builtin_objects_create(njs_vm_t *vm) objects[i].shared = 1; } +functions = vm->shared->functions; + +for (i = NJS_FUNCTION_EVAL; i < NJS_FUNCTION_MAX; i++) { +ret = njs_object_hash_create(vm, [i].object.shared_hash, + function_init[i]->properties, + function_init[i]->items); +if (nxt_slow_path(ret != NXT_OK)) { +return NXT_ERROR; +} + +functions[i].object.shared = 1; +functions[i].native = 1; +functions[i].args_offset = 1; +functions[i].u.native = native_functions[i].native; +functions[i].args_types[0] = native_functions[i].args_types[0]; +functions[i].args_types[1] = native_functions[i].args_types[1]; +functions[i].args_types[2] = native_functions[i].args_types[2]; +functions[i].args_types[3] = native_functions[i].args_types[3]; +functions[i].args_types[4] = native_functions[i].args_types[4]; +} + prototypes = vm->shared->prototypes; for (i = NJS_PROTOTYPE_OBJECT; i < NJS_PROTOTYPE_MAX; i++) { @@ -130,20 +156,22 @@ njs_builtin_objects_create(njs_vm_t *vm) } } -functions = vm->shared->functions; +constructors = vm->shared->constructors; -for (i = NJS_FUNCTION_OBJECT; i
[njs] njs_string_new().
details: http://hg.nginx.org/njs/rev/f720a6378a2f branches: changeset: 103:f720a6378a2f user: Igor Sysoev <i...@sysoev.ru> date: Tue Apr 19 16:07:33 2016 +0300 description: njs_string_new(). diffstat: njs/njs_date.c | 30 +++--- njs/njs_number.c | 25 + njs/njs_string.c | 51 +-- njs/njs_string.h | 2 ++ 4 files changed, 35 insertions(+), 73 deletions(-) diffs (237 lines): diff -r 23ff7c369101 -r f720a6378a2f njs/njs_date.c --- a/njs/njs_date.cTue Apr 19 17:26:25 2016 +0300 +++ b/njs/njs_date.cTue Apr 19 16:07:33 2016 +0300 @@ -831,7 +831,6 @@ njs_date_string(njs_vm_t *vm, const char { size_t size; time_t clock; -u_char *start; u_char buf[NJS_DATE_TIME_LEN]; struct tm tm; @@ -841,14 +840,7 @@ njs_date_string(njs_vm_t *vm, const char size = strftime((char *) buf, NJS_DATE_TIME_LEN, fmt, ); -start = njs_string_alloc(vm, >retval, size, size); - -if (nxt_fast_path(start != NULL)) { -memcpy(start, buf, size); -return NXT_OK; -} - -return NXT_ERROR; +return njs_string_new(vm, >retval, buf, size, size); } vm->retval = njs_string_invalid_date; @@ -864,7 +856,6 @@ njs_date_prototype_to_utc_string(njs_vm_ double time; size_t size; time_t clock; -u_char *start; u_char buf[NJS_DATE_TIME_LEN]; struct tm tm; @@ -886,14 +877,7 @@ njs_date_prototype_to_utc_string(njs_vm_ tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec); -start = njs_string_alloc(vm, >retval, size, size); - -if (nxt_fast_path(start != NULL)) { -memcpy(start, buf, size); -return NXT_OK; -} - -return NXT_ERROR; +return njs_string_new(vm, >retval, buf, size, size); } vm->retval = njs_string_invalid_date; @@ -910,7 +894,6 @@ njs_date_prototype_to_iso_string(njs_vm_ double time; size_t size; time_t clock; -u_char *start; u_char buf[NJS_ISO_DATE_TIME_LEN]; struct tm tm; @@ -930,14 +913,7 @@ njs_date_prototype_to_iso_string(njs_vm_ tm.tm_hour, tm.tm_min, tm.tm_sec, (int) ((int64_t) time % 1000)); -start = njs_string_alloc(vm, >retval, size, size); - -if (nxt_fast_path(start != NULL)) { -memcpy(start, buf, size); -return NXT_OK; -} - -return NXT_ERROR; +return njs_string_new(vm, >retval, buf, size, size); } vm->exception = _exception_range_error; diff -r 23ff7c369101 -r f720a6378a2f njs/njs_number.c --- a/njs/njs_number.c Tue Apr 19 17:26:25 2016 +0300 +++ b/njs/njs_number.c Tue Apr 19 16:07:33 2016 +0300 @@ -167,12 +167,11 @@ njs_ret_t njs_number_to_string(njs_vm_t *vm, njs_value_t *string, const njs_value_t *number) { -u_char *p; double n, num; size_t size; const char *fmt; const njs_value_t *value; -char buf[128]; +u_char buf[128]; num = number->data.u.number; @@ -207,16 +206,9 @@ njs_number_to_string(njs_vm_t *vm, njs_v fmt = "%1.e"; } -size = snprintf(buf, sizeof(buf), fmt, num); - -p = njs_string_alloc(vm, string, size, size); +size = snprintf((char *) buf, sizeof(buf), fmt, num); -if (nxt_fast_path(p != NULL)) { -memcpy(p, buf, size); -return NXT_OK; -} - -return NXT_ERROR; +return njs_string_new(vm, string, buf, size, size); } *string = *value; @@ -363,7 +355,7 @@ static njs_ret_t njs_number_to_string_radix(njs_vm_t *vm, njs_value_t *string, const njs_value_t *number, uint32_t radix) { -u_char *p, *f, *start, *end; +u_char *p, *f, *end; double n, next; size_t size; uint8_t reminder; @@ -410,14 +402,7 @@ njs_number_to_string_radix(njs_vm_t *vm, size = f - p; -start = njs_string_alloc(vm, string, size, size); - -if (nxt_fast_path(start != NULL)) { -memcpy(start, p, size); -return NXT_OK; -} - -return NXT_ERROR; +return njs_string_new(vm, string, p, size, size); } diff -r 23ff7c369101 -r f720a6378a2f njs/njs_string.c --- a/njs/njs_string.c Tue Apr 19 17:26:25 2016 +0300 +++ b/njs/njs_string.c Tue Apr 19 16:07:33 2016 +0300 @@ -92,6 +92,28 @@ njs_string_create(njs_vm_t *vm, njs_valu } +nxt_noinline njs_ret_t +njs_string_new(njs_vm_t *vm, njs_value_t *value, const u_char *start, +uint32_t size, uint32_t length) +{ +u_char *p; + +p = njs_string_alloc(vm, value, size, length); + +if (nxt_fast_pat
[njs] String.toUpperCase().
details: http://hg.nginx.org/njs/rev/e411e0cbd20d branches: changeset: 101:e411e0cbd20d user: Igor Sysoev <i...@sysoev.ru> date: Fri Apr 15 18:01:40 2016 +0300 description: String.toUpperCase(). diffstat: njs/njs_string.c |59 ++ njs/test/njs_unit_test.c |27 + nxt/Makefile | 1 + nxt/nxt_stub.h| 7 + nxt/nxt_unicode_upper_case.h | 1108 + nxt/nxt_unicode_upper_case.pl |91 +++ nxt/nxt_utf8.c|35 +- nxt/nxt_utf8.h| 2 + 8 files changed, 1328 insertions(+), 2 deletions(-) diffs (truncated from 1420 to 1000 lines): diff -r b7442865d9fa -r e411e0cbd20d njs/njs_string.c --- a/njs/njs_string.c Fri Apr 15 18:01:19 2016 +0300 +++ b/njs/njs_string.c Fri Apr 15 18:01:40 2016 +0300 @@ -1343,6 +1343,58 @@ njs_string_prototype_to_lower_case(njs_v } +/* + * String.toUpperCase(). + * The method supports only simple folding. For example, German "ß" + * folding "\u00DF" to "\u0053\u0053" is not supported. + */ + +static njs_ret_t +njs_string_prototype_to_upper_case(njs_vm_t *vm, njs_value_t *args, +nxt_uint_t nargs, njs_index_t unused) +{ +size_t size; +u_char *p, *start; +const u_char *s, *end; +njs_string_prop_t string; + +(void) njs_string_prop(, [0]); + +start = njs_string_alloc(vm, >retval, string.size, string.length); +if (nxt_slow_path(start == NULL)) { +return NXT_ERROR; +} + +p = start; +s = string.start; +size = string.size; + +if (string.length == 0 || string.length == size) { +/* Byte or ASCII string. */ + +while (size != 0) { +*p++ = nxt_upper_case(*s++); +size--; +} + +} else { +/* UTF-8 string. */ +end = s + size; + +while (size != 0) { +p = nxt_utf8_encode(p, nxt_utf8_upper_case(, end)); +size--; +} + +if (string.length >= NJS_STRING_MAP_OFFSET) { +njs_string_offset_map_init(start, string.size); +} +} + +return NXT_OK; +} + + static njs_ret_t njs_string_prototype_search(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) @@ -1813,6 +1865,13 @@ static const njs_object_prop_t njs_stri { .type = NJS_METHOD, +.name = njs_string("toUpperCase"), +.value = njs_native_function(njs_string_prototype_to_upper_case, 0, + NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG), +}, + +{ +.type = NJS_METHOD, .name = njs_string("search"), .value = njs_native_function(njs_string_prototype_search, 0, NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG), diff -r b7442865d9fa -r e411e0cbd20d njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Fri Apr 15 18:01:19 2016 +0300 +++ b/njs/test/njs_unit_test.c Fri Apr 15 18:01:40 2016 +0300 @@ -2754,6 +2754,33 @@ static njs_unit_test_t njs_test[] = { nxt_string("'АБВ'.toLowerCase()"), nxt_string("абв") }, +{ nxt_string("'abc'.toUpperCase()"), + nxt_string("ABC") }, + +{ nxt_string("'αβγ'.toUpperCase()"), + nxt_string("ΑΒΓ") }, + +{ nxt_string("'абв'.toUpperCase()"), + nxt_string("АБВ") }, + +{ nxt_string("var a = [];" + "for (code = 0; code <= 1114111; code++) {" + "var s = String.fromCharCode(code);" + "var n = s.toUpperCase();" + "if (s != n && s != n.toLowerCase())" + "a.push(code);" + "} a"), + nxt_string("181,305,383,453,456,459,498,837,962,976,977,981,982,1008,1009,1013,7835,8126") }, + +{ nxt_string("var a = [];" + "for (code = 0; code <= 1114111; code++) {" + "var s = String.fromCharCode(code);" + "var n = s.toLowerCase();" + "if (s != n && s != n.toUpperCase())" + "a.push(code);" + "} a"), + nxt_string("304,453,456,459,498,1012,7838,8486,8490,8491") }, + { nxt_string("'abcdefgh'.search()"), nxt_string("0") }, diff -r b7442865d9fa -r e411e0cbd20d nxt/Makefile --- a/nxt/Makefile Fri Apr 15 18:01:19 2016 +0300 +++ b/nxt/Makefile Fri Apr 15 18:01:40 2016 +0300 @@ -48,6 +48,7 @@ NXT_LIB = nxt $(NXT_LIB)/nxt_clang.h \ $(NXT_LIB)/nxt_utf8.h \ $(NXT_LIB)/nxt_unicode_lower_case.h \ + $(NXT_LIB)/nxt_unicode_upper_case.h \ $(NXT_LIB)/nxt_utf8.c \ $(NXT_CC) -c -o $(
[njs] String.toLowerCase().
details: http://hg.nginx.org/njs/rev/b7442865d9fa branches: changeset: 100:b7442865d9fa user: Igor Sysoev <i...@sysoev.ru> date: Fri Apr 15 18:01:19 2016 +0300 description: String.toLowerCase(). diffstat: njs/njs_string.c |59 ++ njs/test/njs_unit_test.c | 9 + nxt/Makefile | 1 + nxt/nxt_djb_hash.c| 4 +- nxt/nxt_stub.h| 9 +- nxt/nxt_unicode_lowcase.h | 1043 - nxt/nxt_unicode_lowcase.pl|88 --- nxt/nxt_unicode_lower_case.h | 1043 + nxt/nxt_unicode_lower_case.pl |92 +++ nxt/nxt_utf8.c|28 +- nxt/nxt_utf8.h| 3 +- 11 files changed, 1225 insertions(+), 1154 deletions(-) diffs (truncated from 2510 to 1000 lines): diff -r 1c50334fbea6 -r b7442865d9fa njs/njs_string.c --- a/njs/njs_string.c Thu Apr 14 18:23:09 2016 +0300 +++ b/njs/njs_string.c Fri Apr 15 18:01:19 2016 +0300 @@ -1291,6 +1291,58 @@ njs_string_index(njs_string_prop_t *stri } +/* + * String.toLowerCase(). + * The method supports only simple folding. For example, Turkish "İ" + * folding "\u0130" to "\u0069\u0307" is not supported. + */ + +static njs_ret_t +njs_string_prototype_to_lower_case(njs_vm_t *vm, njs_value_t *args, +nxt_uint_t nargs, njs_index_t unused) +{ +size_t size; +u_char *p, *start; +const u_char *s, *end; +njs_string_prop_t string; + +(void) njs_string_prop(, [0]); + +start = njs_string_alloc(vm, >retval, string.size, string.length); +if (nxt_slow_path(start == NULL)) { +return NXT_ERROR; +} + +p = start; +s = string.start; +size = string.size; + +if (string.length == 0 || string.length == size) { +/* Byte or ASCII string. */ + +while (size != 0) { +*p++ = nxt_lower_case(*s++); +size--; +} + +} else { +/* UTF-8 string. */ +end = s + size; + +while (size != 0) { +p = nxt_utf8_encode(p, nxt_utf8_lower_case(, end)); +size--; +} + +if (string.length >= NJS_STRING_MAP_OFFSET) { +njs_string_offset_map_init(start, string.size); +} +} + +return NXT_OK; +} + + static njs_ret_t njs_string_prototype_search(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) @@ -1754,6 +1806,13 @@ static const njs_object_prop_t njs_stri { .type = NJS_METHOD, +.name = njs_string("toLowerCase"), +.value = njs_native_function(njs_string_prototype_to_lower_case, 0, + NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG), +}, + +{ +.type = NJS_METHOD, .name = njs_string("search"), .value = njs_native_function(njs_string_prototype_search, 0, NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG), diff -r 1c50334fbea6 -r b7442865d9fa njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Apr 14 18:23:09 2016 +0300 +++ b/njs/test/njs_unit_test.c Fri Apr 15 18:01:19 2016 +0300 @@ -2745,6 +2745,15 @@ static njs_unit_test_t njs_test[] = { nxt_string("'abc abc abc abc'.lastIndexOf('abc', 0)"), nxt_string("-1") }, +{ nxt_string("'ABC'.toLowerCase()"), + nxt_string("abc") }, + +{ nxt_string("'ΑΒΓ'.toLowerCase()"), + nxt_string("αβγ") }, + +{ nxt_string("'АБВ'.toLowerCase()"), + nxt_string("абв") }, + { nxt_string("'abcdefgh'.search()"), nxt_string("0") }, diff -r 1c50334fbea6 -r b7442865d9fa nxt/Makefile --- a/nxt/Makefile Thu Apr 14 18:23:09 2016 +0300 +++ b/nxt/Makefile Fri Apr 15 18:01:19 2016 +0300 @@ -47,6 +47,7 @@ NXT_LIB = nxt $(NXT_LIB)/nxt_types.h \ $(NXT_LIB)/nxt_clang.h \ $(NXT_LIB)/nxt_utf8.h \ + $(NXT_LIB)/nxt_unicode_lower_case.h \ $(NXT_LIB)/nxt_utf8.c \ $(NXT_CC) -c -o $(NXT_BUILDDIR)/nxt_utf8.o $(NXT_CFLAGS) \ diff -r 1c50334fbea6 -r b7442865d9fa nxt/nxt_djb_hash.c --- a/nxt/nxt_djb_hash.cThu Apr 14 18:23:09 2016 +0300 +++ b/nxt/nxt_djb_hash.cFri Apr 15 18:01:19 2016 +0300 @@ -31,7 +31,6 @@ nxt_djb_hash(const void *data, size_t le uint32_t nxt_djb_hash_lowcase(const void *data, size_t len) { -u_charc; uint32_t hash; const u_char *p; @@ -39,8 +38,7 @@ nxt_djb_hash_lowcase(const void *data, s hash = NXT_DJB_HASH_INIT; while (len != 0) { -c = *p++; -hash = nxt_djb_hash_add(hash, nxt_lowcase(c)); +hash = nxt_djb_hash_add(hash, nxt_lower_case(*p++)); len--; } diff -r 1c50334fbea6 -r b7442865d9fa nxt/nxt_stub.h --- a/nxt/nxt_stub.hThu Apr 14 18:23:09 2016 +0300 +++ b/nxt/nxt_stub.hFri A
Re: [nginx] dso
On 27 Apr 2016, at 19:32, 洪志道 <hongzhi...@gmail.com> wrote: > Get. > In production, there may be some possibility with load_module directive. > 1. add new module: load_module modules/some_module.so; [?] > 2. remove exist load_module directive, just comment out. [?] > 3. directive not changed but the so file changed. [kill -USR2 `cat > nginx.pid`; sleep 2; kill -QUIT `cat nginx.pid.oldbin`] > And how to deal with? USR2/QUIT is online binary upgrade procedure: http://nginx.org/en/docs/control.html#upgrade And this procedure should be used to change and to unload modules. -- Igor Sysoev http://nginx.com > 2016-04-28 0:08 GMT+08:00 Igor Sysoev <i...@sysoev.ru>: > On 27 Apr 2016, at 18:51, 洪志道 <hongzhi...@gmail.com> wrote: > >> Thanks for your reply. >> >> Is it the only way to solve the problem? > > This is a way to reload a module in production without service interruption. > >> I think it will be common that developers try to use dso instead of static >> module. > > Developers can simply stop and start nginx again. > > -- > Igor Sysoev > http://nginx.com > >> Nginx offical site points out we could load in so modules using reload or >> restart, but it seems forget to instruct the details about reload. >> And it's a great design, thanks again. >> >> 2016-04-27 19:22 GMT+08:00 Igor Sysoev <i...@sysoev.ru>: >> On 27 Apr 2016, at 12:10, 洪志道 <hongzhi...@gmail.com> wrote: >> >>> Hi, >>> >>> for example following config: >>> >>> daemon on; >>> ... >>> load_module modules/ngx_http_test_module.so; >>> ... >>> >>> > start nginx >>> > change ngx_http_test_module.c, then regenerate so file >>> > kill -HUP pid >>> >>> I found nginx still run the old so file (load first time), and how to work >>> with new so file? >>> >>> I tried .../sbin/nginx -s reload, It works as I expected. It seems there is >>> some differences in 'kill -HUP' and 'sbin/nginx -s reload’; >> >> kill -USR2 `cat nginx.pid`; sleep 2; kill -QUIT `cat nginx.pid.oldbin` >> >> >> -- >> Igor Sysoev >> http://nginx.com > > > ___ > nginx-devel mailing list > nginx-devel@nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel > > ___ > nginx-devel mailing list > nginx-devel@nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
Re: [nginx] dso
On 27 Apr 2016, at 12:10, 洪志道 <hongzhi...@gmail.com> wrote: > Hi, > > for example following config: > > daemon on; > ... > load_module modules/ngx_http_test_module.so; > ... > > > start nginx > > change ngx_http_test_module.c, then regenerate so file > > kill -HUP pid > > I found nginx still run the old so file (load first time), and how to work > with new so file? > > I tried .../sbin/nginx -s reload, It works as I expected. It seems there is > some differences in 'kill -HUP' and 'sbin/nginx -s reload’; kill -USR2 `cat nginx.pid`; sleep 2; kill -QUIT `cat nginx.pid.oldbin` -- Igor Sysoev http://nginx.com ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] "new Date()" incorrectly returned always Jan 1, 1970.
details: http://hg.nginx.org/njs/rev/1c50334fbea6 branches: changeset: 99:1c50334fbea6 user: Igor Sysoev <i...@sysoev.ru> date: Thu Apr 14 18:23:09 2016 +0300 description: "new Date()" incorrectly returned always Jan 1, 1970. diffstat: njs/njs_date.c | 2 +- njs/test/njs_unit_test.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diffs (24 lines): diff -r 51009da8e3d0 -r 1c50334fbea6 njs/njs_date.c --- a/njs/njs_date.cMon Apr 11 14:39:59 2016 +0300 +++ b/njs/njs_date.cThu Apr 14 18:23:09 2016 +0300 @@ -88,7 +88,7 @@ njs_date_constructor(njs_vm_t *vm, njs_v if (vm->frame->ctor) { -if (nargs == 0) { +if (nargs == 1) { time = njs_gettime(); } else if (nargs == 2 && njs_is_string([1])) { diff -r 51009da8e3d0 -r 1c50334fbea6 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Mon Apr 11 14:39:59 2016 +0300 +++ b/njs/test/njs_unit_test.c Thu Apr 14 18:23:09 2016 +0300 @@ -4025,7 +4025,7 @@ static njs_unit_test_t njs_test[] = { nxt_string("Date.parse('-01-01-01T00:00:00.000Z')"), nxt_string("-6219875520") }, -{ nxt_string("var d = new Date(); d == Date.parse(d.toString())"), +{ nxt_string("var d = new Date(); d == Date.parse(d.toISOString())"), nxt_string("true") }, { nxt_string("var s = Date(); s === Date(Date.parse(s))"), ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] String.fromCharCode() and String.fromCodePoint().
details: http://hg.nginx.org/njs/rev/51009da8e3d0 branches: changeset: 98:51009da8e3d0 user: Igor Sysoev <i...@sysoev.ru> date: Mon Apr 11 14:39:59 2016 +0300 description: String.fromCharCode() and String.fromCodePoint(). diffstat: njs/njs_string.c | 69 njs/test/njs_unit_test.c | 21 ++ 2 files changed, 90 insertions(+), 0 deletions(-) diffs (124 lines): diff -r 24544f647802 -r 51009da8e3d0 njs/njs_string.c --- a/njs/njs_string.c Sat Apr 09 12:21:31 2016 +0300 +++ b/njs/njs_string.c Mon Apr 11 14:39:59 2016 +0300 @@ -35,6 +35,8 @@ static nxt_noinline void njs_string_slic njs_slice_prop_t *slice, njs_value_t *args, nxt_uint_t nargs); static nxt_noinline void njs_string_slice_args(njs_slice_prop_t *slice, njs_value_t *args, nxt_uint_t nargs); +static njs_ret_t njs_string_prototype_from_char_code(njs_vm_t *vm, +njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); static nxt_noinline ssize_t njs_string_index_of(njs_vm_t *vm, njs_value_t *src, njs_value_t *search_string, size_t index); @@ -305,6 +307,20 @@ static const njs_object_prop_t njs_stri .name = njs_string("prototype"), .value = njs_native_getter(njs_object_prototype_create), }, + +{ +.type = NJS_METHOD, +.name = njs_string("fromCharCode"), +.value = njs_native_function(njs_string_prototype_from_char_code, 0, 0), +}, + + +/* ECMAScript 6, fromCodePoint(). */ +{ +.type = NJS_METHOD, +.name = njs_string("fromCodePoint"), +.value = njs_native_function(njs_string_prototype_from_char_code, 0, 0), +}, }; @@ -1045,6 +1061,59 @@ done: static njs_ret_t +njs_string_prototype_from_char_code(njs_vm_t *vm, njs_value_t *args, +nxt_uint_t nargs, njs_index_t unused) +{ +u_char *p; +double num; +size_t size; +int32_t code; +nxt_uint_t i; + +for (i = 1; i < nargs; i++) { +if (!njs_is_numeric([i])) { +vm->frame->trap_scratch.data.u.value = [i]; +return NJS_TRAP_NUMBER_ARG; +} +} + +size = 0; + +for (i = 1; i < nargs; i++) { +num = args[i].data.u.number; +if (njs_is_nan(num)) { +goto range_error; +} + +code = num; + +if (code != num || code < 0 || code >= 0x11) { +goto range_error; +} + +size += nxt_utf8_size(code); +} + +p = njs_string_alloc(vm, >retval, size, nargs - 1); +if (nxt_slow_path(p == NULL)) { +return NXT_ERROR; +} + +for (i = 1; i < nargs; i++) { +p = nxt_utf8_encode(p, args[i].data.u.number); +} + +return NXT_OK; + +range_error: + +vm->exception = _exception_range_error; + +return NXT_ERROR; +} + + +static njs_ret_t njs_string_prototype_index_of(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { diff -r 24544f647802 -r 51009da8e3d0 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Sat Apr 09 12:21:31 2016 +0300 +++ b/njs/test/njs_unit_test.c Mon Apr 11 14:39:59 2016 +0300 @@ -2681,6 +2681,27 @@ static njs_unit_test_t njs_test[] = ".length"), nxt_string("5") }, +{ nxt_string("String.fromCharCode('_')"), + nxt_string("RangeError") }, + +{ nxt_string("String.fromCharCode(3.14)"), + nxt_string("RangeError") }, + +{ nxt_string("String.fromCharCode(65, 90)"), + nxt_string("AZ") }, + +{ nxt_string("String.fromCharCode(945, 946, 947)"), + nxt_string("αβγ") }, + +{ nxt_string("(function() {" + "for (n = 0; n <= 1114111; n++) {" + "if (String.fromCharCode(n).charCodeAt(0) !== n)" + "return n;" + "}" + "return -1" + "})()"), + nxt_string("-1") }, + { nxt_string("a = 'abcdef'; function f(a) {" "return a.slice(a.indexOf('cd')) } f(a)"), nxt_string("cdef") }, ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Old array data are freed after array relocation.
details: http://hg.nginx.org/njs/rev/24544f647802 branches: changeset: 97:24544f647802 user: Igor Sysoev <i...@sysoev.ru> date: Sat Apr 09 12:21:31 2016 +0300 description: Old array data are freed after array relocation. diffstat: njs/njs_array.c | 7 +++ 1 files changed, 3 insertions(+), 4 deletions(-) diffs (31 lines): diff -r 160e59aaf9bb -r 24544f647802 njs/njs_array.c --- a/njs/njs_array.c Sat Apr 09 12:18:47 2016 +0300 +++ b/njs/njs_array.c Sat Apr 09 12:21:31 2016 +0300 @@ -143,7 +143,7 @@ njs_array_realloc(njs_vm_t *vm, njs_arra uint32_t size) { nxt_uint_t n; -njs_value_t *value; +njs_value_t *value, *old; if (size != array->size) { if (size < 16) { @@ -160,8 +160,7 @@ njs_array_realloc(njs_vm_t *vm, njs_arra return NXT_ERROR; } -/* GC: old = array->data */ - +old = array->data; array->data = value; while (prepend != 0) { @@ -185,7 +184,7 @@ njs_array_realloc(njs_vm_t *vm, njs_arra size--; } -/* GC: free old pointer. */ +nxt_mem_cache_free(vm->mem_cache_pool, old); return NXT_OK; } ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Forgotten nxt/nxt_time.h file has been added.
details: http://hg.nginx.org/njs/rev/0e62188391a1 branches: changeset: 95:0e62188391a1 user: Igor Sysoev <i...@sysoev.ru> date: Fri Apr 08 18:59:06 2016 +0300 description: Forgotten nxt/nxt_time.h file has been added. diffstat: nxt/nxt_time.h | 24 1 files changed, 24 insertions(+), 0 deletions(-) diffs (28 lines): diff -r 39557c1b3088 -r 0e62188391a1 nxt/nxt_time.h --- /dev/null Thu Jan 01 00:00:00 1970 + +++ b/nxt/nxt_time.hFri Apr 08 18:59:06 2016 +0300 @@ -0,0 +1,24 @@ + +/* + * Copyright (C) Igor Sysoev + * Copyright (C) NGINX, Inc. + */ + +#ifndef _NXT_TIME_H_INCLUDED_ +#define _NXT_TIME_H_INCLUDED_ + + +#if (NXT_HAVE_TM_GMTOFF) + +#define nxt_timezone(tm) \ +((tm)->tm_gmtoff) + +#elif (NXT_HAVE_ALTZONE) + +#define nxt_timezone(tm) \ +(-(((tm)->tm_isdst > 0) ? altzone : timezone)) + +#endif + + +#endif /* _NXT_TIME_H_INCLUDED_ */ ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Date() function.
details: http://hg.nginx.org/njs/rev/39557c1b3088 branches: changeset: 94:39557c1b3088 user: Igor Sysoev <i...@sysoev.ru> date: Fri Apr 08 18:19:43 2016 +0300 description: Date() function. diffstat: Makefile |16 + njs/njs_builtin.c| 9 + njs/njs_date.c | 2104 ++ njs/njs_date.h |25 + njs/njs_function.h | 1 + njs/njs_generator.c | 1 + njs/njs_lexer_keyword.c | 1 + njs/njs_object.c | 3 + njs/njs_object_hash.h|15 + njs/njs_parser.c | 4 + njs/njs_parser.h | 5 +- njs/njs_vm.c | 8 + njs/njs_vm.h |14 +- njs/test/njs_unit_test.c | 305 ++ nxt/auto/configure | 1 + nxt/auto/time|39 + 16 files changed, 2547 insertions(+), 4 deletions(-) diffs (truncated from 2813 to 1000 lines): diff -r 91543c86f412 -r 39557c1b3088 Makefile --- a/Makefile Tue Mar 29 13:38:18 2016 +0300 +++ b/Makefile Fri Apr 08 18:19:43 2016 +0300 @@ -18,6 +18,7 @@ NXT_BUILDDIR =build $(NXT_BUILDDIR)/njs_array.o \ $(NXT_BUILDDIR)/njs_function.o \ $(NXT_BUILDDIR)/njs_regexp.o \ + $(NXT_BUILDDIR)/njs_date.o \ $(NXT_BUILDDIR)/njs_math.o \ $(NXT_BUILDDIR)/njs_extern.o \ $(NXT_BUILDDIR)/njs_variable.o \ @@ -48,6 +49,7 @@ NXT_BUILDDIR =build $(NXT_BUILDDIR)/njs_array.o \ $(NXT_BUILDDIR)/njs_function.o \ $(NXT_BUILDDIR)/njs_regexp.o \ + $(NXT_BUILDDIR)/njs_date.o \ $(NXT_BUILDDIR)/njs_math.o \ $(NXT_BUILDDIR)/njs_extern.o \ $(NXT_BUILDDIR)/njs_variable.o \ @@ -224,6 +226,20 @@ tarball: -I$(NXT_LIB) -Injs $(NXT_PCRE_CFLAGS) \ njs/njs_regexp.c +$(NXT_BUILDDIR)/njs_date.o: \ + $(NXT_BUILDDIR)/libnxt.a \ + njs/njscript.h \ + njs/njs_vm.h \ + njs/njs_string.h \ + njs/njs_object.h \ + njs/njs_function.h \ + njs/njs_date.h \ + njs/njs_date.c \ + + $(NXT_CC) -c -o $(NXT_BUILDDIR)/njs_date.o $(NXT_CFLAGS) \ + -I$(NXT_LIB) -Injs $(NXT_PCRE_CFLAGS) \ + njs/njs_date.c + $(NXT_BUILDDIR)/njs_math.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ diff -r 91543c86f412 -r 39557c1b3088 njs/njs_builtin.c --- a/njs/njs_builtin.c Tue Mar 29 13:38:18 2016 +0300 +++ b/njs/njs_builtin.c Fri Apr 08 18:19:43 2016 +0300 @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -46,6 +47,7 @@ njs_builtin_objects_create(njs_vm_t *vm) _string_prototype_init, _function_prototype_init, _regexp_prototype_init, +_date_prototype_init, }; static const njs_object_init_t*function_init[] = { @@ -56,6 +58,7 @@ njs_builtin_objects_create(njs_vm_t *vm) _string_constructor_init, _function_constructor_init, _regexp_constructor_init, +_date_constructor_init, _eval_function_init, }; @@ -70,6 +73,8 @@ njs_builtin_objects_create(njs_vm_t *vm) { njs_function_constructor, { 0 } }, { njs_regexp_constructor, { NJS_SKIP_ARG, NJS_STRING_ARG, NJS_STRING_ARG } }, +{ njs_date_constructor, { 0 } }, + { njs_eval_function,{ 0 } }, }; @@ -178,6 +183,10 @@ njs_builtin_objects_create(njs_vm_t *vm) * RegExp.__proto__ -> Function_Prototype, * RegExp_Prototype.__proto__ -> Object_Prototype, * + * Date(), + * Date.__proto__ -> Function_Prototype, + * Date_Prototype.__proto__ -> Object_Prototype, + * * eval(), * eval.__proto__ -> Function_Prototype. */ diff -r 91543c86f412 -r 39557c1b3088 njs/njs_date.c --- /dev/null Thu Jan 01 00:00:00 1970 + +++ b/njs/njs_date.cFri Apr 08 18:19:43 2016 +0300 @@ -0,0 +1,2104 @@ + +/* + * Copyright (C) Igor Sysoev + * Copyright (C) NGINX, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* + * njs_timegm() is used because + * Solaris lacks timegm(), + * FreeBSD and MacOSX timegm() cannot handle years before 1900. + */ + +#define NJS_ISO_DATE_TIME_LEN sizeof("+001970-09-28T12:00:00.000Z") + +#define NJS_DATE_TIME_LEN \ +sizeof("Mon Sep 28 1970 12:00:00 GMT+0600 (X)") + + +static nxt_noinline double njs_date_string_parse(njs_value_t *date); +static const u_char *njs_date_skip_week_day(const u_char *p, const u_char *end); +static const u_char *njs_date_skip_spaces(const u_char *p, const u_char *end); +static nxt_noinline nxt_i
[njs] A fast exit from argument normalization loop.
details: http://hg.nginx.org/njs/rev/91543c86f412 branches: changeset: 93:91543c86f412 user: Igor Sysoev <i...@sysoev.ru> date: Tue Mar 29 13:38:18 2016 +0300 description: A fast exit from argument normalization loop. This also fixes an issue when SunC 5.9 does not set omitted array elements to a zero. diffstat: njs/njs_vm.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diffs (15 lines): diff -r f674bd8a8b76 -r 91543c86f412 njs/njs_vm.c --- a/njs/njs_vm.c Mon Mar 28 17:34:42 2016 +0300 +++ b/njs/njs_vm.c Tue Mar 29 13:38:18 2016 +0300 @@ -2474,8 +2474,10 @@ njs_normalize_args(njs_vm_t *vm, njs_val break; case NJS_SKIP_ARG: - break; + +case 0: +return NJS_OK; } args++; ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Fixed building on Solaris by SunC.
details: http://hg.nginx.org/njs/rev/f674bd8a8b76 branches: changeset: 92:f674bd8a8b76 user: Igor Sysoev <i...@sysoev.ru> date: Mon Mar 28 17:34:42 2016 +0300 description: Fixed building on Solaris by SunC. diffstat: njs/njs_math.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r 0354cdd7d114 -r f674bd8a8b76 njs/njs_math.c --- a/njs/njs_math.cThu Mar 24 17:13:27 2016 +0300 +++ b/njs/njs_math.cMon Mar 28 17:34:42 2016 +0300 @@ -536,7 +536,7 @@ static const njs_object_prop_t njs_math { .type = NJS_METHOD, .name = njs_string("random"), -.value = njs_native_function(njs_object_math_random, 0, ), +.value = njs_native_function(njs_object_math_random, 0, 0), }, { ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] User defined function prototype.
details: http://hg.nginx.org/njs/rev/6e70fe1e0a47 branches: changeset: 88:6e70fe1e0a47 user: Igor Sysoev <i...@sysoev.ru> date: Wed Mar 23 15:49:49 2016 +0300 description: User defined function prototype. diffstat: njs/njs_builtin.c| 18 ++-- njs/njs_function.c | 63 - njs/njs_function.h |3 + njs/njs_object.c | 101 -- njs/njs_object.h |4 + njs/njs_vm.c | 45 - njs/njs_vm.h |1 + njs/test/njs_unit_test.c | 14 ++ 8 files changed, 209 insertions(+), 40 deletions(-) diffs (438 lines): diff -r 7ad8820b9c74 -r 6e70fe1e0a47 njs/njs_builtin.c --- a/njs/njs_builtin.c Wed Mar 23 15:49:46 2016 +0300 +++ b/njs/njs_builtin.c Wed Mar 23 15:49:49 2016 +0300 @@ -77,18 +77,30 @@ njs_builtin_objects_create(njs_vm_t *vm) _math_object_init, }; -static const njs_object_prop_t null_proto_property = { +static const njs_object_prop_tnull_proto_property = { .type = NJS_WHITEOUT, .name = njs_string("__proto__"), .value = njs_value(NJS_NULL, 0, 0.0), }; +static const njs_object_prop_tfunction_prototype_property = { +.type = NJS_NATIVE_GETTER, +.name = njs_string("prototype"), +.value = njs_native_getter(njs_function_prototype_create), +}; + ret = njs_object_hash_create(vm, >shared->null_proto_hash, _proto_property, 1); if (nxt_slow_path(ret != NXT_OK)) { return NXT_ERROR; } +ret = njs_object_hash_create(vm, >shared->function_prototype_hash, + _prototype_property, 1); +if (nxt_slow_path(ret != NXT_OK)) { +return NXT_ERROR; +} + objects = vm->shared->objects; for (i = NJS_OBJECT_MATH; i < NJS_OBJECT_MAX; i++) { @@ -105,8 +117,6 @@ njs_builtin_objects_create(njs_vm_t *vm) prototypes = vm->shared->prototypes; for (i = NJS_PROTOTYPE_OBJECT; i < NJS_PROTOTYPE_MAX; i++) { -/* TODO: shared hash: prototype & constructor getters, methods */ - ret = njs_object_hash_create(vm, [i].shared_hash, prototype_init[i]->properties, prototype_init[i]->items); @@ -134,8 +144,6 @@ njs_builtin_objects_create(njs_vm_t *vm) } } -/* TODO: create function shared hash: prototype+contructor getter */ - return NXT_OK; } diff -r 7ad8820b9c74 -r 6e70fe1e0a47 njs/njs_function.c --- a/njs/njs_function.cWed Mar 23 15:49:46 2016 +0300 +++ b/njs/njs_function.cWed Mar 23 15:49:49 2016 +0300 @@ -35,10 +35,10 @@ njs_function_alloc(njs_vm_t *vm) /* * nxt_mem_cache_zalloc() does also: * nxt_lvlhsh_init(>object.hash); - * nxt_lvlhsh_init(>object.shared_hash); * function->object.__proto__ = NULL; */ +function->object.shared_hash = vm->shared->function_prototype_hash; function->object.shared = 1; function->args_offset = 1; @@ -305,6 +305,67 @@ njs_function_call(njs_vm_t *vm, njs_inde } +/* + * The "prototype" property of user defined functions is created on + * demand in private hash of the functions by the "prototype" getter. + * The getter creates a copy of function which is private to nJSVM, + * adds a "prototype" object property to the copy, and then adds a + * "constructor" property in the prototype object. The "constructor" + * property points to the copy of function: + * "F.prototype.constructor === F" + */ + +njs_ret_t +njs_function_prototype_create(njs_vm_t *vm, njs_value_t *value) +{ +njs_value_t *proto; + +proto = njs_function_property_prototype_create(vm, value); + +if (nxt_fast_path(proto != NULL)) { +vm->retval = *proto; +return NXT_OK; +} + +return NXT_ERROR; +} + + +njs_value_t * +njs_function_property_prototype_create(njs_vm_t *vm, njs_value_t *value) +{ +njs_value_t *proto, *cons; +njs_object_t*prototype; +njs_function_t *function; + +prototype = njs_object_alloc(vm); + +if (nxt_slow_path(prototype == NULL)) { +return NULL; +} + +function = njs_function_value_copy(vm, value); + +if (nxt_slow_path(function == NULL)) { +return NULL; +} + +proto = njs_property_prototype_create(vm, >object.hash, + prototype); +if (nxt_slow_path(proto == NULL)) { +return NULL; +} + +cons = njs_property_constructor_create(vm, >hash, value); + +if (nxt_fast_path(cons != NULL)) { +return proto; +} + +return NULL; +} + + njs_ret_t njs_function_constructor(njs_vm_t *vm, njs_value_
[njs] Math object.
details: http://hg.nginx.org/njs/rev/e3bc4f6f3480 branches: changeset: 86:e3bc4f6f3480 user: Igor Sysoev <i...@sysoev.ru> date: Wed Mar 23 15:27:14 2016 +0300 description: Math object. diffstat: Makefile | 14 + njs/njs_array.c |1 + njs/njs_builtin.c| 22 +- njs/njs_disassembler.c |4 +- njs/njs_function.c | 15 +- njs/njs_generator.c | 42 +++- njs/njs_lexer_keyword.c |1 + njs/njs_math.c | 554 +++ njs/njs_math.h | 17 + njs/njs_object.c | 28 ++- njs/njs_object.h |2 + njs/njs_parser.c | 37 +++- njs/njs_parser.h |4 + njs/njs_regexp.c |1 + njs/njs_vm.c | 64 +++-- njs/njs_vm.h | 26 +- njs/test/njs_unit_test.c | 62 + 17 files changed, 841 insertions(+), 53 deletions(-) diffs (truncated from 1256 to 1000 lines): diff -r 5995bd7637ff -r e3bc4f6f3480 Makefile --- a/Makefile Wed Mar 23 15:27:10 2016 +0300 +++ b/Makefile Wed Mar 23 15:27:14 2016 +0300 @@ -18,6 +18,7 @@ NXT_BUILDDIR =build $(NXT_BUILDDIR)/njs_array.o \ $(NXT_BUILDDIR)/njs_function.o \ $(NXT_BUILDDIR)/njs_regexp.o \ + $(NXT_BUILDDIR)/njs_math.o \ $(NXT_BUILDDIR)/njs_extern.o \ $(NXT_BUILDDIR)/njs_variable.o \ $(NXT_BUILDDIR)/njs_builtin.o \ @@ -46,6 +47,7 @@ NXT_BUILDDIR =build $(NXT_BUILDDIR)/njs_array.o \ $(NXT_BUILDDIR)/njs_function.o \ $(NXT_BUILDDIR)/njs_regexp.o \ + $(NXT_BUILDDIR)/njs_math.o \ $(NXT_BUILDDIR)/njs_extern.o \ $(NXT_BUILDDIR)/njs_variable.o \ $(NXT_BUILDDIR)/njs_builtin.o \ @@ -220,6 +222,18 @@ tarball: -I$(NXT_LIB) -Injs $(NXT_PCRE_CFLAGS) \ njs/njs_regexp.c +$(NXT_BUILDDIR)/njs_math.o: \ + $(NXT_BUILDDIR)/libnxt.a \ + njs/njscript.h \ + njs/njs_vm.h \ + njs/njs_object.h \ + njs/njs_math.h \ + njs/njs_math.c \ + + $(NXT_CC) -c -o $(NXT_BUILDDIR)/njs_math.o $(NXT_CFLAGS) \ + -I$(NXT_LIB) -Injs \ + njs/njs_math.c + $(NXT_BUILDDIR)/njs_extern.o: \ $(NXT_BUILDDIR)/libnxt.a \ njs/njscript.h \ diff -r 5995bd7637ff -r e3bc4f6f3480 njs/njs_array.c --- a/njs/njs_array.c Wed Mar 23 15:27:10 2016 +0300 +++ b/njs/njs_array.c Wed Mar 23 15:27:14 2016 +0300 @@ -129,6 +129,7 @@ njs_array_alloc(njs_vm_t *vm, uint32_t l nxt_lvlhsh_init(>object.hash); nxt_lvlhsh_init(>object.shared_hash); array->object.__proto__ = >prototypes[NJS_PROTOTYPE_ARRAY]; +array->object.shared = 0; array->size = size; array->length = length; diff -r 5995bd7637ff -r e3bc4f6f3480 njs/njs_builtin.c --- a/njs/njs_builtin.c Wed Mar 23 15:27:10 2016 +0300 +++ b/njs/njs_builtin.c Wed Mar 23 15:27:14 2016 +0300 @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -33,7 +34,7 @@ njs_builtin_objects_create(njs_vm_t *vm) { nxt_int_t ret; nxt_uint_ti; -njs_object_t *prototypes; +njs_object_t *objects, *prototypes; njs_function_t*functions; static const njs_object_init_t*prototype_init[] = { @@ -71,6 +72,10 @@ njs_builtin_objects_create(njs_vm_t *vm) { njs_eval_function,{ 0 } }, }; +static const njs_object_init_t*objects_init[] = { +_math_object_init, +}; + static const njs_object_prop_t null_proto_property = { .type = NJS_WHITEOUT, .name = njs_string("__proto__"), @@ -83,6 +88,19 @@ njs_builtin_objects_create(njs_vm_t *vm) return NXT_ERROR; } +objects = vm->shared->objects; + +for (i = NJS_OBJECT_MATH; i < NJS_OBJECT_MAX; i++) { +ret = njs_object_hash_create(vm, [i].shared_hash, + objects_init[i]->properties, + objects_init[i]->items); +if (nxt_slow_path(ret != NXT_OK)) { +return NXT_ERROR; +} + +objects[i].shared = 1; +} + prototypes = vm->shared->prototypes; for (i = NJS_PROTOTYPE_OBJECT; i < NJS_PROTOTYPE_MAX; i++) { @@ -99,9 +117,9 @@ njs_builtin_objects_create(njs_vm_t *vm) functions = vm->shared->functions; for (i = NJS_FUNCTION_OBJECT; i < NJS_FUNCTION_MAX; i++) { +functions[i].object.shared = 0; functions[i].native = 1; functions[i].args_offset = 1; -functions[i].shared = 0; functions[i].u.native = native_functions[i].native; functions[i].args_types[0] = native_functions[i].args_types[0]; functions[i].args_types[1] = native_functions[i].args_types[1];
[njs] Issues found by Coverity Scan in Regex have been fixed.
details: http://hg.nginx.org/njs/rev/027e0e8e7f61 branches: changeset: 90:027e0e8e7f61 user: Igor Sysoev <i...@sysoev.ru> date: Thu Mar 24 14:22:08 2016 +0300 description: Issues found by Coverity Scan in Regex have been fixed. diffstat: njs/njs_regexp.c | 22 +++--- 1 files changed, 19 insertions(+), 3 deletions(-) diffs (60 lines): diff -r 425cf63a7283 -r 027e0e8e7f61 njs/njs_regexp.c --- a/njs/njs_regexp.c Thu Mar 24 13:57:06 2016 +0300 +++ b/njs/njs_regexp.c Thu Mar 24 14:22:08 2016 +0300 @@ -36,6 +36,8 @@ static int njs_regexp_pattern_compile(pc u_char *source, int options); static njs_ret_t njs_regexp_exec_result(njs_vm_t *vm, njs_regexp_t *regexp, u_char *string, int *captures, nxt_uint_t utf8); +static njs_ret_t njs_regexp_string_create(njs_vm_t *vm, njs_value_t *value, +u_char *start, uint32_t size, int32_t length); njs_ret_t @@ -436,7 +438,7 @@ njs_regexp_prototype_source(njs_vm_t *vm size = strlen((char *) source) - pattern->flags; length = nxt_utf8_length(source, size); -return njs_string_create(vm, >retval, source, size, length); +return njs_regexp_string_create(vm, >retval, source, size, length); } @@ -454,7 +456,7 @@ njs_regexp_prototype_to_string(njs_vm_t size = strlen((char *) source); length = nxt_utf8_length(source, size); -return njs_string_create(vm, >retval, source, size, length); +return njs_regexp_string_create(vm, >retval, source, size, length); } @@ -621,7 +623,8 @@ njs_regexp_exec_result(njs_vm_t *vm, njs break; } -ret = njs_string_create(vm, >start[i], start, size, length); +ret = njs_regexp_string_create(vm, >start[i], + start, size, length); if (nxt_slow_path(ret != NXT_OK)) { return NXT_ERROR; } @@ -684,6 +687,19 @@ njs_regexp_exec_result(njs_vm_t *vm, njs } +static njs_ret_t +njs_regexp_string_create(njs_vm_t *vm, njs_value_t *value, u_char *start, +uint32_t size, int32_t length) +{ +if (nxt_fast_path(length >= 0)) { +return njs_string_create(vm, value, start, size, length); +} + +vm->exception = _exception_internal_error; +return NXT_ERROR; +} + + static const njs_object_prop_t njs_regexp_constructor_properties[] = { /* RegExp.name == "RegExp". */ ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel