[njs] Fixed editline detection.

2019-04-02 Thread Igor Sysoev
details:   https://hg.nginx.org/njs/rev/61f2616e21c7
branches:  
changeset: 863:61f2616e21c7
user:  Igor Sysoev 
date:  Tue Apr 02 17:17:49 2019 +0300
description:
Fixed editline detection.

This simplifies building on modern macOS.

diffstat:

 auto/editline   |  37 +
 njs/njs_shell.c |   8 +++-
 2 files changed, 32 insertions(+), 13 deletions(-)

diffs (92 lines):

diff -r b38fe378d900 -r 61f2616e21c7 auto/editline
--- a/auto/editline Mon Apr 01 19:11:39 2019 +0300
+++ b/auto/editline Tue Apr 02 17:17:49 2019 +0300
@@ -7,26 +7,33 @@ NXT_EDITLINE_LIB=
 
 nxt_found=no
 
-nxt_feature="editline library"
+nxt_feature="editline library in editline/readline.h"
 nxt_feature_name=NXT_HAVE_EDITLINE
 nxt_feature_run=no
-nxt_feature_incs="-I/usr/include/editline"
+nxt_feature_incs=
 nxt_feature_libs="-ledit"
 nxt_feature_test="#include 
-  #include 
+  #include 
 
- int main(void) {
- add_history(NULL);
- return 0;
- }"
+  int main(void) {
+  add_history(NULL);
+  return 0;
+  }"
 . auto/feature
 
 if [ $nxt_found = no ]; then
 
 # FreeBSD port
 
-nxt_feature="editline in /usr/include/edit"
-nxt_feature_incs="-I/usr/include/edit/readline"
+nxt_feature_name=NXT_HAVE_EDIT_READLINE
+nxt_feature="editline in edit/readline/readline.h"
+nxt_feature_test="#include 
+  #include 
+
+  int main(void) {
+  add_history(NULL);
+  return 0;
+  }"
 
 . auto/feature
 fi
@@ -35,9 +42,15 @@ if [ $nxt_found = no ]; then
 
 # NetBSD
 
-nxt_feature="editline in /usr/include"
-nxt_feature_incs="-I/usr/include/readline"
+nxt_feature_name=NXT_HAVE_READLINE
+nxt_feature="editline in readline/readline.h"
+nxt_feature_test="#include 
+  #include 
 
+  int main(void) {
+  add_history(NULL);
+  return 0;
+  }"
 . auto/feature
 fi
 
@@ -47,8 +60,8 @@ if [ $nxt_found = yes ]; then
 NXT_HAVE_LIBEDIT=YES
 NXT_EDITLINE_CFLAGS=$nxt_feature_incs
 NXT_EDITLINE_LIB=$nxt_feature_libs
+NXT_DEFAULT_TARGET="$NXT_DEFAULT_TARGET njs"
 
-   NXT_DEFAULT_TARGET="$NXT_DEFAULT_TARGET njs"
 else
 NXT_HAVE_LIBEDIT=NO
 $echo " - building interactive shell is not possible"
diff -r b38fe378d900 -r 61f2616e21c7 njs/njs_shell.c
--- a/njs/njs_shell.c   Mon Apr 01 19:11:39 2019 +0300
+++ b/njs/njs_shell.c   Tue Apr 02 17:17:49 2019 +0300
@@ -17,7 +17,13 @@
 #include 
 
 #include 
-#include 
+#if (NXT_HAVE_EDITLINE)
+#include 
+#elif (NXT_HAVE_EDIT_READLINE)
+#include 
+#else
+#include 
+#endif
 
 
 typedef struct {
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: NGX error logging - Race condition possible?

2018-09-03 Thread Igor Sysoev
> On 2 Sep 2018, at 21:44, Slawitscheck Stefan via nginx-devel 
>  wrote:
> 
> Dear Development Team,
> 
> I have one question about the logging mechanism of nginx with more worker 
> processes under Windows.
> 
> In ngx_log.c is the function ngx_write_console() which calls the systemcall 
> WriteFile().
> 
> How is do you ensures that there is no race condition while using this 
> function to write into the error.log file with multiple working processes?
> 
> From my understanding, each worker process writes into the error.log file by 
> itself. So it could be that there are two processes (worker) trying to write 
> at the same time?
> So usually you need some locking, semaphore, mutex or something like that?
> 
> If you ensure that there will be no race condition, how do you guarantee it?
> 
> I am looking forward to your answer.

It should be guaranteed by CreateFile options: FILE_APPEND_DATA | SYNCHRONIZE.


-- 
Igor Sysoev
http://nginx.com

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Refactored trap infrastructure.

2018-07-24 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/69300ba58603
branches:  
changeset: 570:69300ba58603
user:  Igor Sysoev 
date:  Tue Jul 24 19:50:02 2018 +0300
description:
Refactored trap infrastructure.

This change allows to introduce virtually unlimited number of traps.

diffstat:

 njs/njs_array.c  |5 +-
 njs/njs_date.c   |6 +-
 njs/njs_math.c   |8 +-
 njs/njs_object.c |6 +-
 njs/njs_string.c |8 +-
 njs/njs_vm.c |  162 --
 njs/njs_vm.h |   32 +++---
 7 files changed, 126 insertions(+), 101 deletions(-)

diffs (658 lines):

diff -r 8960cef1cd5f -r 69300ba58603 njs/njs_array.c
--- a/njs/njs_array.c   Tue Jul 24 19:50:02 2018 +0300
+++ b/njs/njs_array.c   Tue Jul 24 19:50:02 2018 +0300
@@ -917,7 +917,7 @@ njs_array_prototype_join_continuation(nj
 if (!njs_is_string(value)) {
 njs_vm_trap_value(vm, value);
 
-return NJS_TRAP_STRING_ARG;
+return njs_trap(vm, NJS_TRAP_STRING_ARG);
 }
 }
 
@@ -1952,7 +1952,8 @@ njs_array_string_sort(njs_vm_t *vm, njs_
 for (i = 1; i < nargs; i++) {
 if (!njs_is_string([i])) {
 njs_vm_trap_value(vm, [i]);
-return NJS_TRAP_STRING_ARG;
+
+return njs_trap(vm, NJS_TRAP_STRING_ARG);
 }
 }
 
diff -r 8960cef1cd5f -r 69300ba58603 njs/njs_date.c
--- a/njs/njs_date.cTue Jul 24 19:50:02 2018 +0300
+++ b/njs/njs_date.cTue Jul 24 19:50:02 2018 +0300
@@ -90,7 +90,8 @@ njs_date_constructor(njs_vm_t *vm, njs_v
 for (i = 1; i < n; i++) {
 if (!njs_is_numeric([i])) {
 njs_vm_trap_value(vm, [i]);
-return NJS_TRAP_NUMBER_ARG;
+
+return njs_trap(vm, NJS_TRAP_NUMBER_ARG);
 }
 
 num = args[i].data.u.number;
@@ -170,7 +171,8 @@ njs_date_utc(njs_vm_t *vm, njs_value_t *
 for (i = 1; i < n; i++) {
 if (!njs_is_numeric([i])) {
 njs_vm_trap_value(vm, [i]);
-return NJS_TRAP_NUMBER_ARG;
+
+return njs_trap(vm, NJS_TRAP_NUMBER_ARG);
 }
 
 num = args[i].data.u.number;
diff -r 8960cef1cd5f -r 69300ba58603 njs/njs_math.c
--- a/njs/njs_math.cTue Jul 24 19:50:02 2018 +0300
+++ b/njs/njs_math.cTue Jul 24 19:50:02 2018 +0300
@@ -365,7 +365,7 @@ njs_object_math_hypot(njs_vm_t *vm, njs_
 if (!njs_is_numeric([i])) {
 njs_vm_trap_value(vm, [i]);
 
-return NJS_TRAP_NUMBER_ARG;
+return njs_trap(vm, NJS_TRAP_NUMBER_ARG);
 }
 }
 
@@ -504,7 +504,8 @@ njs_object_math_max(njs_vm_t *vm, njs_va
 for (i = 1; i < nargs; i++) {
 if (!njs_is_numeric([i])) {
 njs_vm_trap_value(vm, [i]);
-return NJS_TRAP_NUMBER_ARG;
+
+return njs_trap(vm, NJS_TRAP_NUMBER_ARG);
 }
 }
 
@@ -535,7 +536,8 @@ njs_object_math_min(njs_vm_t *vm, njs_va
 for (i = 1; i < nargs; i++) {
 if (!njs_is_numeric([i])) {
 njs_vm_trap_value(vm, [i]);
-return NJS_TRAP_NUMBER_ARG;
+
+return njs_trap(vm, NJS_TRAP_NUMBER_ARG);
 }
 }
 
diff -r 8960cef1cd5f -r 69300ba58603 njs/njs_object.c
--- a/njs/njs_object.c  Tue Jul 24 19:50:02 2018 +0300
+++ b/njs/njs_object.c  Tue Jul 24 19:50:02 2018 +0300
@@ -227,7 +227,7 @@ njs_object_property(njs_vm_t *vm, const 
  *   NJS_STRING_VALUE property operation was applied to a string,
  *   NJS_ARRAY_VALUE  object is array,
  *   NJS_EXTERNAL_VALUE   object is external entity,
- *   NJS_TRAP_PROPERTYthe property trap must be called,
+ *   NJS_TRAP the property trap must be called,
  *   NXT_ERRORexception has been thrown.
  */
 
@@ -275,7 +275,7 @@ njs_property_query(njs_vm_t *vm, njs_pro
 }
 
 } else {
-return NJS_TRAP_PROPERTY;
+return njs_trap(vm, NJS_TRAP_PROPERTY);
 }
 }
 
@@ -359,7 +359,7 @@ njs_property_query(njs_vm_t *vm, njs_pro
 return ret;
 }
 
-return NJS_TRAP_PROPERTY;
+return njs_trap(vm, NJS_TRAP_PROPERTY);
 }
 
 
diff -r 8960cef1cd5f -r 69300ba58603 njs/njs_string.c
--- a/njs/njs_string.c  Tue Jul 24 19:50:02 2018 +0300
+++ b/njs/njs_string.c  Tue Jul 24 19:50:02 2018 +0300
@@ -842,7 +842,7 @@ njs_string_prototype_concat(njs_vm_t *vm
 if (!njs_is_string([i])) {
 njs_vm_trap_value(vm, [i]);
 
-return NJS_TRAP_STRING_ARG;
+return njs_trap(vm, NJS_TRAP_STRING_ARG);
 }
 }
 
@@ -1427,7 +1427,8 @@ njs_string_bytes_from_array(njs_vm_t *vm
 for (i = 0; i < length; i++) {
 if (!njs_is_numeric(>start[i])) {
 njs_vm_trap_value(vm, >start[i]);
-return NJS_TRAP_NUMBER_ARG;
+
+  

[njs] Removed artifacts left after changeset 25bd2742a18b.

2018-07-24 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/8960cef1cd5f
branches:  
changeset: 569:8960cef1cd5f
user:  Igor Sysoev 
date:  Tue Jul 24 19:50:02 2018 +0300
description:
Removed artifacts left after changeset 25bd2742a18b.

diffstat:

 njs/njs_vm.c |  17 +
 1 files changed, 5 insertions(+), 12 deletions(-)

diffs (50 lines):

diff -r 7ccf9c0a412a -r 8960cef1cd5f njs/njs_vm.c
--- a/njs/njs_vm.c  Tue Jul 24 19:25:39 2018 +0300
+++ b/njs/njs_vm.c  Tue Jul 24 19:50:02 2018 +0300
@@ -43,7 +43,7 @@ static njs_ret_t njs_function_frame_free
 
 static void njs_vm_trap(njs_vm_t *vm, nxt_uint_t trap, njs_value_t *value1,
 njs_value_t *value2);
-static njs_ret_t njs_vm_trap_argument(njs_vm_t *vm, nxt_uint_t trap);
+static void njs_vm_trap_argument(njs_vm_t *vm, nxt_uint_t trap);
 static njs_ret_t njs_vmcode_number_primitive(njs_vm_t *vm, njs_value_t *invld,
 njs_value_t *narg);
 static njs_ret_t njs_vmcode_string_primitive(njs_vm_t *vm, njs_value_t *invld,
@@ -188,12 +188,9 @@ start:
 case NJS_TRAP_NUMBER_ARG:
 case NJS_TRAP_STRING_ARG:
 
-ret = njs_vm_trap_argument(vm, ret - NJS_TRAP_BASE);
-if (nxt_fast_path(ret == NXT_OK)) {
-goto start;
-}
-
-break;
+njs_vm_trap_argument(vm, ret - NJS_TRAP_BASE);
+
+goto start;
 
 default:
 break;
@@ -2875,7 +2872,7 @@ njs_vm_trap(njs_vm_t *vm, nxt_uint_t tra
 }
 
 
-static njs_ret_t
+static void
 njs_vm_trap_argument(njs_vm_t *vm, nxt_uint_t trap)
 {
 njs_value_t *value;
@@ -2888,12 +2885,8 @@ njs_vm_trap_argument(njs_vm_t *vm, nxt_u
 frame->trap_values[1].data.u.value = value;
 frame->trap_values[0] = *value;
 
-njs_set_invalid(>trap_scratch);
-
 frame->trap_restart = vm->current;
 vm->current = (u_char *) njs_vm_traps[trap].code;
-
-return NXT_OK;
 }
 
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed addition operator applied to an object.

2018-07-24 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/766fcec15744
branches:  
changeset: 571:766fcec15744
user:  Igor Sysoev 
date:  Tue Jul 24 19:50:02 2018 +0300
description:
Fixed addition operator applied to an object.

This fixes #36 issue on Github.

diffstat:

 njs/njs_vm.c |  190 +-
 njs/njs_vm.h |3 +-
 njs/test/njs_unit_test.c |6 +
 3 files changed, 160 insertions(+), 39 deletions(-)

diffs (314 lines):

diff -r 69300ba58603 -r 766fcec15744 njs/njs_vm.c
--- a/njs/njs_vm.c  Tue Jul 24 19:50:02 2018 +0300
+++ b/njs/njs_vm.c  Tue Jul 24 19:50:02 2018 +0300
@@ -23,6 +23,8 @@ struct njs_property_next_s {
  * and should fit in CPU L1 instruction cache.
  */
 
+static nxt_noinline njs_ret_t njs_string_concat(njs_vm_t *vm,
+njs_value_t *val1, njs_value_t *val2);
 static njs_ret_t njs_method_private_copy(njs_vm_t *vm,
 njs_property_query_t *pq);
 static nxt_noinline njs_ret_t njs_values_equal(njs_vm_t *vm,
@@ -48,6 +50,10 @@ static njs_ret_t njs_vmcode_number_primi
 njs_value_t *narg);
 static njs_ret_t njs_vmcode_string_primitive(njs_vm_t *vm, njs_value_t *invld,
 njs_value_t *narg);
+static njs_ret_t njs_vmcode_addition_primitive(njs_vm_t *vm, njs_value_t 
*invld,
+njs_value_t *narg);
+static njs_ret_t njs_vmcode_comparison_primitive(njs_vm_t *vm,
+njs_value_t *invld, njs_value_t *narg);
 static njs_ret_t njs_vmcode_number_argument(njs_vm_t *vm, njs_value_t *invld1,
 njs_value_t *inlvd2);
 static njs_ret_t njs_vmcode_string_argument(njs_vm_t *vm, njs_value_t *invld1,
@@ -181,7 +187,8 @@ start:
 /* Fall through. */
 
 case NJS_TRAP_NUMBERS:
-case NJS_TRAP_STRINGS:
+case NJS_TRAP_ADDITION:
+case NJS_TRAP_COMPARISON:
 case NJS_TRAP_INCDEC:
 case NJS_TRAP_PROPERTY:
 
@@ -1301,10 +1308,9 @@ njs_vmcode_unary_negation(njs_vm_t *vm, 
 njs_ret_t
 njs_vmcode_addition(njs_vm_t *vm, njs_value_t *val1, njs_value_t *val2)
 {
-double num;
-u_char *start;
-size_t size, length;
-njs_string_prop_t  string1, string2;
+double   num;
+njs_ret_tret;
+njs_value_t  *s1, *s2, *src, dst;
 
 if (nxt_fast_path(njs_is_numeric(val1) && njs_is_numeric(val2))) {
 
@@ -1315,34 +1321,70 @@ njs_vmcode_addition(njs_vm_t *vm, njs_va
 }
 
 if (nxt_fast_path(njs_is_string(val1) && njs_is_string(val2))) {
-
-(void) njs_string_prop(, val1);
-(void) njs_string_prop(, val2);
-
-if ((string1.length != 0 || string1.size == 0)
-&& (string2.length != 0 || string2.size == 0))
-{
-length = string1.length + string2.length;
+return njs_string_concat(vm, val1, val2);
+}
+
+if (nxt_fast_path(njs_is_primitive(val1) && njs_is_primitive(val2))) {
+
+if (njs_is_string(val1)) {
+s1 = val1;
+s2 = 
+src = val2;
 
 } else {
-length = 0;
+s1 = 
+s2 = val2;
+src = val1;
+}
+
+ret = njs_primitive_value_to_string(vm, , src);
+
+if (nxt_fast_path(ret == NXT_OK)) {
+return njs_string_concat(vm, s1, s2);
 }
 
-size = string1.size + string2.size;
-
-start = njs_string_alloc(vm, >retval, size, length);
-
-if (nxt_slow_path(start == NULL)) {
-return NXT_ERROR;
-}
-
-(void) memcpy(start, string1.start, string1.size);
-(void) memcpy(start + string1.size, string2.start, string2.size);
-
-return sizeof(njs_vmcode_3addr_t);
+return ret;
 }
 
-return njs_trap(vm, NJS_TRAP_STRINGS);
+return njs_trap(vm, NJS_TRAP_ADDITION);
+}
+
+
+static nxt_noinline njs_ret_t
+njs_string_concat(njs_vm_t *vm, njs_value_t *val1, njs_value_t *val2)
+{
+u_char *start;
+size_t size, length;
+njs_string_prop_t  string1, string2;
+
+(void) njs_string_prop(, val1);
+(void) njs_string_prop(, val2);
+
+/*
+ * A result of concatenation of Byte and ASCII or UTF-8 strings
+ * is a Byte string.
+ */
+if ((string1.length != 0 || string1.size == 0)
+&& (string2.length != 0 || string2.size == 0))
+{
+length = string1.length + string2.length;
+
+} else {
+length = 0;
+}
+
+size = string1.size + string2.size;
+
+start = njs_string_alloc(vm, >retval, size, length);
+
+if (nxt_slow_path(start == NULL)) {
+return NXT_ERROR;
+}
+
+(void) memcpy(start, string1.start, string1.size);
+(void) memcpy(start + string1.size, string2.start, string2.size);
+
+return sizeof(njs_vmcode_3addr_t);
 }
 
 
@@ -1778,7 +1820,7 @@ njs_values_compare(njs_vm_t *vm, const n
 return (njs_string_cmp(val1, val2) < 0) ? 1 : 0;
 }
 
-return njs_trap(vm, NJS_TRAP_STRINGS);
+return njs_trap(vm, 

[njs] Style fixes.

2018-07-03 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/c1f9fe4022bc
branches:  
changeset: 553:c1f9fe4022bc
user:  Igor Sysoev 
date:  Tue Jul 03 15:48:04 2018 +0300
description:
Style fixes.

diffstat:

 njs/njs_error.h  |  3 ++-
 njs/njs_fs.c |  4 ++--
 njs/njs_object.c |  3 ++-
 njs/njs_string.c |  4 ++--
 njs/njs_string.h |  4 ++--
 5 files changed, 10 insertions(+), 8 deletions(-)

diffs (69 lines):

diff -r 3aef480987d6 -r c1f9fe4022bc njs/njs_error.h
--- a/njs/njs_error.h   Tue Jul 03 15:48:03 2018 +0300
+++ b/njs/njs_error.h   Tue Jul 03 15:48:04 2018 +0300
@@ -13,7 +13,8 @@
 #define njs_eval_error(vm, fmt, ...)  \
 njs_exception_error_create(vm, NJS_OBJECT_EVAL_ERROR, fmt, ##__VA_ARGS__)
 #define njs_internal_error(vm, fmt, ...)  \
-njs_exception_error_create(vm, NJS_OBJECT_INTERNAL_ERROR, fmt, 
##__VA_ARGS__)
+njs_exception_error_create(vm, NJS_OBJECT_INTERNAL_ERROR, fmt,\
+   ##__VA_ARGS__)
 #define njs_range_error(vm, fmt, ...) \
 njs_exception_error_create(vm, NJS_OBJECT_RANGE_ERROR, fmt, ##__VA_ARGS__)
 #define njs_reference_error(vm, fmt, ...) \
diff -r 3aef480987d6 -r c1f9fe4022bc njs/njs_fs.c
--- a/njs/njs_fs.c  Tue Jul 03 15:48:03 2018 +0300
+++ b/njs/njs_fs.c  Tue Jul 03 15:48:04 2018 +0300
@@ -43,8 +43,8 @@ static njs_ret_t njs_fs_write_file_sync(
 nxt_uint_t nargs, njs_index_t unused);
 static njs_ret_t njs_fs_write_file_internal(njs_vm_t *vm, njs_value_t *args,
 nxt_uint_t nargs, int default_flags);
-static njs_ret_t njs_fs_write_file_sync_internal(njs_vm_t *vm, njs_value_t 
*args,
-nxt_uint_t nargs, int default_flags);
+static njs_ret_t njs_fs_write_file_sync_internal(njs_vm_t *vm,
+njs_value_t *args, nxt_uint_t nargs, int default_flags);
 static njs_ret_t njs_fs_done(njs_vm_t *vm, njs_value_t *args,
 nxt_uint_t nargs, njs_index_t unused);
 
diff -r 3aef480987d6 -r c1f9fe4022bc njs/njs_object.c
--- a/njs/njs_object.c  Tue Jul 03 15:48:03 2018 +0300
+++ b/njs/njs_object.c  Tue Jul 03 15:48:04 2018 +0300
@@ -631,7 +631,8 @@ njs_object_keys(njs_vm_t *vm, njs_value_
 return NXT_OK;
 }
 
-njs_array_t*
+
+njs_array_t *
 njs_object_keys_array(njs_vm_t *vm, const njs_value_t *object)
 {
 size_t size;
diff -r 3aef480987d6 -r c1f9fe4022bc njs/njs_string.c
--- a/njs/njs_string.c  Tue Jul 03 15:48:03 2018 +0300
+++ b/njs/njs_string.c  Tue Jul 03 15:48:04 2018 +0300
@@ -716,8 +716,8 @@ njs_string_prototype_value_of(njs_vm_t *
  */
 
 static njs_ret_t
-njs_string_prototype_to_string(njs_vm_t *vm, njs_value_t *args, nxt_uint_t 
nargs,
-njs_index_t unused)
+njs_string_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
+nxt_uint_t nargs, njs_index_t unused)
 {
 nxt_int_t  ret;
 nxt_str_t  enc, str;
diff -r 3aef480987d6 -r c1f9fe4022bc njs/njs_string.h
--- a/njs/njs_string.h  Tue Jul 03 15:48:03 2018 +0300
+++ b/njs/njs_string.h  Tue Jul 03 15:48:04 2018 +0300
@@ -126,9 +126,9 @@ njs_ret_t njs_string_new(njs_vm_t *vm, n
 njs_ret_t njs_string_hex(njs_vm_t *vm, njs_value_t *value,
 const nxt_str_t *src);
 njs_ret_t njs_string_base64(njs_vm_t *vm, njs_value_t *value,
-   const nxt_str_t *src);
+const nxt_str_t *src);
 njs_ret_t njs_string_base64url(njs_vm_t *vm, njs_value_t *value,
-   const nxt_str_t *src);
+const nxt_str_t *src);
 void njs_string_copy(njs_value_t *dst, njs_value_t *src);
 njs_ret_t njs_string_validate(njs_vm_t *vm, njs_string_prop_t *string,
 njs_value_t *value);
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Added information about illegal token in number parsing.

2018-07-03 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/3aef480987d6
branches:  
changeset: 552:3aef480987d6
user:  Igor Sysoev 
date:  Tue Jul 03 15:48:03 2018 +0300
description:
Added information about illegal token in number parsing.

diffstat:

 njs/njs_lexer.c  |  61 +--
 njs/test/njs_unit_test.c |  26 ++--
 2 files changed, 46 insertions(+), 41 deletions(-)

diffs (195 lines):

diff -r f20bf1b5db20 -r 3aef480987d6 njs/njs_lexer.c
--- a/njs/njs_lexer.c   Tue Jul 03 14:15:29 2018 +0300
+++ b/njs/njs_lexer.c   Tue Jul 03 15:48:03 2018 +0300
@@ -21,7 +21,7 @@ struct njs_lexer_multi_s {
 static njs_token_t njs_lexer_next_token(njs_lexer_t *lexer);
 static njs_token_t njs_lexer_word(njs_lexer_t *lexer, u_char c);
 static njs_token_t njs_lexer_string(njs_lexer_t *lexer, u_char quote);
-static njs_token_t njs_lexer_number(njs_lexer_t *lexer);
+static njs_token_t njs_lexer_number(njs_lexer_t *lexer, u_char c);
 static njs_token_t njs_lexer_multi(njs_lexer_t *lexer,
 njs_token_t token, nxt_uint_t n, const njs_lexer_multi_t *multi);
 static njs_token_t njs_lexer_division(njs_lexer_t *lexer,
@@ -316,7 +316,7 @@ njs_lexer_next_token(njs_lexer_t *lexer)
 return njs_lexer_string(lexer, c);
 
 case NJS_TOKEN_DIGIT:
-return njs_lexer_number(lexer);
+return njs_lexer_number(lexer, c);
 
 case NJS_TOKEN_ASSIGNMENT:
 n = nxt_nitems(njs_assignment_token),
@@ -523,12 +523,11 @@ njs_lexer_string(njs_lexer_t *lexer, u_c
 
 
 static njs_token_t
-njs_lexer_number(njs_lexer_t *lexer)
+njs_lexer_number(njs_lexer_t *lexer, u_char c)
 {
-u_char  c, *p;
+const u_char  *p;
 
 p = lexer->start;
-c = p[-1];
 
 if (c == '0' && p != lexer->end) {
 
@@ -538,14 +537,12 @@ njs_lexer_number(njs_lexer_t *lexer)
 p++;
 
 if (p == lexer->end) {
-return NJS_TOKEN_ILLEGAL;
+goto illegal_token;
 }
 
-lexer->start = p;
-lexer->number = njs_number_hex_parse((const u_char **) 
>start,
- lexer->end);
+lexer->number = njs_number_hex_parse(, lexer->end);
 
-return NJS_TOKEN_NUMBER;
+goto done;
 }
 
 /* Octal literal values. */
@@ -554,19 +551,16 @@ njs_lexer_number(njs_lexer_t *lexer)
 p++;
 
 if (p == lexer->end) {
-return NJS_TOKEN_ILLEGAL;
+goto illegal_token;
 }
 
-lexer->start = p;
-lexer->number = njs_number_oct_parse((const u_char **) 
>start,
- lexer->end);
-p = lexer->start;
+lexer->number = njs_number_oct_parse(, lexer->end);
 
 if (p < lexer->end && (*p == '8' || *p == '9')) {
-return NJS_TOKEN_ILLEGAL;
+goto illegal_trailer;
 }
 
-return NJS_TOKEN_NUMBER;
+goto done;
 }
 
 /* Binary literal values. */
@@ -575,33 +569,44 @@ njs_lexer_number(njs_lexer_t *lexer)
 p++;
 
 if (p == lexer->end) {
-return NJS_TOKEN_ILLEGAL;
+goto illegal_token;
 }
 
-lexer->start = p;
-lexer->number = njs_number_bin_parse((const u_char **) 
>start,
- lexer->end);
-p = lexer->start;
+lexer->number = njs_number_bin_parse(, lexer->end);
 
 if (p < lexer->end && (*p >= '2' && *p <= '9')) {
-return NJS_TOKEN_ILLEGAL;
+goto illegal_trailer;
 }
 
-return NJS_TOKEN_NUMBER;
+goto done;
 }
 
 /* Legacy Octal literals are deprecated. */
 
 if (*p >= '0' && *p <= '9') {
-return NJS_TOKEN_ILLEGAL;
+goto illegal_trailer;
 }
 }
 
-lexer->start = p - 1;
-lexer->number = njs_number_dec_parse((const u_char **) >start,
- lexer->end);
+p--;
+lexer->number = njs_number_dec_parse(, lexer->end);
+
+done:
+
+lexer->start = (u_char *) p;
 
 return NJS_TOKEN_NUMBER;
+
+illegal_trailer:
+
+p++;
+
+illegal_token:
+
+lexer->text.start = lexer->start - 1;
+lexer->text.length = p - lexer->text.start;
+
+return NJS_TOKEN_ILLEGAL;
 }
 
 
diff -r f20bf1b5db20 -r 3aef480987d6 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Tue Jul 03 14:15:29 2018 +0300
+++ b/njs/test/njs_unit_test.c  Tue Jul 03 15:48:03 2018 +0300
@@ -127,25 +127,25 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("-0O777"),
   nxt_string("-511"

[njs] Using correct code size addition.

2018-04-04 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/5fd1cb826b96
branches:  
changeset: 492:5fd1cb826b96
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Apr 04 16:21:09 2018 +0300
description:
Using correct code size addition.

Found by Clang Static Analyzer.

diffstat:

 njs/njs_parser_expression.c |  22 ++
 1 files changed, 10 insertions(+), 12 deletions(-)

diffs (53 lines):

diff -r c64c3f5b6328 -r 5fd1cb826b96 njs/njs_parser_expression.c
--- a/njs/njs_parser_expression.c   Tue Apr 03 19:47:57 2018 +0300
+++ b/njs/njs_parser_expression.c   Wed Apr 04 16:21:09 2018 +0300
@@ -862,6 +862,11 @@ njs_parser_inc_dec_expression(njs_vm_t *
 return NJS_TOKEN_ILLEGAL;
 }
 
+parser->code_size += (parser->node->token == NJS_TOKEN_NAME)
+ ? sizeof(njs_vmcode_3addr_t)
+ : sizeof(njs_vmcode_3addr_t)
+   + sizeof(njs_vmcode_prop_set_t);
+
 node = njs_parser_node_alloc(vm);
 if (nxt_slow_path(node == NULL)) {
 return NJS_TOKEN_ERROR;
@@ -873,12 +878,6 @@ njs_parser_inc_dec_expression(njs_vm_t *
 node->left = parser->node;
 parser->node = node;
 
-parser->code_size += (token == NJS_TOKEN_NAME)
- ? sizeof(njs_vmcode_3addr_t)
- : sizeof(njs_vmcode_prop_get_t)
-   + sizeof(njs_vmcode_3addr_t)
-   + sizeof(njs_vmcode_prop_set_t);
-
 return next;
 }
 
@@ -918,6 +917,11 @@ njs_parser_post_inc_dec_expression(njs_v
 return NJS_TOKEN_ILLEGAL;
 }
 
+parser->code_size += (parser->node->token == NJS_TOKEN_NAME)
+ ? sizeof(njs_vmcode_3addr_t)
+ : sizeof(njs_vmcode_3addr_t)
+   + sizeof(njs_vmcode_prop_set_t);
+
 node = njs_parser_node_alloc(vm);
 if (nxt_slow_path(node == NULL)) {
 return NJS_TOKEN_ERROR;
@@ -929,12 +933,6 @@ njs_parser_post_inc_dec_expression(njs_v
 node->left = parser->node;
 parser->node = node;
 
-parser->code_size += (token == NJS_TOKEN_NAME)
- ? sizeof(njs_vmcode_3addr_t)
- : sizeof(njs_vmcode_prop_get_t)
-   + sizeof(njs_vmcode_3addr_t)
-   + sizeof(njs_vmcode_prop_set_t);
-
 return njs_parser_token(parser);
 }
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Exact values for default switch case expressions.

2018-04-03 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/641b3189d658
branches:  
changeset: 490:641b3189d658
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Apr 03 17:55:56 2018 +0300
description:
Exact values for default switch case expressions.

diffstat:

 njs/njs_lexer.c  |   3 ++-
 njs/njs_string.c |   6 --
 njs/njs_string.h |   3 ++-
 njs/njs_vm.c |  20 +++-
 4 files changed, 19 insertions(+), 13 deletions(-)

diffs (111 lines):

diff -r 39374a5d6cda -r 641b3189d658 njs/njs_lexer.c
--- a/njs/njs_lexer.c   Tue Apr 03 17:55:23 2018 +0300
+++ b/njs/njs_lexer.c   Tue Apr 03 17:55:56 2018 +0300
@@ -427,7 +427,8 @@ njs_lexer_next_token(njs_lexer_t *lexer)
 lexer->text.length = lexer->start - lexer->text.start;
 return token;
 
-default:  /* NJS_TOKEN_ILLEGAL */
+case NJS_TOKEN_ILLEGAL:
+default:
 lexer->start--;
 return token;
 }
diff -r 39374a5d6cda -r 641b3189d658 njs/njs_string.c
--- a/njs/njs_string.c  Tue Apr 03 17:55:23 2018 +0300
+++ b/njs/njs_string.c  Tue Apr 03 17:55:56 2018 +0300
@@ -2137,7 +2137,8 @@ njs_string_prototype_search(njs_vm_t *vm
 
 goto done;
 
-default:  /* NJS_VOID */
+case NJS_VOID:
+default:
 goto done;
 }
 
@@ -2452,7 +2453,8 @@ njs_string_prototype_split(njs_vm_t *vm,
 
 goto done;
 
-default: /* NJS_VOID */
+case NJS_VOID:
+default:
 break;
 }
 }
diff -r 39374a5d6cda -r 641b3189d658 njs/njs_string.h
--- a/njs/njs_string.h  Tue Apr 03 17:55:23 2018 +0300
+++ b/njs/njs_string.h  Tue Apr 03 17:55:56 2018 +0300
@@ -112,7 +112,8 @@ njs_string_length(njs_utf8_t utf8, u_cha
 case NJS_STRING_ASCII:
 return size;
 
-default:  /* NJS_STRING_UTF8 */
+case NJS_STRING_UTF8:
+default:
 length = nxt_utf8_length(start, size);
 
 return (length >= 0) ? length : 0;
diff -r 39374a5d6cda -r 641b3189d658 njs/njs_vm.c
--- a/njs/njs_vm.c  Tue Apr 03 17:55:23 2018 +0300
+++ b/njs/njs_vm.c  Tue Apr 03 17:55:56 2018 +0300
@@ -649,9 +649,9 @@ njs_vmcode_property_get(njs_vm_t *vm, nj
 
 return sizeof(njs_vmcode_prop_get_t);
 
+case NJS_TRAP_PROPERTY:
+case NXT_ERROR:
 default:
-/* NJS_TRAP_PROPERTY */
-/* NXT_ERROR */
 
 return ret;
 }
@@ -760,9 +760,9 @@ njs_vmcode_property_set(njs_vm_t *vm, nj
 
 return sizeof(njs_vmcode_prop_set_t);
 
+case NJS_TRAP_PROPERTY:
+case NXT_ERROR:
 default:
-/* NJS_TRAP_PROPERTY */
-/* NXT_ERROR */
 
 return ret;
 }
@@ -844,9 +844,9 @@ njs_vmcode_property_in(njs_vm_t *vm, njs
 
 break;
 
+case NJS_TRAP_PROPERTY:
+case NXT_ERROR:
 default:
-/* NJS_TRAP_PROPERTY */
-/* NXT_ERROR */
 
 return ret;
 }
@@ -946,9 +946,9 @@ njs_vmcode_property_delete(njs_vm_t *vm,
 
 break;
 
+case NJS_TRAP_PROPERTY:
+case NXT_ERROR:
 default:
-/* NJS_TRAP_PROPERTY */
-/* NXT_ERROR */
 
 return ret;
 }
@@ -1059,7 +1059,9 @@ njs_property_query(njs_vm_t *vm, njs_pro
 obj = NULL;
 break;
 
-default:  /* NJS_VOID, NJS_NULL. */
+case NJS_VOID:
+case NJS_NULL:
+default:
 if (nxt_fast_path(njs_is_primitive(property))) {
 
 ret = njs_primitive_value_to_string(vm, >value, property);
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Style fixes.

2018-04-03 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/39374a5d6cda
branches:  
changeset: 489:39374a5d6cda
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Apr 03 17:55:23 2018 +0300
description:
Style fixes.

diffstat:

 njs/njs_parser.h|   4 ++--
 njs/njs_parser_expression.c |  20 ++--
 njs/njs_vm.c|   4 +---
 3 files changed, 13 insertions(+), 15 deletions(-)

diffs (66 lines):

diff -r addefc71957b -r 39374a5d6cda njs/njs_parser.h
--- a/njs/njs_parser.h  Tue Apr 03 17:55:08 2018 +0300
+++ b/njs/njs_parser.h  Tue Apr 03 17:55:23 2018 +0300
@@ -389,9 +389,9 @@ nxt_bool_t njs_parser_has_side_effect(nj
 u_char *njs_parser_trace_handler(nxt_trace_t *trace, nxt_trace_data_t *td,
 u_char *start);
 void njs_parser_syntax_error(njs_vm_t *vm, njs_parser_t *parser,
-   const char* fmt, ...);
+const char* fmt, ...);
 void njs_parser_ref_error(njs_vm_t *vm, njs_parser_t *parser, const char* fmt,
-   ...);
+...);
 nxt_int_t njs_generate_scope(njs_vm_t *vm, njs_parser_t *parser,
 njs_parser_node_t *node);
 
diff -r addefc71957b -r 39374a5d6cda njs/njs_parser_expression.c
--- a/njs/njs_parser_expression.c   Tue Apr 03 17:55:08 2018 +0300
+++ b/njs/njs_parser_expression.c   Tue Apr 03 17:55:23 2018 +0300
@@ -873,11 +873,11 @@ njs_parser_inc_dec_expression(njs_vm_t *
 node->left = parser->node;
 parser->node = node;
 
-parser->code_size += (node->token == NJS_TOKEN_NAME) ?
- sizeof(njs_vmcode_3addr_t):
- sizeof(njs_vmcode_prop_get_t)
- + sizeof(njs_vmcode_3addr_t)
- + sizeof(njs_vmcode_prop_set_t);
+parser->code_size += (token == NJS_TOKEN_NAME)
+ ? sizeof(njs_vmcode_3addr_t)
+ : sizeof(njs_vmcode_prop_get_t)
+   + sizeof(njs_vmcode_3addr_t)
+   + sizeof(njs_vmcode_prop_set_t);
 
 return next;
 }
@@ -929,11 +929,11 @@ njs_parser_post_inc_dec_expression(njs_v
 node->left = parser->node;
 parser->node = node;
 
-parser->code_size += (parser->node->token == NJS_TOKEN_NAME) ?
- sizeof(njs_vmcode_3addr_t):
- sizeof(njs_vmcode_prop_get_t)
- + sizeof(njs_vmcode_3addr_t)
- + sizeof(njs_vmcode_prop_set_t);
+parser->code_size += (token == NJS_TOKEN_NAME)
+ ? sizeof(njs_vmcode_3addr_t)
+ : sizeof(njs_vmcode_prop_get_t)
+   + sizeof(njs_vmcode_3addr_t)
+   + sizeof(njs_vmcode_prop_set_t);
 
 return njs_parser_token(parser);
 }
diff -r addefc71957b -r 39374a5d6cda njs/njs_vm.c
--- a/njs/njs_vm.c  Tue Apr 03 17:55:08 2018 +0300
+++ b/njs/njs_vm.c  Tue Apr 03 17:55:23 2018 +0300
@@ -2394,9 +2394,7 @@ njs_vmcode_method_frame(njs_vm_t *vm, nj
 break;
 
 case NXT_ERROR:
-
-/* An exception was set in  njs_property_query(). */
-
+/* An exception was set in njs_property_query(). */
 return NXT_ERROR;
 
 default:
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] The typeof operation did not work in functions.

2018-04-03 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/671d9dd1ffeb
branches:  
changeset: 487:671d9dd1ffeb
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Apr 03 17:55:04 2018 +0300
description:
The typeof operation did not work in functions.

diffstat:

 njs/njs_parser.c|  14 +++---
 njs/njs_parser.h|   8 
 njs/njs_parser_expression.c |   4 
 njs/njs_variable.c  |   9 ++---
 njs/njs_variable.h  |   7 +++
 njs/test/njs_unit_test.c|   3 +++
 6 files changed, 31 insertions(+), 14 deletions(-)

diffs (169 lines):

diff -r 08b637d9a099 -r 671d9dd1ffeb njs/njs_parser.c
--- a/njs/njs_parser.c  Tue Apr 03 14:51:22 2018 +0300
+++ b/njs/njs_parser.c  Tue Apr 03 17:55:04 2018 +0300
@@ -483,7 +483,7 @@ njs_parser_function_declaration(njs_vm_t
 return NJS_TOKEN_ERROR;
 }
 
-ret = njs_variable_reference(vm, parser, node, 0);
+ret = njs_variable_reference(vm, parser, node, NJS_DECLARATION);
 if (nxt_slow_path(ret != NXT_OK)) {
 return NJS_TOKEN_ERROR;
 }
@@ -857,7 +857,7 @@ njs_parser_var_statement(njs_vm_t *vm, n
 
 name->token = NJS_TOKEN_NAME;
 
-ret = njs_variable_reference(vm, parser, name, 0);
+ret = njs_variable_reference(vm, parser, name, NJS_DECLARATION);
 if (nxt_slow_path(ret != NXT_OK)) {
 return NJS_TOKEN_ERROR;
 }
@@ -1342,7 +1342,7 @@ njs_parser_for_var_statement(njs_vm_t *v
 
 name->token = NJS_TOKEN_NAME;
 
-ret = njs_variable_reference(vm, parser, name, 0);
+ret = njs_variable_reference(vm, parser, name, NJS_DECLARATION);
 if (nxt_slow_path(ret != NXT_OK)) {
 return NJS_TOKEN_ERROR;
 }
@@ -1634,7 +1634,7 @@ njs_parser_try_statement(njs_vm_t *vm, n
 
 node->token = NJS_TOKEN_NAME;
 
-ret = njs_variable_reference(vm, parser, node, 0);
+ret = njs_variable_reference(vm, parser, node, NJS_DECLARATION);
 if (nxt_slow_path(ret != NXT_OK)) {
 return NJS_TOKEN_ERROR;
 }
@@ -1852,7 +1852,7 @@ njs_parser_terminal(njs_vm_t *vm, njs_pa
 break;
 }
 
-ret = njs_variable_reference(vm, parser, node, 1);
+ret = njs_variable_reference(vm, parser, node, NJS_REFERENCE);
 if (nxt_slow_path(ret != NXT_OK)) {
 return NJS_TOKEN_ERROR;
 }
@@ -2106,7 +2106,7 @@ njs_parser_builtin_object(njs_vm_t *vm, 
 var->value.type = NJS_OBJECT;
 var->value.data.truth = 1;
 
-ret = njs_variable_reference(vm, parser, node, 1);
+ret = njs_variable_reference(vm, parser, node, NJS_REFERENCE);
 if (nxt_slow_path(ret != NXT_OK)) {
 return NJS_TOKEN_ERROR;
 }
@@ -2139,7 +2139,7 @@ njs_parser_builtin_function(njs_vm_t *vm
 var->value.type = NJS_FUNCTION;
 var->value.data.truth = 1;
 
-ret = njs_variable_reference(vm, parser, node, 1);
+ret = njs_variable_reference(vm, parser, node, NJS_REFERENCE);
 if (nxt_slow_path(ret != NXT_OK)) {
 return NJS_TOKEN_ERROR;
 }
diff -r 08b637d9a099 -r 671d9dd1ffeb njs/njs_parser.h
--- a/njs/njs_parser.h  Tue Apr 03 14:51:22 2018 +0300
+++ b/njs/njs_parser.h  Tue Apr 03 17:55:04 2018 +0300
@@ -255,9 +255,9 @@ typedef struct njs_parser_node_snjs_
 
 struct njs_parser_node_s {
 njs_token_t token:16;
-uint8_t ctor:1;  /* 1 bit  */
-uint8_t temporary;   /* 1 bit  */
-uint8_t reference;   /* 1 bit  */
+uint8_t ctor:1;
+njs_variable_reference_treference:2;
+uint8_t temporary;/* 1 bit  */
 uint32_ttoken_line;
 uint32_tvariable_name_hash;
 
@@ -381,7 +381,7 @@ njs_token_t njs_parser_property_token(nj
 njs_token_t njs_parser_token(njs_parser_t *parser);
 nxt_int_t njs_parser_string_create(njs_vm_t *vm, njs_value_t *value);
 njs_ret_t njs_variable_reference(njs_vm_t *vm, njs_parser_t *parser,
-njs_parser_node_t *node, nxt_bool_t reference);
+njs_parser_node_t *node, njs_variable_reference_t reference);
 njs_variable_t *njs_variable_get(njs_vm_t *vm, njs_parser_node_t *node);
 njs_index_t njs_variable_typeof(njs_vm_t *vm, njs_parser_node_t *node);
 njs_index_t njs_variable_index(njs_vm_t *vm, njs_parser_node_t *node);
diff -r 08b637d9a099 -r 671d9dd1ffeb njs/njs_parser_expression.c
--- a/njs/njs_parser_expression.c   Tue Apr 03 14:51:22 2018 +0300
+++ b/njs/njs_parser_expression.c   Tue Apr 03 17:55:04 2018 +0300
@@ -805,6 +805,10 @@ njs_parser_unary_expression(njs_vm_t *vm
 }
 }
 
+if (token == NJS_TOKEN_TYPEOF && parser->node->token == NJS_TOKEN_NAME) {
+parser->node->reference = NJS_TYPEOF;
+}
+
 node = njs_parser_node_alloc(vm);
 if (nxt_slow_path(node == NULL)) {
 return NJS_TOKEN_ERROR;
diff -r 

[njs] Small optimizations.

2018-04-03 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/addefc71957b
branches:  
changeset: 488:addefc71957b
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Apr 03 17:55:08 2018 +0300
description:
Small optimizations.

diffstat:

 njs/njs_parser_expression.c |  25 +++--
 1 files changed, 11 insertions(+), 14 deletions(-)

diffs (63 lines):

diff -r 671d9dd1ffeb -r addefc71957b njs/njs_parser_expression.c
--- a/njs/njs_parser_expression.c   Tue Apr 03 17:55:04 2018 +0300
+++ b/njs/njs_parser_expression.c   Tue Apr 03 17:55:08 2018 +0300
@@ -762,19 +762,16 @@ njs_parser_unary_expression(njs_vm_t *vm
 return NJS_TOKEN_ILLEGAL;
 }
 
-if (token == NJS_TOKEN_UNARY_PLUS
-&& parser->node->token == NJS_TOKEN_NUMBER)
-{
+node = parser->node;
+
+if (token == NJS_TOKEN_UNARY_PLUS && node->token == NJS_TOKEN_NUMBER) {
 /* Skip the unary plus of number. */
 return next;
 }
 
-if (token == NJS_TOKEN_UNARY_NEGATION
-&& parser->node->token == NJS_TOKEN_NUMBER)
-{
+if (token == NJS_TOKEN_UNARY_NEGATION && node->token == NJS_TOKEN_NUMBER) {
+
 /* Optimization of common negative number. */
-
-node = parser->node;
 num = -node->u.value.data.u.number;
 node->u.value.data.u.number = num;
 node->u.value.data.truth = njs_is_number_true(num);
@@ -784,11 +781,11 @@ njs_parser_unary_expression(njs_vm_t *vm
 
 if (token == NJS_TOKEN_DELETE) {
 
-switch (parser->node->token) {
+switch (node->token) {
 
 case NJS_TOKEN_PROPERTY:
-parser->node->token = NJS_TOKEN_PROPERTY_DELETE;
-parser->node->u.operation = njs_vmcode_property_delete;
+node->token = NJS_TOKEN_PROPERTY_DELETE;
+node->u.operation = njs_vmcode_property_delete;
 parser->code_size += sizeof(njs_vmcode_3addr_t);
 
 return next;
@@ -805,8 +802,8 @@ njs_parser_unary_expression(njs_vm_t *vm
 }
 }
 
-if (token == NJS_TOKEN_TYPEOF && parser->node->token == NJS_TOKEN_NAME) {
-parser->node->reference = NJS_TYPEOF;
+if (token == NJS_TOKEN_TYPEOF && node->token == NJS_TOKEN_NAME) {
+node->reference = NJS_TYPEOF;
 }
 
 node = njs_parser_node_alloc(vm);
@@ -876,7 +873,7 @@ njs_parser_inc_dec_expression(njs_vm_t *
 node->left = parser->node;
 parser->node = node;
 
-parser->code_size += (parser->node->token == NJS_TOKEN_NAME) ?
+parser->code_size += (node->token == NJS_TOKEN_NAME) ?
  sizeof(njs_vmcode_3addr_t):
  sizeof(njs_vmcode_prop_get_t)
  + sizeof(njs_vmcode_3addr_t)
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Code simplification.

2018-03-14 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/895355fde02c
branches:  
changeset: 458:895355fde02c
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Mar 14 14:32:24 2018 +0300
description:
Code simplification.

A dead assignment left after the changeset 6738ff52a2cb was found
by Clang Static Analyzer.

diffstat:

 njs/njs_vm.c |  14 --
 1 files changed, 4 insertions(+), 10 deletions(-)

diffs (31 lines):

diff -r 8a274b5f1a04 -r 895355fde02c njs/njs_vm.c
--- a/njs/njs_vm.c  Tue Mar 13 20:37:01 2018 +0300
+++ b/njs/njs_vm.c  Wed Mar 14 14:32:24 2018 +0300
@@ -1179,10 +1179,10 @@ njs_object_property_query(njs_vm_t *vm, 
 
 if (ret == NXT_OK) {
 pq->shared = 1;
-prop = pq->lhq.value;
-
-switch (pq->query) {
-case NJS_PROPERTY_QUERY_GET:
+
+if (pq->query == NJS_PROPERTY_QUERY_GET) {
+prop = pq->lhq.value;
+
 if (prop->type == NJS_NATIVE_GETTER) {
 pq->scratch = *prop;
 prop = >scratch;
@@ -1193,12 +1193,6 @@ njs_object_property_query(njs_vm_t *vm, 
 pq->lhq.value = prop;
 }
 }
-
-break;
-
-case NJS_PROPERTY_QUERY_IN:
-prop = pq->lhq.value;
-break;
 }
 
 return ret;
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Removed unused null proto hash.

2018-03-13 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/6738ff52a2cb
branches:  
changeset: 456:6738ff52a2cb
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Mar 13 19:51:25 2018 +0300
description:
Removed unused null proto hash.

diffstat:

 njs/njs_builtin.c |  12 
 njs/njs_object.c  |   1 -
 njs/njs_vm.c  |   5 -
 njs/njs_vm.h  |   1 -
 4 files changed, 0 insertions(+), 19 deletions(-)

diffs (65 lines):

diff -r 9dcf4f92e32a -r 6738ff52a2cb njs/njs_builtin.c
--- a/njs/njs_builtin.c Tue Mar 13 18:55:24 2018 +0300
+++ b/njs/njs_builtin.c Tue Mar 13 19:51:25 2018 +0300
@@ -222,24 +222,12 @@ njs_builtin_objects_create(njs_vm_t *vm)
 { njs_memory_error_constructor,  { NJS_SKIP_ARG, NJS_STRING_ARG } },
 };
 
-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)) {
diff -r 9dcf4f92e32a -r 6738ff52a2cb njs/njs_object.c
--- a/njs/njs_object.c  Tue Mar 13 18:55:24 2018 +0300
+++ b/njs/njs_object.c  Tue Mar 13 19:51:25 2018 +0300
@@ -299,7 +299,6 @@ njs_object_create(njs_vm_t *vm, njs_valu
 object->__proto__ = args[1].data.u.object;
 
 } else {
-object->shared_hash = vm->shared->null_proto_hash;
 object->__proto__ = NULL;
 }
 
diff -r 9dcf4f92e32a -r 6738ff52a2cb njs/njs_vm.c
--- a/njs/njs_vm.c  Tue Mar 13 18:55:24 2018 +0300
+++ b/njs/njs_vm.c  Tue Mar 13 19:51:25 2018 +0300
@@ -1198,11 +1198,6 @@ njs_object_property_query(njs_vm_t *vm, 
 
 case NJS_PROPERTY_QUERY_IN:
 prop = pq->lhq.value;
-
-if (prop->type == NJS_WHITEOUT) {
-return NXT_DECLINED;
-}
-
 break;
 }
 
diff -r 9dcf4f92e32a -r 6738ff52a2cb njs/njs_vm.h
--- a/njs/njs_vm.h  Tue Mar 13 18:55:24 2018 +0300
+++ b/njs/njs_vm.h  Tue Mar 13 19:51:25 2018 +0300
@@ -1022,7 +1022,6 @@ typedef struct {
 struct njs_vm_shared_s {
 nxt_lvlhsh_t keywords_hash;
 nxt_lvlhsh_t values_hash;
-nxt_lvlhsh_t null_proto_hash;
 nxt_lvlhsh_t function_prototype_hash;
 
 njs_object_t objects[NJS_OBJECT_MAX];
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed String.prototype.toUTF8() function.

2018-02-28 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/ab1f67b69707
branches:  
changeset: 453:ab1f67b69707
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Feb 28 16:20:11 2018 +0300
description:
Fixed String.prototype.toUTF8() function.

A byte string returned by String.prototype.toUTF8() had length equal
to its size so the string can be processed later as an ASCII string.

diffstat:

 njs/njs_string.c |  5 +
 njs/test/njs_unit_test.c |  9 +
 2 files changed, 14 insertions(+), 0 deletions(-)

diffs (34 lines):

diff -r 0f1c3efcd894 -r ab1f67b69707 njs/njs_string.c
--- a/njs/njs_string.c  Tue Feb 27 14:11:00 2018 +0300
+++ b/njs/njs_string.c  Wed Feb 28 16:20:11 2018 +0300
@@ -1051,6 +1051,11 @@ njs_string_slice(njs_vm_t *vm, njs_value
 start += slice->start;
 size = slice->length;
 
+if (string->length == 0) {
+/* Byte string. */
+length = 0;
+}
+
 } else {
 /* UTF-8 string. */
 end = start + string->size;
diff -r 0f1c3efcd894 -r ab1f67b69707 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Tue Feb 27 14:11:00 2018 +0300
+++ b/njs/test/njs_unit_test.c  Wed Feb 28 16:20:11 2018 +0300
@@ -3529,6 +3529,15 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("'α'.toUTF8()[0]"),
   nxt_string("\xCE") },
 
+{ nxt_string("/^\\x80$/.test('\\x80'.toBytes())"),
+  nxt_string("true") },
+
+{ nxt_string("/^\\xC2\\x80$/.test('\\x80'.toUTF8())"),
+  nxt_string("true") },
+
+{ nxt_string("'α'.toUTF8().toBytes()"),
+  nxt_string("α") },
+
 { nxt_string("var a = 'a'.toBytes() + 'α'; a + a.length"),
   nxt_string("aα3") },
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

[njs] Added tag 0.1.13 for changeset d548b78eb881

2017-08-31 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/2a8aa9783fe9
branches:  
changeset: 405:2a8aa9783fe9
user:  Igor Sysoev <i...@sysoev.ru>
date:  Thu Aug 31 20:50:25 2017 +0300
description:
Added tag 0.1.13 for changeset d548b78eb881

diffstat:

 .hgtags |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (8 lines):

diff -r d548b78eb881 -r 2a8aa9783fe9 .hgtags
--- a/.hgtags   Thu Aug 31 20:48:52 2017 +0300
+++ b/.hgtags   Thu Aug 31 20:50:25 2017 +0300
@@ -11,3 +11,4 @@ 5bd2833988222900f60ad9b330ebc44df3b30662
 b1456ef3e002376d9d146a8a02acf6a4a21748e9 0.1.10
 fc5df33f4e6b02a673daf3728ff690fb1e09b95e 0.1.11
 c07b060396be3622ca97b037a86076b61b850847 0.1.12
+d548b78eb881ca799aa6fc8ba459d076f7db5ac8 0.1.13
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Version 0.1.13.

2017-08-31 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/d548b78eb881
branches:  
changeset: 404:d548b78eb881
user:  Igor Sysoev <i...@sysoev.ru>
date:  Thu Aug 31 20:48:52 2017 +0300
description:
Version 0.1.13.

diffstat:

 CHANGES  |  13 +
 Makefile |   2 +-
 2 files changed, 14 insertions(+), 1 deletions(-)

diffs (30 lines):

diff -r 27aa477208f5 -r d548b78eb881 CHANGES
--- a/CHANGES   Thu Aug 31 20:27:31 2017 +0300
+++ b/CHANGES   Thu Aug 31 20:48:52 2017 +0300
@@ -1,3 +1,16 @@
+
+Changes with nJScript 0.1.13 31 Aug 2017
+
+*) Feature: console.log() and console.help() methods in interactive
+   shell.
+
+*) Feature: interactive shell prints backtrace on exception.
+
+*) Feature: interactive shell by default if libedit is available.
+
+*) Bugfix: processing of large files from stdin in command line mode.
+
+*) Bugfix: improved editline detection.
 
 Changes with nJScript 0.1.12 08 Aug 2017
 
diff -r 27aa477208f5 -r d548b78eb881 Makefile
--- a/Makefile  Thu Aug 31 20:27:31 2017 +0300
+++ b/Makefile  Thu Aug 31 20:48:52 2017 +0300
@@ -1,5 +1,5 @@
 
-NJS_VER =  0.1.12
+NJS_VER =  0.1.13
 
 NXT_LIB =  nxt
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Added tag 0.1.12 for changeset c07b060396be

2017-08-08 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/f47b1eed6ed8
branches:  
changeset: 396:f47b1eed6ed8
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Aug 08 18:06:53 2017 +0300
description:
Added tag 0.1.12 for changeset c07b060396be

diffstat:

 .hgtags |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (8 lines):

diff -r c07b060396be -r f47b1eed6ed8 .hgtags
--- a/.hgtags   Tue Aug 08 18:05:14 2017 +0300
+++ b/.hgtags   Tue Aug 08 18:06:53 2017 +0300
@@ -10,3 +10,4 @@ a29f29d481125db6101ecdc23dc20187c143cdc9
 5bd2833988222900f60ad9b330ebc44df3b30662 0.1.9
 b1456ef3e002376d9d146a8a02acf6a4a21748e9 0.1.10
 fc5df33f4e6b02a673daf3728ff690fb1e09b95e 0.1.11
+c07b060396be3622ca97b037a86076b61b850847 0.1.12
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Version 0.1.12.

2017-08-08 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/c07b060396be
branches:  
changeset: 395:c07b060396be
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Aug 08 18:05:14 2017 +0300
description:
Version 0.1.12.

diffstat:

 CHANGES  |  6 ++
 Makefile |  2 +-
 2 files changed, 7 insertions(+), 1 deletions(-)

diffs (23 lines):

diff -r bd7e5e51b6be -r c07b060396be CHANGES
--- a/CHANGES   Tue Aug 08 18:05:11 2017 +0300
+++ b/CHANGES   Tue Aug 08 18:05:14 2017 +0300
@@ -1,3 +1,9 @@
+
+Changes with nJScript 0.1.12 08 Aug 2017
+
+*) Feature: Interactive shell.
+
+*) Bugfix: in Object.isSealed().
 
 Changes with nJScript 0.1.11 27 Jun 2017
 
diff -r bd7e5e51b6be -r c07b060396be Makefile
--- a/Makefile  Tue Aug 08 18:05:11 2017 +0300
+++ b/Makefile  Tue Aug 08 18:05:14 2017 +0300
@@ -1,5 +1,5 @@
 
-NJS_VER =  0.1.11
+NJS_VER =  0.1.12
 
 NXT_LIB =  nxt
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Removed unused field.

2017-08-08 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/bc306c37d037
branches:  
changeset: 392:bc306c37d037
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Aug 08 17:47:55 2017 +0300
description:
Removed unused field.

diffstat:

 njs/njs_parser.c|  12 
 njs/njs_parser.h|   2 --
 njs/njs_parser_expression.c |   2 --
 3 files changed, 0 insertions(+), 16 deletions(-)

diffs (81 lines):

diff -r e2baf506be4c -r bc306c37d037 njs/njs_parser.c
--- a/njs/njs_parser.c  Tue Aug 08 17:47:53 2017 +0300
+++ b/njs/njs_parser.c  Tue Aug 08 17:47:55 2017 +0300
@@ -934,8 +934,6 @@ njs_parser_if_statement(njs_vm_t *vm, nj
 njs_token_ttoken;
 njs_parser_node_t  *node, *cond, *stmt;
 
-parser->branch = 1;
-
 token = njs_parser_grouping_expression(vm, parser);
 if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
 return token;
@@ -995,8 +993,6 @@ njs_parser_switch_statement(njs_vm_t *vm
 njs_token_ttoken;
 njs_parser_node_t  *node, *swtch, *branch, *dflt, **last;
 
-parser->branch = 1;
-
 node = NULL;
 branch = NULL;
 dflt = NULL;
@@ -1114,8 +1110,6 @@ njs_parser_while_statement(njs_vm_t *vm,
 njs_token_ttoken;
 njs_parser_node_t  *node, *cond;
 
-parser->branch = 1;
-
 token = njs_parser_grouping_expression(vm, parser);
 if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
 return token;
@@ -1150,8 +1144,6 @@ njs_parser_do_while_statement(njs_vm_t *
 njs_token_ttoken;
 njs_parser_node_t  *node, *stmt;
 
-parser->branch = 1;
-
 token = njs_parser_token(parser);
 if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
 return token;
@@ -1195,8 +1187,6 @@ njs_parser_for_statement(njs_vm_t *vm, n
 njs_token_ttoken;
 njs_parser_node_t  *node, *init, *condition, *update, *cond, *body;
 
-parser->branch = 1;
-
 init = NULL;
 condition = NULL;
 update = NULL;
@@ -1580,8 +1570,6 @@ njs_parser_try_statement(njs_vm_t *vm, n
 njs_variable_t *var;
 njs_parser_node_t  *node, *try, *catch;
 
-parser->branch = 1;
-
 token = njs_parser_try_block(vm, parser);
 if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
 return token;
diff -r e2baf506be4c -r bc306c37d037 njs/njs_parser.h
--- a/njs/njs_parser.h  Tue Aug 08 17:47:53 2017 +0300
+++ b/njs/njs_parser.h  Tue Aug 08 17:47:55 2017 +0300
@@ -314,8 +314,6 @@ struct njs_parser_s {
 
 nxt_array_t *index_cache;
 
-uint8_t branch;   /* 1 bit */
-
 /* Parsing Function() or eval(). */
 uint8_t runtime;  /* 1 bit */
 
diff -r e2baf506be4c -r bc306c37d037 njs/njs_parser_expression.c
--- a/njs/njs_parser_expression.c   Tue Aug 08 17:47:53 2017 +0300
+++ b/njs/njs_parser_expression.c   Tue Aug 08 17:47:55 2017 +0300
@@ -518,8 +518,6 @@ njs_parser_conditional_expression(njs_vm
 return token;
 }
 
-parser->branch = 1;
-
 token = njs_parser_token(parser);
 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] Style fix in Unicode header files and Perl scripts which

2017-08-08 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/49a8c7cfb121
branches:  
changeset: 393:49a8c7cfb121
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Aug 08 17:47:56 2017 +0300
description:
Style fix in Unicode header files and Perl scripts which
generate the files.

diffstat:

 nxt/nxt_unicode_lower_case.h  |  108 -
 nxt/nxt_unicode_lower_case.pl |9 ++-
 nxt/nxt_unicode_upper_case.h  |  120 +++--
 nxt/nxt_unicode_upper_case.pl |8 ++-
 4 files changed, 183 insertions(+), 62 deletions(-)

diffs (684 lines):

diff -r bc306c37d037 -r 49a8c7cfb121 nxt/nxt_unicode_lower_case.h
--- a/nxt/nxt_unicode_lower_case.h  Tue Aug 08 17:47:55 2017 +0300
+++ b/nxt/nxt_unicode_lower_case.h  Tue Aug 08 17:47:56 2017 +0300
@@ -9,7 +9,9 @@
 #define NXT_UNICODE_BLOCK_SIZE  128
 
 
-static const uint32_t  nxt_unicode_lower_case_block_000[128]  nxt_aligned(64) 
= {
+static const uint32_t  nxt_unicode_lower_case_block_000[128]
+nxt_aligned(64) =
+{
 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
 0x00010, 0x00011, 0x00012, 0x00013, 0x00014, 0x00015, 0x00016, 0x00017,
@@ -29,7 +31,9 @@ static const uint32_t  nxt_unicode_lower
 };
 
 
-static const uint32_t  nxt_unicode_lower_case_block_001[128]  nxt_aligned(64) 
= {
+static const uint32_t  nxt_unicode_lower_case_block_001[128]
+nxt_aligned(64) =
+{
 0x00080, 0x00081, 0x00082, 0x00083, 0x00084, 0x00085, 0x00086, 0x00087,
 0x00088, 0x00089, 0x0008a, 0x0008b, 0x0008c, 0x0008d, 0x0008e, 0x0008f,
 0x00090, 0x00091, 0x00092, 0x00093, 0x00094, 0x00095, 0x00096, 0x00097,
@@ -49,7 +53,9 @@ static const uint32_t  nxt_unicode_lower
 };
 
 
-static const uint32_t  nxt_unicode_lower_case_block_002[128]  nxt_aligned(64) 
= {
+static const uint32_t  nxt_unicode_lower_case_block_002[128]
+nxt_aligned(64) =
+{
 0x00101, 0x00101, 0x00103, 0x00103, 0x00105, 0x00105, 0x00107, 0x00107,
 0x00109, 0x00109, 0x0010b, 0x0010b, 0x0010d, 0x0010d, 0x0010f, 0x0010f,
 0x00111, 0x00111, 0x00113, 0x00113, 0x00115, 0x00115, 0x00117, 0x00117,
@@ -69,7 +75,9 @@ static const uint32_t  nxt_unicode_lower
 };
 
 
-static const uint32_t  nxt_unicode_lower_case_block_003[128]  nxt_aligned(64) 
= {
+static const uint32_t  nxt_unicode_lower_case_block_003[128]
+nxt_aligned(64) =
+{
 0x00180, 0x00253, 0x00183, 0x00183, 0x00185, 0x00185, 0x00254, 0x00188,
 0x00188, 0x00256, 0x00257, 0x0018c, 0x0018c, 0x0018d, 0x001dd, 0x00259,
 0x0025b, 0x00192, 0x00192, 0x00260, 0x00263, 0x00195, 0x00269, 0x00268,
@@ -89,7 +97,9 @@ static const uint32_t  nxt_unicode_lower
 };
 
 
-static const uint32_t  nxt_unicode_lower_case_block_004[128]  nxt_aligned(64) 
= {
+static const uint32_t  nxt_unicode_lower_case_block_004[128]
+nxt_aligned(64) =
+{
 0x00201, 0x00201, 0x00203, 0x00203, 0x00205, 0x00205, 0x00207, 0x00207,
 0x00209, 0x00209, 0x0020b, 0x0020b, 0x0020d, 0x0020d, 0x0020f, 0x0020f,
 0x00211, 0x00211, 0x00213, 0x00213, 0x00215, 0x00215, 0x00217, 0x00217,
@@ -109,7 +119,9 @@ static const uint32_t  nxt_unicode_lower
 };
 
 
-static const uint32_t  nxt_unicode_lower_case_block_006[128]  nxt_aligned(64) 
= {
+static const uint32_t  nxt_unicode_lower_case_block_006[128]
+nxt_aligned(64) =
+{
 0x00300, 0x00301, 0x00302, 0x00303, 0x00304, 0x00305, 0x00306, 0x00307,
 0x00308, 0x00309, 0x0030a, 0x0030b, 0x0030c, 0x0030d, 0x0030e, 0x0030f,
 0x00310, 0x00311, 0x00312, 0x00313, 0x00314, 0x00315, 0x00316, 0x00317,
@@ -129,7 +141,9 @@ static const uint32_t  nxt_unicode_lower
 };
 
 
-static const uint32_t  nxt_unicode_lower_case_block_007[128]  nxt_aligned(64) 
= {
+static const uint32_t  nxt_unicode_lower_case_block_007[128]
+nxt_aligned(64) =
+{
 0x00380, 0x00381, 0x00382, 0x00383, 0x00384, 0x00385, 0x003ac, 0x00387,
 0x003ad, 0x003ae, 0x003af, 0x0038b, 0x003cc, 0x0038d, 0x003cd, 0x003ce,
 0x00390, 0x003b1, 0x003b2, 0x003b3, 0x003b4, 0x003b5, 0x003b6, 0x003b7,
@@ -149,7 +163,9 @@ static const uint32_t  nxt_unicode_lower
 };
 
 
-static const uint32_t  nxt_unicode_lower_case_block_008[128]  nxt_aligned(64) 
= {
+static const uint32_t  nxt_unicode_lower_case_block_008[128]
+nxt_aligned(64) =
+{
 0x00450, 0x00451, 0x00452, 0x00453, 0x00454, 0x00455, 0x00456, 0x00457,
 0x00458, 0x00459, 0x0045a, 0x0045b, 0x0045c, 0x0045d, 0x0045e, 0x0045f,
 0x00430, 0x00431, 0x00432, 0x00433, 0x00434, 0x00435, 0x00436, 0x00437,
@@ -169,7 +185,9 @@ static const uint32_t  nxt_unicode_lower
 };
 
 
-static const uint32_t  nxt_unicode_lower_case_block_009[128]  nxt_aligned(64) 
= {
+static const uint32_t  nxt_unicode_lower_case_block_009[128]
+nxt_aligned(64) =
+{
 0x00481, 0x00481, 0x00482, 0x00483, 0x00484, 0x00485, 0x00486, 0x00487,
 0x00488, 0x00489, 0x0048b, 0x0048b, 0x0048d, 0x0048d, 0x0048f, 0x0048f,
 0x00491, 0x00491, 0x00493, 0

[njs] Disabled njs_object_prop_alloc() inlining.

2017-08-08 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/bd7e5e51b6be
branches:  
changeset: 394:bd7e5e51b6be
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Aug 08 18:05:11 2017 +0300
description:
Disabled njs_object_prop_alloc() inlining.

diffstat:

 njs/njs_object.c |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r 49a8c7cfb121 -r bd7e5e51b6be njs/njs_object.c
--- a/njs/njs_object.c  Tue Aug 08 17:47:56 2017 +0300
+++ b/njs/njs_object.c  Tue Aug 08 18:05:11 2017 +0300
@@ -173,7 +173,7 @@ njs_object_hash_test(nxt_lvlhsh_query_t 
 }
 
 
-njs_object_prop_t *
+nxt_noinline njs_object_prop_t *
 njs_object_prop_alloc(njs_vm_t *vm, const njs_value_t *name,
 const njs_value_t *value, uint8_t attributes)
 {
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Style fixes.

2017-08-08 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/e2baf506be4c
branches:  
changeset: 391:e2baf506be4c
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Aug 08 17:47:53 2017 +0300
description:
Style fixes.

diffstat:

 njs/njs_generator.c |  5 +
 njs/njs_variable.c  |  3 ---
 2 files changed, 1 insertions(+), 7 deletions(-)

diffs (59 lines):

diff -r c347ea0bbdd6 -r e2baf506be4c njs/njs_generator.c
--- a/njs/njs_generator.c   Tue Jul 18 19:25:50 2017 +0300
+++ b/njs/njs_generator.c   Tue Aug 08 17:47:53 2017 +0300
@@ -380,7 +380,7 @@ njs_generate_builtin_object(njs_vm_t *vm
 
 node->index = njs_generator_dest_index(vm, parser, node);
 if (nxt_slow_path(node->index == NJS_INDEX_ERROR)) {
-return node->index;
+return NXT_ERROR;
 }
 
 njs_generate_code(parser, njs_vmcode_object_copy_t, copy);
@@ -2541,13 +2541,11 @@ njs_generator_temp_index_get(njs_vm_t *v
 }
 
 if (vm->accumulative && scope->type == NJS_SCOPE_GLOBAL) {
-
 /*
  * When non-clonable VM runs in accumulative mode
  * all global variables are allocated in absolute scope
  * to simplify global scope handling.
  */
-
 value = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t),
 sizeof(njs_value_t));
 if (nxt_slow_path(value == NULL)) {
@@ -2557,7 +2555,6 @@ njs_generator_temp_index_get(njs_vm_t *v
 index = (njs_index_t) value;
 
 } else {
-
 value = nxt_array_add(scope->values[0], _array_mem_proto,
   vm->mem_cache_pool);
 if (nxt_slow_path(value == NULL)) {
diff -r c347ea0bbdd6 -r e2baf506be4c njs/njs_variable.c
--- a/njs/njs_variable.cTue Jul 18 19:25:50 2017 +0300
+++ b/njs/njs_variable.cTue Aug 08 17:47:53 2017 +0300
@@ -356,13 +356,11 @@ njs_variable_get(njs_vm_t *vm, njs_parse
 }
 
 if (vm->accumulative && vs.scope->type == NJS_SCOPE_GLOBAL) {
-
 /*
  * When non-clonable VM runs in accumulative mode all
  * global variables should be allocated in absolute scope
  * to share them among consecutive VM invocations.
  */
-
 value = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t),
 sizeof(njs_value_t));
 if (nxt_slow_path(value == NULL)) {
@@ -391,7 +389,6 @@ njs_variable_get(njs_vm_t *vm, njs_parse
 
 index = vs.scope->next_index[n];
 vs.scope->next_index[n] += sizeof(njs_value_t);
-
 }
 
 if (njs_is_object(>value)) {
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Trailer content after script is optional.

2017-07-17 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/bef6842774f6
branches:  
changeset: 386:bef6842774f6
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon Jul 17 14:46:35 2017 +0300
description:
Trailer content after script is optional.

diffstat:

 njs/njs_parser.c |  16 
 njs/njs_vm.h |   2 ++
 njs/njscript.c   |   2 ++
 njs/njscript.h   |   2 ++
 njs/test/njs_unit_test.c |  10 --
 5 files changed, 26 insertions(+), 6 deletions(-)

diffs (110 lines):

diff -r 0ad7f75f9dbf -r bef6842774f6 njs/njs_parser.c
--- a/njs/njs_parser.c  Fri Jul 07 19:17:26 2017 +0300
+++ b/njs/njs_parser.c  Mon Jul 17 14:46:35 2017 +0300
@@ -115,7 +115,7 @@ njs_parser(njs_vm_t *vm, njs_parser_t *p
 return NULL;
 }
 
-if (token == NJS_TOKEN_CLOSE_BRACE) {
+if (token == NJS_TOKEN_CLOSE_BRACE && vm->trailer) {
 parser->lexer->start--;
 break;
 }
@@ -332,9 +332,13 @@ njs_parser_statement(njs_vm_t *vm, njs_p
 return njs_parser_block_statement(vm, parser);
 
 case NJS_TOKEN_CLOSE_BRACE:
-parser->node = NULL;
-nxt_thread_log_debug("BLOCK END");
-return token;
+if (vm->trailer) {
+parser->node = NULL;
+nxt_thread_log_debug("BLOCK END");
+return token;
+}
+
+/* Fall through. */
 
 default:
 token = njs_parser_expression(vm, parser, token);
@@ -1043,6 +1047,10 @@ njs_parser_switch_statement(njs_vm_t *vm
 
 parser->node = NULL;
 
+if (token == NJS_TOKEN_CLOSE_BRACE) {
+break;
+}
+
 } else if (branch == NULL) {
 /* The first switch statment is not "case/default" keyword. */
 return NJS_TOKEN_ILLEGAL;
diff -r 0ad7f75f9dbf -r bef6842774f6 njs/njs_vm.h
--- a/njs/njs_vm.h  Fri Jul 07 19:17:26 2017 +0300
+++ b/njs/njs_vm.h  Mon Jul 17 14:46:35 2017 +0300
@@ -902,6 +902,8 @@ struct njs_vm_s {
 
 nxt_trace_t  trace;
 nxt_random_t random;
+
+uint8_t  trailer;  /* 1 bit */
 };
 
 
diff -r 0ad7f75f9dbf -r bef6842774f6 njs/njscript.c
--- a/njs/njscript.cFri Jul 07 19:17:26 2017 +0300
+++ b/njs/njscript.cMon Jul 17 14:46:35 2017 +0300
@@ -173,6 +173,8 @@ njs_vm_create(njs_vm_opt_t *options)
 vm->trace.size = 2048;
 vm->trace.handler = njs_parser_trace_handler;
 vm->trace.data = vm;
+
+vm->trailer = options->trailer;
 }
 
 return vm;
diff -r 0ad7f75f9dbf -r bef6842774f6 njs/njscript.h
--- a/njs/njscript.hFri Jul 07 19:17:26 2017 +0300
+++ b/njs/njscript.hMon Jul 17 14:46:35 2017 +0300
@@ -69,6 +69,8 @@ typedef struct {
 nxt_lvlhsh_t*externals;
 njs_vm_shared_t *shared;
 nxt_mem_cache_pool_t*mcp;
+
+uint8_t trailer;   /* 1 bit */
 } njs_vm_opt_t;
 
 
diff -r 0ad7f75f9dbf -r bef6842774f6 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Fri Jul 07 19:17:26 2017 +0300
+++ b/njs/test/njs_unit_test.c  Mon Jul 17 14:46:35 2017 +0300
@@ -28,6 +28,12 @@ typedef struct {
 
 static njs_unit_test_t  njs_test[] =
 {
+{ nxt_string("}"),
+  nxt_string("SyntaxError: Unexpected token \"}\" in 1") },
+
+{ nxt_string("1}"),
+  nxt_string("SyntaxError: Unexpected token \"}\" in 1") },
+
 /* Variable declarations. */
 
 { nxt_string("var x"),
@@ -1898,7 +1904,7 @@ 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("var a = [3], b; if (1==1||2==2) { b = '1'+'2'+a[0] }; b"),
   nxt_string("123") },
 
 { nxt_string("(function(){ if(true) return 1 else return 0; })()"),
@@ -2122,7 +2128,7 @@ static njs_unit_test_t  njs_test[] =
   nxt_string("10") },
 
 { nxt_string("var a = [1,2,3,4,5]; var s = 0, i;"
- "for (i in a) if (a[i] > 4) break; s += a[i] } s"),
+ "for (i in a) if (a[i] > 4) break; s += a[i]; s"),
   nxt_string("5") },
 
 /**/
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Version 0.1.11.

2017-06-27 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/fc5df33f4e6b
branches:  
changeset: 379:fc5df33f4e6b
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Jun 27 14:17:12 2017 +0300
description:
Version 0.1.11.

diffstat:

 CHANGES  |  22 ++
 Makefile |   2 +-
 2 files changed, 23 insertions(+), 1 deletions(-)

diffs (39 lines):

diff -r 30cc8990272a -r fc5df33f4e6b CHANGES
--- a/CHANGES   Tue Jun 27 11:17:54 2017 +0300
+++ b/CHANGES   Tue Jun 27 14:17:12 2017 +0300
@@ -1,3 +1,25 @@
+
+Changes with nJScript 0.1.11 27 Jun 2017
+
+*) Feature: Object.keys(), Object.prototype.hasOwnProperty() methods.
+
+*) Feature: Object.defineProperty(), Object.defineProperties(),
+   Object.getOwnPropertyDescriptor() methods.
+
+*) Feature: Object.getPrototypeOf(), Object.prototype.isPrototypeOf()
+   methods.
+
+*) Feature: Object.preventExtensions(), Object.isExtensible(),
+   Object.freeze(), Object.isFrozen(), Object.seal(), Object.isSealed()
+   methods.
+
+*) Feature: scientific notation literals support.
+
+*) Feature: hexadecimal literals support.
+
+*) Bugfix: processing of large array indexes.
+
+*) Bugfix: in parseInt() and Date.parse().
 
 Changes with nJScript 0.1.10 04 Apr 2017
 
diff -r 30cc8990272a -r fc5df33f4e6b Makefile
--- a/Makefile  Tue Jun 27 11:17:54 2017 +0300
+++ b/Makefile  Tue Jun 27 14:17:12 2017 +0300
@@ -1,5 +1,5 @@
 
-NJS_VER =  0.1.10
+NJS_VER =  0.1.11
 
 NXT_LIB =  nxt
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Style fixes and small miscellaneous changes.

2017-06-27 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/30cc8990272a
branches:  
changeset: 378:30cc8990272a
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Jun 27 11:17:54 2017 +0300
description:
Style fixes and small miscellaneous changes.

diffstat:

 nginx/ngx_http_js_module.c |   2 +-
 njs/njs_date.c |   4 ++--
 njs/njs_number.c   |  14 +++---
 njs/njs_object.c   |   4 ++--
 njs/njs_string.c   |  24 
 nxt/nxt_lvlhsh.c   |   4 ++--
 nxt/nxt_lvlhsh.h   |  12 ++--
 nxt/nxt_rbtree.c   |   1 -
 nxt/nxt_utf8.c |   2 +-
 9 files changed, 29 insertions(+), 38 deletions(-)

diffs (223 lines):

diff -r d882561d50e8 -r 30cc8990272a nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.cFri Jun 23 15:49:09 2017 +0300
+++ b/nginx/ngx_http_js_module.cTue Jun 27 11:17:54 2017 +0300
@@ -139,7 +139,7 @@ static ngx_command_t  ngx_http_js_comman
 { ngx_string("js_set"),
   NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE2,
   ngx_http_js_set,
-  NGX_HTTP_LOC_CONF_OFFSET,
+  0,
   0,
   NULL },
 
diff -r d882561d50e8 -r 30cc8990272a njs/njs_date.c
--- a/njs/njs_date.cFri Jun 23 15:49:09 2017 +0300
+++ b/njs/njs_date.cTue Jun 27 11:17:54 2017 +0300
@@ -1052,8 +1052,8 @@ njs_date_prototype_to_iso_string(njs_vm_
 year = tm.tm_year + 1900;
 
 size = snprintf((char *) buf, NJS_ISO_DATE_TIME_LEN,
-(year < 0) ? "%07d-%02d-%02dT%02d:%02d:%02d.%03dZ":
- "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
+(year < 0) ? "%07d-%02d-%02dT%02d:%02d:%02d.%03dZ"
+   : "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
 year, tm.tm_mon + 1, tm.tm_mday,
 tm.tm_hour, tm.tm_min, tm.tm_sec,
 (int) ((int64_t) time % 1000));
diff -r d882561d50e8 -r 30cc8990272a njs/njs_number.c
--- a/njs/njs_number.c  Fri Jun 23 15:49:09 2017 +0300
+++ b/njs/njs_number.c  Tue Jun 27 11:17:54 2017 +0300
@@ -89,7 +89,7 @@ njs_number_dec_parse(u_char **start, u_c
 num = 0;
 
 while (p < end) {
-/* Values below '0' become >= 208. */
+/* Values less than '0' become >= 208. */
 c = *p - '0';
 
 if (nxt_slow_path(c > 9)) {
@@ -106,7 +106,7 @@ njs_number_dec_parse(u_char **start, u_c
 scale = 1;
 
 for (p++; p < end; p++) {
-/* Values below '0' become >= 208. */
+/* Values less than '0' become >= 208. */
 c = *p - '0';
 
 if (nxt_slow_path(c > 9)) {
@@ -135,7 +135,7 @@ njs_number_dec_parse(u_char **start, u_c
 }
 }
 
-/* Values below '0' become >= 208. */
+/* Values less than '0' become >= 208. */
 c = *e - '0';
 
 if (nxt_fast_path(c <= 9)) {
@@ -143,7 +143,7 @@ njs_number_dec_parse(u_char **start, u_c
 p = e + 1;
 
 while (p < end) {
-/* Values below '0' become >= 208. */
+/* Values less than '0' become >= 208. */
 c = *p - '0';
 
 if (nxt_slow_path(c > 9)) {
@@ -180,11 +180,11 @@ njs_number_hex_parse(u_char **start, u_c
 while (p < end) {
 c = (u_char) (*p | 0x20);
 
-/* Values below '0' become >= 208. */
+/* Values less than '0' become >= 208. */
 c = c - '0';
 
 if (c > 9) {
-/* Values below 'a' become >= 159. */
+/* Values less than 'a' become >= 159. */
 c = c - ('a' - '0');
 
 if (nxt_slow_path(c > 5)) {
@@ -800,7 +800,7 @@ njs_number_parse_int(njs_vm_t *vm, njs_v
 n = njs_number_radix_parse(, end, radix);
 
 if (n >= 0) {
-num = (minus) ? -n : n;
+num = minus ? -n : n;
 }
 }
 
diff -r d882561d50e8 -r 30cc8990272a njs/njs_object.c
--- a/njs/njs_object.c  Fri Jun 23 15:49:09 2017 +0300
+++ b/njs/njs_object.c  Tue Jun 27 11:17:54 2017 +0300
@@ -915,8 +915,8 @@ njs_object_is_extensible(njs_vm_t *vm, n
 return NXT_ERROR;
 }
 
-retval = args[1].data.u.object->extensible ? _string_true :
- _string_false;
+retval = args[1].data.u.object->extensible ? _string_true
+   : _string_false;
 
 vm->retval = *retval;
 
diff -r d882561d50e8 -r 30cc8990272a njs/njs_string.c
--- a/njs/njs_string.c  Fri Jun 23 15:49:09 2017 +0300
+++ b/njs/njs_string.c  Tue Jun 27 11:17:54 2017 +0300
@@ -2555,11 +2555,11 @@ static njs_ret_t
 njs_string_replace_search(njs_vm_t *vm, njs_value_t *args,
 njs_string_replace_t *r)
 {
-intcaptures[2];
-u_char *p, *end;
-size_t size;
-njs_ret_t   

[njs] Added tag 0.1.11 for changeset fc5df33f4e6b

2017-06-27 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/a0285736926b
branches:  
changeset: 380:a0285736926b
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Jun 27 14:19:20 2017 +0300
description:
Added tag 0.1.11 for changeset fc5df33f4e6b

diffstat:

 .hgtags |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (8 lines):

diff -r fc5df33f4e6b -r a0285736926b .hgtags
--- a/.hgtags   Tue Jun 27 14:17:12 2017 +0300
+++ b/.hgtags   Tue Jun 27 14:19:20 2017 +0300
@@ -9,3 +9,4 @@ 15dc54100400f99c3ec044d8fb0175dd3d69adcb
 a29f29d481125db6101ecdc23dc20187c143cdc9 0.1.8
 5bd2833988222900f60ad9b330ebc44df3b30662 0.1.9
 b1456ef3e002376d9d146a8a02acf6a4a21748e9 0.1.10
+fc5df33f4e6b02a673daf3728ff690fb1e09b95e 0.1.11
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Time zone name has been removed from unit tests.

2017-06-23 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/d882561d50e8
branches:  
changeset: 377:d882561d50e8
user:  Igor Sysoev <i...@sysoev.ru>
date:  Fri Jun 23 15:49:09 2017 +0300
description:
Time zone name has been removed from unit tests.

diffstat:

 njs/test/njs_unit_test.c |  13 ++---
 1 files changed, 6 insertions(+), 7 deletions(-)

diffs (27 lines):

diff -r e33bea39c650 -r d882561d50e8 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Fri Jun 23 15:27:28 2017 +0300
+++ b/njs/test/njs_unit_test.c  Fri Jun 23 15:49:09 2017 +0300
@@ -6361,17 +6361,16 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("var d = new Date(2011, 5, 24, 18, 45); d.valueOf()"),
   nxt_string("130889520") },
 
-{ nxt_string("var d = new Date(2011, 5, 24, 18, 45); d"),
-  nxt_string("Fri Jun 24 2011 18:45:00 GMT+1245 (CHAST)") },
-
-{ nxt_string("var d = new Date(2011, 5, 24, 18, 45); d.toString()"),
-  nxt_string("Fri Jun 24 2011 18:45:00 GMT+1245 (CHAST)") },
+{ nxt_string("var d = new Date(2011, 5, 24, 18, 45);"
+ "d.toString().slice(0, 33)"),
+  nxt_string("Fri Jun 24 2011 18:45:00 GMT+1245") },
 
 { nxt_string("var d = new Date(2011, 5, 24, 18, 45); d.toDateString()"),
   nxt_string("Fri Jun 24 2011") },
 
-{ nxt_string("var d = new Date(2011, 5, 24, 18, 45); d.toTimeString()"),
-  nxt_string("18:45:00 GMT+1245 (CHAST)") },
+{ nxt_string("var d = new Date(2011, 5, 24, 18, 45);"
+ "d.toTimeString().slice(0, 17)"),
+  nxt_string("18:45:00 GMT+1245") },
 
 { nxt_string("var d = new Date(2011, 5, 24, 18, 45); d.toUTCString()"),
   nxt_string("Fri Jun 24 2011 06:00:00 GMT") },
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed processing of large array indexes.

2017-06-23 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/e33bea39c650
branches:  
changeset: 376:e33bea39c650
user:  Igor Sysoev <i...@sysoev.ru>
date:  Fri Jun 23 15:27:28 2017 +0300
description:
Fixed processing of large array indexes.

diffstat:

 njs/njs_vm.c |  13 +++--
 njs/test/njs_unit_test.c |   3 +++
 2 files changed, 10 insertions(+), 6 deletions(-)

diffs (53 lines):

diff -r 44ca33e6afdb -r e33bea39c650 njs/njs_vm.c
--- a/njs/njs_vm.c  Thu Jun 22 18:56:26 2017 +0300
+++ b/njs/njs_vm.c  Fri Jun 23 15:27:28 2017 +0300
@@ -73,7 +73,7 @@ struct njs_property_next_s {
 static nxt_noinline njs_ret_t njs_property_query(njs_vm_t *vm,
 njs_property_query_t *pq, njs_value_t *object, njs_value_t *property);
 static njs_ret_t njs_array_property_query(njs_vm_t *vm,
-njs_property_query_t *pq, njs_value_t *object, int32_t index);
+njs_property_query_t *pq, njs_value_t *object, uint32_t index);
 static njs_ret_t njs_object_property_query(njs_vm_t *vm,
 njs_property_query_t *pq, njs_value_t *value, njs_object_t *object);
 static njs_ret_t njs_method_private_copy(njs_vm_t *vm,
@@ -1054,21 +1054,22 @@ njs_property_query(njs_vm_t *vm, njs_pro
 
 static njs_ret_t
 njs_array_property_query(njs_vm_t *vm, njs_property_query_t *pq,
-njs_value_t *object, int32_t index)
+njs_value_t *object, uint32_t index)
 {
-int32_t  size;
+uint32_t size;
 njs_ret_tret;
 njs_value_t  *value;
 njs_array_t  *array;
 
 array = object->data.u.array;
-size = index - array->length;
-
-if (size >= 0) {
+
+if (index >= array->length) {
 if (pq->query != NJS_PROPERTY_QUERY_SET) {
 return NXT_DECLINED;
 }
 
+size = index - array->length;
+
 ret = njs_array_expand(vm, array, 0, size + 1);
 if (nxt_slow_path(ret != NXT_OK)) {
 return ret;
diff -r 44ca33e6afdb -r e33bea39c650 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Thu Jun 22 18:56:26 2017 +0300
+++ b/njs/test/njs_unit_test.c  Fri Jun 23 15:27:28 2017 +0300
@@ -2487,6 +2487,9 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("var a = [ 1, 2, 3 ]; a[4294967296] = 4; a + a[4294967296]"),
   nxt_string("1,2,34") },
 
+{ nxt_string("delete[]['4e9']"),
+  nxt_string("false") },
+
 { nxt_string("var n = 1, a = [ n += 1 ]; a"),
   nxt_string("2") },
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] A fix of bug introduced in changeset 7f1f3dcb278f.

2017-05-29 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/4e2da602c2a3
branches:  
changeset: 346:4e2da602c2a3
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon May 29 22:13:21 2017 +0300
description:
A fix of bug introduced in changeset 7f1f3dcb278f.

diffstat:

 njs/njs_parser.c |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r c0bdd23e740e -r 4e2da602c2a3 njs/njs_parser.c
--- a/njs/njs_parser.c  Mon May 29 10:17:36 2017 +0300
+++ b/njs/njs_parser.c  Mon May 29 22:13:21 2017 +0300
@@ -2434,7 +2434,7 @@ njs_parser_escape_string_create(njs_vm_t
 }
 
 } else {
-if ((src - p) > 6 || src == end || *(++src) == '}') {
+if ((src - p) > 6 || src == end || *src++ != '}') {
 goto invalid;
 }
 }
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] A small rbtree delete fixup optimization.

2017-05-29 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/c0bdd23e740e
branches:  
changeset: 345:c0bdd23e740e
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon May 29 10:17:36 2017 +0300
description:
A small rbtree delete fixup optimization.

Setting node color to black is not required here because
it is already black.  Besides in the original algorithm
the node pointer is discarded and the node is set to tree
root just to quit the loop.

Thanks to ??? (Hong Zhi Dao).

diffstat:

 nxt/nxt_rbtree.c |  4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diffs (21 lines):

diff -r 7f1f3dcb278f -r c0bdd23e740e nxt/nxt_rbtree.c
--- a/nxt/nxt_rbtree.c  Sat May 27 18:02:09 2017 +0300
+++ b/nxt/nxt_rbtree.c  Mon May 29 10:17:36 2017 +0300
@@ -402,7 +402,7 @@ nxt_rbtree_delete_fixup(nxt_rbtree_t *tr
 
 nxt_rbtree_left_rotate(parent);
 
-break;
+return;
 
 } else {
 sibling = parent->left;
@@ -440,7 +440,7 @@ nxt_rbtree_delete_fixup(nxt_rbtree_t *tr
 
 nxt_rbtree_right_rotate(parent);
 
-break;
+return;
 }
 }
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Unicode code point parsing optimization.

2017-05-28 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/7f1f3dcb278f
branches:  
changeset: 344:7f1f3dcb278f
user:  Igor Sysoev <i...@sysoev.ru>
date:  Sat May 27 18:02:09 2017 +0300
description:
Unicode code point parsing optimization.

diffstat:

 njs/njs_parser.c |  45 -
 1 files changed, 24 insertions(+), 21 deletions(-)

diffs (93 lines):

diff -r 7156ba123eae -r 7f1f3dcb278f njs/njs_parser.c
--- a/njs/njs_parser.c  Fri May 26 20:10:22 2017 +0300
+++ b/njs/njs_parser.c  Sat May 27 18:02:09 2017 +0300
@@ -2303,7 +2303,7 @@ njs_parser_escape_string_create(njs_vm_t
 njs_value_t *value)
 {
 u_char   c, *p, *start, *dst, *src, *end, *hex_end;
-size_t   size, length, hex_length, skip;
+size_t   size, length, hex_length;
 int64_t  u;
 
 start = NULL;
@@ -2334,35 +2334,25 @@ njs_parser_escape_string_create(njs_vm_t
 switch (c) {
 
 case 'u':
-skip = 0;
 hex_length = 4;
-
 /*
  * A character after "u" can be safely tested here
  * because there is always a closing quote at the
  * end of string: ...\u".
  */
-if (*src == '{') {
-hex_length = 0;
-src++;
-
-for (p = src; p < end && *p != '}'; p++) {
-hex_length++;
-}
-
-if (hex_length == 0 || hex_length > 6) {
-goto invalid;
-}
-
-skip = 1;
+if (*src != '{') {
+goto hex_length_test;
 }
 
+src++;
+hex_length = 0;
+hex_end = end;
+
 goto hex;
 
 case 'x':
-skip = 0;
 hex_length = 2;
-goto hex;
+goto hex_length_test;
 
 case '0':
 c = '\0';
@@ -2421,7 +2411,7 @@ njs_parser_escape_string_create(njs_vm_t
 
 continue;
 
-hex:
+hex_length_test:
 
 hex_end = src + hex_length;
 
@@ -2429,13 +2419,26 @@ njs_parser_escape_string_create(njs_vm_t
 goto invalid;
 }
 
+hex:
+
+p = src;
 u = njs_number_radix_parse(, hex_end, 16);
 
-if (nxt_slow_path(src != hex_end)) {
+if (nxt_slow_path(u < 0)) {
 goto invalid;
 }
 
-src += skip;
+if (hex_length != 0) {
+if (src != hex_end) {
+goto invalid;
+}
+
+} else {
+if ((src - p) > 6 || src == end || *(++src) == '}') {
+goto invalid;
+}
+}
+
 size += nxt_utf8_size(u);
 length++;
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] parseInt() did not test invalid values.

2017-05-26 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/be8d68d4b8b5
branches:  
changeset: 342:be8d68d4b8b5
user:  Igor Sysoev <i...@sysoev.ru>
date:  Fri May 26 20:07:24 2017 +0300
description:
parseInt() did not test invalid values.

diffstat:

 njs/njs_number.c |  22 --
 njs/njs_number.h |   3 +--
 njs/njs_parser.c |   7 ---
 njs/test/njs_unit_test.c |  10 --
 4 files changed, 25 insertions(+), 17 deletions(-)

diffs (117 lines):

diff -r fc6c8da00858 -r be8d68d4b8b5 njs/njs_number.c
--- a/njs/njs_number.c  Thu May 25 14:16:31 2017 +0300
+++ b/njs/njs_number.c  Fri May 26 20:07:24 2017 +0300
@@ -132,9 +132,11 @@ njs_number_parse(const u_char **start, c
 
 
 int64_t
-njs_number_radix_parse(u_char *p, u_char *end, uint8_t radix, nxt_bool_t exact)
+njs_number_radix_parse(u_char **start, u_char *end, uint8_t radix)
 {
+u_char*p;
 uint8_t   d;
+int64_t   num;
 uint64_t  n;
 
 static const int8_t  digits[256]
@@ -158,19 +160,23 @@ njs_number_radix_parse(u_char *p, u_char
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 };
 
+num = -1;
 n = 0;
 
-while (p < end) {
-d = digits[*p++];
+for (p = *start; p < end; p++) {
+d = digits[*p];
 
 if (nxt_slow_path(d >= radix)) {
-return (exact) ? -1 : (int64_t) n;
+break;
 }
 
 n = (n * radix) + d;
+num = n;
 }
 
-return n;
+*start = p;
+
+return num;
 }
 
 
@@ -715,11 +721,7 @@ njs_number_parse_int(njs_vm_t *vm, njs_v
 radix = 16;
 }
 
-if (p == end) {
-goto done;
-}
-
-n = njs_number_radix_parse(p, end, radix, 0);
+n = njs_number_radix_parse(, end, radix);
 
 if (n >= 0) {
 num = (minus) ? -n : n;
diff -r fc6c8da00858 -r be8d68d4b8b5 njs/njs_number.h
--- a/njs/njs_number.h  Thu May 25 14:16:31 2017 +0300
+++ b/njs/njs_number.h  Fri May 26 20:07:24 2017 +0300
@@ -13,8 +13,7 @@
 
 double njs_value_to_number(njs_value_t *value);
 double njs_number_parse(const u_char **start, const u_char *end);
-int64_t njs_number_radix_parse(u_char *p, u_char *end, uint8_t radix,
-nxt_bool_t exact);
+int64_t njs_number_radix_parse(u_char **start, u_char *end, uint8_t radix);
 njs_ret_t njs_number_to_string(njs_vm_t *vm, njs_value_t *string,
 const njs_value_t *number);
 njs_ret_t njs_number_constructor(njs_vm_t *vm, njs_value_t *args,
diff -r fc6c8da00858 -r be8d68d4b8b5 njs/njs_parser.c
--- a/njs/njs_parser.c  Thu May 25 14:16:31 2017 +0300
+++ b/njs/njs_parser.c  Fri May 26 20:07:24 2017 +0300
@@ -2429,12 +2429,13 @@ njs_parser_escape_string_create(njs_vm_t
 goto invalid;
 }
 
-u = njs_number_radix_parse(src, hex_end, 16, 1);
-if (nxt_slow_path(u < 0)) {
+u = njs_number_radix_parse(, hex_end, 16);
+
+if (nxt_slow_path(src != hex_end)) {
 goto invalid;
 }
 
-src = hex_end + skip;
+src += skip;
 size += nxt_utf8_size(u);
 length++;
 
diff -r fc6c8da00858 -r be8d68d4b8b5 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Thu May 25 14:16:31 2017 +0300
+++ b/njs/test/njs_unit_test.c  Fri May 26 20:07:24 2017 +0300
@@ -3139,6 +3139,9 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("'\\u'"),
   nxt_string("SyntaxError: Invalid Unicode code point \"\\u\" in 1") },
 
+{ nxt_string("'\\u'"),
+  nxt_string("SyntaxError: Invalid Unicode code point \"\\u\" in 1") },
+
 { nxt_string("'\\u03B'"),
   nxt_string("SyntaxError: Invalid Unicode code point \"\\u03B\" in 1") },
 
@@ -7050,8 +7053,11 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("parseInt('0x')"),
   nxt_string("NaN") },
 
-{ nxt_string("parseInt('0x', 10)"),
-  nxt_string("0") },
+{ nxt_string("parseInt('z')"),
+  nxt_string("NaN") },
+
+{ nxt_string("parseInt('0xz')"),
+  nxt_string("NaN") },
 
 { nxt_string("parseInt('0x', 16)"),
   nxt_string("NaN") },
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] A small rbtree insert fixup optimization.

2017-05-26 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/7156ba123eae
branches:  
changeset: 343:7156ba123eae
user:  Igor Sysoev <i...@sysoev.ru>
date:  Fri May 26 20:10:22 2017 +0300
description:
A small rbtree insert fixup optimization.

Thanks to ??? (Hong Zhi Dao).

diffstat:

 nxt/nxt_rbtree.c |  13 +
 1 files changed, 9 insertions(+), 4 deletions(-)

diffs (36 lines):

diff -r be8d68d4b8b5 -r 7156ba123eae nxt/nxt_rbtree.c
--- a/nxt/nxt_rbtree.c  Fri May 26 20:07:24 2017 +0300
+++ b/nxt/nxt_rbtree.c  Fri May 26 20:10:22 2017 +0300
@@ -129,11 +129,15 @@ nxt_rbtree_insert_fixup(nxt_rbtree_node_
 nxt_rbtree_left_rotate(node);
 }
 
+/*
+ * nxt_rbtree_left_rotate() swaps parent and
+ * child whilst keeps grandparent the same.
+ */
 parent = node->parent;
+
 parent->color = NXT_RBTREE_BLACK;
+grandparent->color = NXT_RBTREE_RED;
 
-grandparent = parent->parent;
-grandparent->color = NXT_RBTREE_RED;
 nxt_rbtree_right_rotate(grandparent);
 /*
  * nxt_rbtree_right_rotate() does not change node->parent
@@ -153,11 +157,12 @@ nxt_rbtree_insert_fixup(nxt_rbtree_node_
 nxt_rbtree_right_rotate(node);
 }
 
+/* See the comment in the symmetric branch above. */
 parent = node->parent;
+
 parent->color = NXT_RBTREE_BLACK;
+grandparent->color = NXT_RBTREE_RED;
 
-grandparent = parent->parent;
-grandparent->color = NXT_RBTREE_RED;
 nxt_rbtree_left_rotate(grandparent);
 
 /* See the comment in the symmetric branch above. */
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [njs] Lexer support for hexadecimal literal values.

2017-05-25 Thread Igor Sysoev
Thank you for your patch.
We are currently working on comprehensive hexadecimal support.


-- 
Igor Sysoev
http://nginx.com

On 21 May 2017, at 20:52, Paulo Pacheco <fooi...@gmail.com> wrote:

> # HG changeset patch
> # User Paulo Pacheco <fooi...@gmail.com>
> # Date 1495388206 0
> #  Sun May 21 17:36:46 2017 +
> # Node ID 22db6b6a3a0eebff8453fb22035628410c05c5c8
> # Parent  96fda9957427e1ea78d0096b019a3f3183db7346
> [njs] Lexer support for hexadecimal literal values.
> 
> diff -r 96fda9957427 -r 22db6b6a3a0e njs/njs_lexer.c
> --- a/njs/njs_lexer.cWed Apr 19 17:48:56 2017 +0300
> +++ b/njs/njs_lexer.cSun May 21 17:36:46 2017 +
> @@ -19,7 +19,7 @@
>  #include 
>  #include 
>  #include 
> -
> +#include 
> 
>  typedef struct njs_lexer_multi_s  njs_lexer_multi_t;
> 
> @@ -539,10 +539,28 @@
>  {
>  u_char  c, *p;
>  double  num, frac, scale;
> +char *endptr;
> 
>  /* TODO: "1e2" */
> 
>  p = lexer->start;
> +
> +/* Hexadecimal literal values */
> +if ( (lexer->end - lexer->start) > 2
> +&& (*p == 'x' || *p == 'X')
> +&& (lexer->prev_token > 0
> +|| ((lexer->start - 1) == lexer->text.start)
> +)
> +&& (*(p-1) == '0')) {
> +
> +lexer->number = strtod((const char *) p-1, );
> +if ((u_char *) endptr <= lexer->end) {
> +lexer->start = (u_char *) endptr;
> +return NJS_TOKEN_NUMBER;
> +}
> +lexer->number = 0;
> +}
> +
>  c = p[-1];
> 
>  /* Values below '0' become >= 208. */
> diff -r 96fda9957427 -r 22db6b6a3a0e njs/test/njs_unit_test.c
> --- a/njs/test/njs_unit_test.cWed Apr 19 17:48:56 2017 +0300
> +++ b/njs/test/njs_unit_test.cSun May 21 17:36:46 2017 +
> @@ -112,6 +112,18 @@
>  { nxt_string("+1"),
>nxt_string("1") },
> 
> +{ nxt_string("var a = 0x01; a"),
> +  nxt_string("1") },
> +
> +{ nxt_string("var x = 0x; x"),
> +  nxt_string("65535") },
> +
> +{ nxt_string("0x01"),
> +  nxt_string("1") },
> +
> +{ nxt_string("0x"),
> +  nxt_string("65535") },
> +
>  { nxt_string("+1\n"),
>nxt_string("1") },
> 
> 
> -- CUT HERE 
> --
> Paulo Pacheco | Паулу Пашеку
> 
> 
> ___
> 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] Core: signal sender pid logging.

2017-04-20 Thread Igor Sysoev
details:   http://hg.nginx.org/nginx/rev/23ecffd5bcfe
branches:  
changeset: 6985:23ecffd5bcfe
user:  Igor Sysoev <i...@sysoev.ru>
date:  Thu Apr 20 13:58:16 2017 +0300
description:
Core: signal sender pid logging.

diffstat:

 src/os/unix/ngx_process.c |  32 
 1 files changed, 24 insertions(+), 8 deletions(-)

diffs (76 lines):

diff -r 201038680680 -r 23ecffd5bcfe src/os/unix/ngx_process.c
--- a/src/os/unix/ngx_process.c Tue Apr 18 19:55:23 2017 +0300
+++ b/src/os/unix/ngx_process.c Thu Apr 20 13:58:16 2017 +0300
@@ -15,13 +15,13 @@ typedef struct {
 int signo;
 char   *signame;
 char   *name;
-void  (*handler)(int signo);
+void  (*handler)(int signo, siginfo_t *siginfo, void *ucontext);
 } ngx_signal_t;
 
 
 
 static void ngx_execute_proc(ngx_cycle_t *cycle, void *data);
-static void ngx_signal_handler(int signo);
+static void ngx_signal_handler(int signo, siginfo_t *siginfo, void *ucontext);
 static void ngx_process_get_status(void);
 static void ngx_unlock_mutexes(ngx_pid_t pid);
 
@@ -75,9 +75,9 @@ ngx_signal_t  signals[] = {
 
 { SIGCHLD, "SIGCHLD", "", ngx_signal_handler },
 
-{ SIGSYS, "SIGSYS, SIG_IGN", "", SIG_IGN },
+{ SIGSYS, "SIGSYS, SIG_IGN", "", NULL },
 
-{ SIGPIPE, "SIGPIPE, SIG_IGN", "", SIG_IGN },
+{ SIGPIPE, "SIGPIPE, SIG_IGN", "", NULL },
 
 { 0, NULL, "", NULL }
 };
@@ -288,7 +288,15 @@ ngx_init_signals(ngx_log_t *log)
 
 for (sig = signals; sig->signo != 0; sig++) {
 ngx_memzero(, sizeof(struct sigaction));
-sa.sa_handler = sig->handler;
+
+if (sig->handler) {
+sa.sa_sigaction = sig->handler;
+sa.sa_flags = SA_SIGINFO;
+
+} else {
+sa.sa_handler = SIG_IGN;
+}
+
 sigemptyset(_mask);
 if (sigaction(sig->signo, , NULL) == -1) {
 #if (NGX_VALGRIND)
@@ -307,7 +315,7 @@ ngx_init_signals(ngx_log_t *log)
 
 
 static void
-ngx_signal_handler(int signo)
+ngx_signal_handler(int signo, siginfo_t *siginfo, void *ucontext)
 {
 char*action;
 ngx_int_tignore;
@@ -431,8 +439,16 @@ ngx_signal_handler(int signo)
 break;
 }
 
-ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
-  "signal %d (%s) received%s", signo, sig->signame, action);
+if (siginfo && siginfo->si_pid) {
+ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
+  "signal %d (%s) received from %P%s",
+  signo, sig->signame, siginfo->si_pid, action);
+
+} else {
+ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
+  "signal %d (%s) received%s",
+  signo, sig->signame, action);
+}
 
 if (ignore) {
 ngx_log_error(NGX_LOG_CRIT, ngx_cycle->log, 0,
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Version 0.1.10.

2017-04-04 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/b1456ef3e002
branches:  
changeset: 338:b1456ef3e002
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Apr 04 13:23:11 2017 +0300
description:
Version 0.1.10.

diffstat:

 CHANGES  |  9 +
 Makefile |  2 +-
 2 files changed, 10 insertions(+), 1 deletions(-)

diffs (26 lines):

diff -r 7e6460db39ad -r b1456ef3e002 CHANGES
--- a/CHANGES   Tue Apr 04 13:23:10 2017 +0300
+++ b/CHANGES   Tue Apr 04 13:23:11 2017 +0300
@@ -1,3 +1,12 @@
+
+Changes with nJScript 0.1.10 04 Apr 2017
+
+*) Feature: nested functions and function closures.
+
+*) Feature: Array.of(), Array.prototype.fill(), Array.prototype.find(),
+   Array.prototype.findIndex() methods.
+
+*) Bugfix: miscellaneous bugs and segmentation faults have been fixed.
 
 Changes with nJScript 0.1.9  01 Feb 2017
 
diff -r 7e6460db39ad -r b1456ef3e002 Makefile
--- a/Makefile  Tue Apr 04 13:23:10 2017 +0300
+++ b/Makefile  Tue Apr 04 13:23:11 2017 +0300
@@ -1,5 +1,5 @@
 
-NJS_VER =  0.1.9
+NJS_VER =  0.1.10
 
 NXT_LIB =  nxt
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Added tag 0.1.10 for changeset b1456ef3e002

2017-04-04 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/5a5b70cbbde9
branches:  
changeset: 339:5a5b70cbbde9
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Apr 04 13:24:09 2017 +0300
description:
Added tag 0.1.10 for changeset b1456ef3e002

diffstat:

 .hgtags |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (8 lines):

diff -r b1456ef3e002 -r 5a5b70cbbde9 .hgtags
--- a/.hgtags   Tue Apr 04 13:23:11 2017 +0300
+++ b/.hgtags   Tue Apr 04 13:24:09 2017 +0300
@@ -8,3 +8,4 @@ 44b524f7e313369cd062a387511ea6fdc427875f
 15dc54100400f99c3ec044d8fb0175dd3d69adcb 0.1.7
 a29f29d481125db6101ecdc23dc20187c143cdc9 0.1.8
 5bd2833988222900f60ad9b330ebc44df3b30662 0.1.9
+b1456ef3e002376d9d146a8a02acf6a4a21748e9 0.1.10
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Moving njs_array_prototype_fill() to appropriate place.

2017-04-04 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/f62632793238
branches:  
changeset: 336:f62632793238
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Apr 04 11:00:49 2017 +0300
description:
Moving njs_array_prototype_fill() to appropriate place.

diffstat:

 njs/njs_array.c |  126 
 1 files changed, 63 insertions(+), 63 deletions(-)

diffs (143 lines):

diff -r a4e6f27ce598 -r f62632793238 njs/njs_array.c
--- a/njs/njs_array.c   Tue Apr 04 10:56:33 2017 +0300
+++ b/njs/njs_array.c   Tue Apr 04 11:00:49 2017 +0300
@@ -1214,6 +1214,69 @@ done:
 
 
 static njs_ret_t
+njs_array_prototype_fill(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+njs_index_t unused)
+{
+nxt_int_ti, start, end, length;
+njs_array_t  *array;
+
+vm->retval = args[0];
+
+if (nargs < 2 || !njs_is_array([0])) {
+return NXT_OK;
+}
+
+array = args[0].data.u.array;
+length = array->length;
+
+if (length == 0) {
+return NXT_OK;
+}
+
+start = 0;
+end = length;
+
+if (nargs > 2) {
+start = args[2].data.u.number;
+
+if (start > length) {
+start = length;
+}
+
+if (start < 0) {
+start += length;
+
+if (start < 0) {
+start = 0;
+}
+}
+
+   if (nargs > 3) {
+   end = args[3].data.u.number;
+
+   if (end > length) {
+   end = length;
+   }
+
+   if (end < 0) {
+   end += length;
+
+   if (end < 0) {
+   end = 0;
+   }
+   }
+   }
+}
+
+for (i = start; i < end; i++) {
+array->start[i] = args[1];
+}
+
+return NXT_OK;
+}
+
+
+static njs_ret_t
 njs_array_prototype_for_each(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 njs_index_t unused)
 {
@@ -1352,69 +1415,6 @@ njs_array_prototype_every_continuation(n
 
 
 static njs_ret_t
-njs_array_prototype_fill(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
-njs_index_t unused)
-{
-nxt_int_ti, start, end, length;
-njs_array_t  *array;
-
-vm->retval = args[0];
-
-if (nargs < 2 || !njs_is_array([0])) {
-return NXT_OK;
-}
-
-array = args[0].data.u.array;
-length = array->length;
-
-if (length == 0) {
-return NXT_OK;
-}
-
-start = 0;
-end = length;
-
-if (nargs > 2) {
-start = args[2].data.u.number;
-
-if (start > length) {
-start = length;
-}
-
-if (start < 0) {
-start += length;
-
-if (start < 0) {
-start = 0;
-}
-}
-
-   if (nargs > 3) {
-   end = args[3].data.u.number;
-
-   if (end > length) {
-   end = length;
-   }
-
-   if (end < 0) {
-   end += length;
-
-   if (end < 0) {
-   end = 0;
-   }
-   }
-   }
-}
-
-for (i = start; i < end; i++) {
-array->start[i] = args[1];
-}
-
-return NXT_OK;
-}
-
-
-static njs_ret_t
 njs_array_prototype_filter(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 njs_index_t unused)
 {
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Style fixes and small miscellaneous changes.

2017-04-04 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/7e6460db39ad
branches:  
changeset: 337:7e6460db39ad
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Apr 04 13:23:10 2017 +0300
description:
Style fixes and small miscellaneous changes.

diffstat:

 njs/njs_array.c|  2 +-
 njs/njs_function.c |  4 ++--
 njs/njs_parser.c   |  2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diffs (45 lines):

diff -r f62632793238 -r 7e6460db39ad njs/njs_array.c
--- a/njs/njs_array.c   Tue Apr 04 11:00:49 2017 +0300
+++ b/njs/njs_array.c   Tue Apr 04 13:23:10 2017 +0300
@@ -2044,7 +2044,7 @@ njs_array_prototype_sort_continuation(nj
 sort->current++;
 n = sort->current;
 
-} while (sort->current < array->length);
+} while (n < array->length);
 }
 
 vm->retval = args[0];
diff -r f62632793238 -r 7e6460db39ad njs/njs_function.c
--- a/njs/njs_function.cTue Apr 04 11:00:49 2017 +0300
+++ b/njs/njs_function.cTue Apr 04 13:23:10 2017 +0300
@@ -162,7 +162,7 @@ njs_function_frame(njs_vm_t *vm, njs_fun
 nxt_bool_t ctor)
 {
 size_t size;
-nxt_uint_t n, max_args, closures;;
+nxt_uint_t n, max_args, closures;
 njs_value_t*value, *bound;
 njs_frame_t*frame;
 njs_native_frame_t *native_frame;
@@ -594,7 +594,7 @@ njs_function_activate(njs_vm_t *vm, njs_
 cont->retval = retval;
 
 cont->return_address = vm->current
-   + sizeof(njs_vmcode_function_call_t);;
+   + sizeof(njs_vmcode_function_call_t);
 vm->current = (u_char *) njs_continuation_nexus;
 
 return NJS_APPLIED;
diff -r f62632793238 -r 7e6460db39ad njs/njs_parser.c
--- a/njs/njs_parser.c  Tue Apr 04 11:00:49 2017 +0300
+++ b/njs/njs_parser.c  Tue Apr 04 13:23:10 2017 +0300
@@ -178,7 +178,7 @@ njs_parser_scope_begin(njs_vm_t *vm, njs
 if (type == NJS_SCOPE_FUNCTION) {
 scope->next_index[0] = type;
 scope->next_index[1] = NJS_SCOPE_CLOSURE + nesting
-   + sizeof(njs_value_t);;
+   + sizeof(njs_value_t);
 
 } else {
 if (type == NJS_SCOPE_GLOBAL) {
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Array.prototype.findIndex() method.

2017-04-04 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/26e0ebd97454
branches:  
changeset: 331:26e0ebd97454
user:  Andrey Zelenkov 
date:  Tue Apr 04 06:16:49 2017 +0300
description:
Array.prototype.findIndex() method.

diffstat:

 njs/njs_array.c  |  58 
 njs/test/njs_unit_test.c |  44 
 2 files changed, 102 insertions(+), 0 deletions(-)

diffs (136 lines):

diff -r 52d53653ac52 -r 26e0ebd97454 njs/njs_array.c
--- a/njs/njs_array.c   Tue Apr 04 06:10:10 2017 +0300
+++ b/njs/njs_array.c   Tue Apr 04 06:16:49 2017 +0300
@@ -100,6 +100,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_find_continuation(njs_vm_t *vm,
 njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
+static njs_ret_t njs_array_prototype_find_index_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 nxt_noinline uint32_t njs_array_prototype_map_index(njs_array_t *array,
@@ -1531,6 +1533,54 @@ njs_array_prototype_find_continuation(nj
 }
 
 
+static njs_ret_t
+njs_array_prototype_find_index(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_vm_continuation(vm);
+iter->u.cont.function = njs_array_prototype_find_index_continuation;
+iter->retval.data.truth = 0;
+
+return njs_array_prototype_find_index_continuation(vm, args, nargs, 
unused);
+}
+
+
+static njs_ret_t
+njs_array_prototype_find_index_continuation(njs_vm_t *vm, njs_value_t *args,
+nxt_uint_t nargs, njs_index_t unused)
+{
+double index;
+njs_array_iter_t   *iter;
+
+iter = njs_vm_continuation(vm);
+index = iter->index;
+
+if (!njs_is_true(>retval)) {
+iter->index++;
+
+if (iter->index < iter->length
+&& iter->index < args[0].data.u.array->length)
+{
+return njs_array_prototype_find_apply(vm, iter, args, nargs);
+}
+
+index = -1;
+}
+
+njs_number_set(>retval, index);
+
+return NXT_OK;
+}
+
+
 static nxt_noinline njs_ret_t
 njs_array_prototype_find_apply(njs_vm_t *vm, njs_array_iter_t *iter,
 njs_value_t *args, nxt_uint_t nargs)
@@ -2147,6 +2197,14 @@ static const njs_object_prop_t  njs_arra
  njs_continuation_size(njs_array_find_t), 0),
 },
 
+/* ES6. */
+{
+.type = NJS_METHOD,
+.name = njs_string("findIndex"),
+.value = njs_native_function(njs_array_prototype_find_index,
+ njs_continuation_size(njs_array_iter_t), 0),
+},
+
 {
 .type = NJS_METHOD,
 .name = njs_string("map"),
diff -r 52d53653ac52 -r 26e0ebd97454 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Tue Apr 04 06:10:10 2017 +0300
+++ b/njs/test/njs_unit_test.c  Tue Apr 04 06:16:49 2017 +0300
@@ -2927,6 +2927,50 @@ static njs_unit_test_t  njs_test[] =
   nxt_string("undefined") },
 
 { nxt_string("var a = [];"
+ "a.findIndex(function(v, i, a) { return v > 1 })"),
+  nxt_string("-1") },
+
+{ nxt_string("var a = [,NaN,0,-1];"
+ "a.findIndex(function(v, i, a) { return v > 1 })"),
+  nxt_string("-1") },
+
+{ nxt_string("var a = [,NaN,0,-1,2];"
+ "a.findIndex(function(v, i, a) { return v > 1 })"),
+ nxt_string("4") },
+
+{ nxt_string("var a = [1,2,3,-1,5];"
+ "a.findIndex(function(v, i, a) { return v > 1 })"),
+  nxt_string("1") },
+
+{ nxt_string("var a = [,1,,-1,5];"
+ "a.findIndex(function(v, i, a) { return v > 1 })"),
+  nxt_string("4") },
+
+{ nxt_string("var a = [,1,,-1,5,6];"
+ "a.findIndex(function(v, i, a) { return v > 1 })"),
+  nxt_string("4") },
+
+{ nxt_string("[].findIndex(function(v) { return (v === undefined) })"),
+  nxt_string("-1") },
+
+{ nxt_string("[,].findIndex(function(v) { return (v === undefined) })"),
+  nxt_string("0") },
+
+{ nxt_string("[1,2,,3].findIndex(function(el){return el === undefined})"),
+  nxt_string("2") },
+
+{ nxt_string("[,2,,3].findIndex(function(el){return el === undefined})"),
+  nxt_string("0") },
+
+{ nxt_string("var a = [1,2,3,4,5,6];"
+ "a.findIndex(function(v, i, a) { a.shift(); return v == 3 
})"),
+  nxt_string("1") },
+
+{ nxt_string("var a = [1,2,3,4,5,6];"
+ "a.findIndex(function(v, i, a) { a.shift(); return v == 4 
})"),
+  nxt_string("-1") },
+
+{ nxt_string("var a = [];"
  "a.map(function(v, 

[njs] Moving common code to njs_array_iterator_args().

2017-04-04 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/a4e6f27ce598
branches:  
changeset: 335:a4e6f27ce598
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Apr 04 10:56:33 2017 +0300
description:
Moving common code to njs_array_iterator_args().

diffstat:

 njs/njs_array.c |  5 +
 1 files changed, 1 insertions(+), 4 deletions(-)

diffs (43 lines):

diff -r 9d211a93c491 -r a4e6f27ce598 njs/njs_array.c
--- a/njs/njs_array.c   Tue Apr 04 10:52:24 2017 +0300
+++ b/njs/njs_array.c   Tue Apr 04 10:56:33 2017 +0300
@@ -1266,7 +1266,6 @@ njs_array_prototype_some(njs_vm_t *vm, n
 
 iter = njs_vm_continuation(vm);
 iter->u.cont.function = njs_array_prototype_some_continuation;
-iter->retval.data.truth = 0;
 
 return njs_array_prototype_some_continuation(vm, args, nargs, unused);
 }
@@ -1429,7 +1428,6 @@ njs_array_prototype_filter(njs_vm_t *vm,
 
 filter = njs_vm_continuation(vm);
 filter->iter.u.cont.function = njs_array_prototype_filter_continuation;
-filter->iter.retval.data.truth = 0;
 
 filter->array = njs_array_alloc(vm, 0, NJS_ARRAY_SPARE);
 if (nxt_slow_path(filter->array == NULL)) {
@@ -1490,7 +1488,6 @@ njs_array_prototype_find(njs_vm_t *vm, n
 
 find = njs_vm_continuation(vm);
 find->iter.u.cont.function = njs_array_prototype_find_continuation;
-find->iter.retval.data.truth = 0;
 
 return njs_array_prototype_find_continuation(vm, args, nargs, unused);
 }
@@ -1547,7 +1544,6 @@ njs_array_prototype_find_index(njs_vm_t 
 
 iter = njs_vm_continuation(vm);
 iter->u.cont.function = njs_array_prototype_find_index_continuation;
-iter->retval.data.truth = 0;
 
 return njs_array_prototype_find_index_continuation(vm, args, nargs, 
unused);
 }
@@ -1770,6 +1766,7 @@ njs_array_iterator_args(njs_vm_t *vm, nj
 
 iter = njs_vm_continuation(vm);
 iter->length = args[0].data.u.array->length;
+iter->retval.data.truth = 0;
 iter->index = NJS_ARRAY_INVALID_INDEX;
 
 return NXT_OK;
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Global variables may be accessed incorrectly by nested functions.

2017-04-04 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/251aa4b128ea
branches:  
changeset: 333:251aa4b128ea
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Apr 04 10:47:02 2017 +0300
description:
Global variables may be accessed incorrectly by nested functions.

diffstat:

 njs/njs_variable.c   |  6 +-
 njs/test/njs_unit_test.c |  4 
 2 files changed, 9 insertions(+), 1 deletions(-)

diffs (30 lines):

diff -r ada17c8bdd5a -r 251aa4b128ea njs/njs_variable.c
--- a/njs/njs_variable.cTue Apr 04 10:47:12 2017 +0300
+++ b/njs/njs_variable.cTue Apr 04 10:47:02 2017 +0300
@@ -322,7 +322,11 @@ njs_variable_get(njs_vm_t *vm, njs_parse
 goto not_found;
 }
 
-n = (node->scope->nesting != vs.scope->nesting);
+n = 0;
+
+if (vs.scope->type > NJS_SCOPE_GLOBAL) {
+n = (node->scope->nesting != vs.scope->nesting);
+}
 
 var = vs.variable;
 index = var->index;
diff -r ada17c8bdd5a -r 251aa4b128ea njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Tue Apr 04 10:47:12 2017 +0300
+++ b/njs/test/njs_unit_test.c  Tue Apr 04 10:47:02 2017 +0300
@@ -4319,6 +4319,10 @@ static njs_unit_test_t  njs_test[] =
  "var y = f(); y()"),
   nxt_string("6") },
 
+{ nxt_string("var x; var y = 4;"
+ "function f() { function h() { x = 3; return y; } }"),
+  nxt_string("undefined") },
+
 /* Recursive fibonacci. */
 
 { nxt_string("function fibo(n) {"
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Array.prototype.find() method.

2017-04-04 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/52d53653ac52
branches:  
changeset: 330:52d53653ac52
user:  Andrey Zelenkov 
date:  Tue Apr 04 06:10:10 2017 +0300
description:
Array.prototype.find() method.

Also introduced njs_array_iterator_sparse_apply() function.

diffstat:

 njs/njs_array.c  |  106 +++
 njs/test/njs_unit_test.c |   43 +++
 2 files changed, 149 insertions(+), 0 deletions(-)

diffs (197 lines):

diff -r c46da90ca064 -r 52d53653ac52 njs/njs_array.c
--- a/njs/njs_array.c   Sun Apr 02 12:36:05 2017 +0300
+++ b/njs/njs_array.c   Tue Apr 04 06:10:10 2017 +0300
@@ -58,6 +58,12 @@ typedef struct {
 
 typedef struct {
 njs_array_iter_titer;
+njs_value_t value;
+} njs_array_find_t;
+
+
+typedef struct {
+njs_array_iter_titer;
 njs_array_t *array;
 } njs_array_map_t;
 
@@ -92,6 +98,8 @@ static njs_ret_t njs_array_prototype_eve
 njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
 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_find_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 nxt_noinline uint32_t njs_array_prototype_map_index(njs_array_t *array,
@@ -102,6 +110,8 @@ static nxt_noinline uint32_t njs_array_i
 njs_array_iter_t *iter);
 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 nxt_noinline njs_ret_t njs_array_prototype_find_apply(njs_vm_t *vm,
+njs_array_iter_t *iter, njs_value_t *args, nxt_uint_t nargs);
 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,
@@ -1465,6 +1475,94 @@ njs_array_prototype_filter_continuation(
 
 
 static njs_ret_t
+njs_array_prototype_find(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+njs_index_t unused)
+{
+nxt_int_t ret;
+njs_array_find_t  *find;
+
+ret = njs_array_iterator_args(vm, args, nargs);
+if (nxt_slow_path(ret != NXT_OK)) {
+return ret;
+}
+
+find = njs_vm_continuation(vm);
+find->iter.u.cont.function = njs_array_prototype_find_continuation;
+find->iter.retval.data.truth = 0;
+
+return njs_array_prototype_find_continuation(vm, args, nargs, unused);
+}
+
+
+static njs_ret_t
+njs_array_prototype_find_continuation(njs_vm_t *vm, njs_value_t *args,
+nxt_uint_t nargs, njs_index_t unused)
+{
+njs_array_t*array;
+njs_array_iter_t   *iter;
+njs_array_find_t   *find;
+const njs_value_t  *retval;
+
+retval = _value_void;
+
+find = njs_vm_continuation(vm);
+iter = >iter;
+
+if (!njs_is_true(>retval)) {
+array = args[0].data.u.array;
+iter->index++;
+
+if (iter->index < iter->length && iter->index < array->length) {
+/* GC: find->value */
+find->value = array->start[iter->index];
+
+return njs_array_prototype_find_apply(vm, iter, args, nargs);
+}
+
+} else {
+if (njs_is_valid(>value)) {
+retval = >value;
+}
+}
+
+vm->retval = *retval;
+
+return NXT_OK;
+}
+
+
+static nxt_noinline njs_ret_t
+njs_array_prototype_find_apply(njs_vm_t *vm, njs_array_iter_t *iter,
+njs_value_t *args, nxt_uint_t nargs)
+{
+uint32_t   n;
+const njs_value_t  *value;
+njs_value_targuments[4];
+
+/* GC: array elt, array */
+
+value = (nargs > 2) ? [2] : _value_void;
+arguments[0] = *value;
+
+n = iter->index;
+value = [0].data.u.array->start[n];
+
+if (!njs_is_valid(value)) {
+value = _value_void;
+}
+
+arguments[1] = *value;
+
+njs_number_set([2], n);
+
+arguments[3] = args[0];
+
+return njs_function_apply(vm, args[1].data.u.function, arguments, 4,
+  (njs_index_t) >retval);
+}
+
+
+static njs_ret_t
 njs_array_prototype_map(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 njs_index_t unused)
 {
@@ -2041,6 +2139,14 @@ static const njs_object_prop_t  njs_arra
  njs_continuation_size(njs_array_filter_t), 0),
 },
 
+/* ES6. */
+{
+.type = NJS_METHOD,
+.name = njs_string("find"),
+.value = njs_native_function(njs_array_prototype_find,
+ njs_continuation_size(njs_array_find_t), 0),
+},
+
 {
 .type = NJS_METHOD,
 .name = njs_string("map"),
diff -r c46da90ca064 -r 52d53653ac52 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Sun Apr 02 12:36:05 2017 

[njs] Function declaration should return "undefined".

2017-04-04 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/ada17c8bdd5a
branches:  
changeset: 332:ada17c8bdd5a
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Apr 04 10:47:12 2017 +0300
description:
Function declaration should return "undefined".

diffstat:

 njs/njs_generator.c  |  7 ---
 njs/test/njs_unit_test.c |  6 ++
 2 files changed, 10 insertions(+), 3 deletions(-)

diffs (33 lines):

diff -r 26e0ebd97454 -r ada17c8bdd5a njs/njs_generator.c
--- a/njs/njs_generator.c   Tue Apr 04 06:16:49 2017 +0300
+++ b/njs/njs_generator.c   Tue Apr 04 10:47:12 2017 +0300
@@ -1261,9 +1261,10 @@ njs_generate_stop_statement(njs_vm_t *vm
 stop->code.retval = NJS_VMCODE_NO_RETVAL;
 
 index = NJS_INDEX_NONE;
-
-if (node->right != NULL) {
-index = node->right->index;
+node = node->right;
+
+if (node != NULL && node->token != NJS_TOKEN_FUNCTION) {
+index = node->index;
 }
 
 if (index == NJS_INDEX_NONE) {
diff -r 26e0ebd97454 -r ada17c8bdd5a njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Tue Apr 04 06:16:49 2017 +0300
+++ b/njs/test/njs_unit_test.c  Tue Apr 04 10:47:12 2017 +0300
@@ -4199,6 +4199,12 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("function () { } f()"),
   nxt_string("SyntaxError: Unexpected token \"(\" in 1") },
 
+{ nxt_string("function f() { }"),
+  nxt_string("undefined") },
+
+{ nxt_string("var x; function f() { }"),
+  nxt_string("undefined") },
+
 { nxt_string("function f() { } f()"),
   nxt_string("undefined") },
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Variables may be accessed incorrectly by nested functions.

2017-04-03 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/c46da90ca064
branches:  
changeset: 329:c46da90ca064
user:  Igor Sysoev <i...@sysoev.ru>
date:  Sun Apr 02 12:36:05 2017 +0300
description:
Variables may be accessed incorrectly by nested functions.

diffstat:

 njs/njs_parser.c |  5 +
 njs/test/njs_unit_test.c |  5 +
 2 files changed, 10 insertions(+), 0 deletions(-)

diffs (30 lines):

diff -r cee288760080 -r c46da90ca064 njs/njs_parser.c
--- a/njs/njs_parser.c  Sun Apr 02 12:35:11 2017 +0300
+++ b/njs/njs_parser.c  Sun Apr 02 12:36:05 2017 +0300
@@ -215,6 +215,11 @@ njs_parser_scope_begin(njs_vm_t *vm, njs
 
 if (parent != NULL) {
 nxt_queue_insert_tail(>nested, >link);
+
+if (nesting == 0) {
+/* Inherit function nesting in blocks. */
+scope->nesting = parent->nesting;
+}
 }
 
 return NXT_OK;
diff -r cee288760080 -r c46da90ca064 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Sun Apr 02 12:35:11 2017 +0300
+++ b/njs/test/njs_unit_test.c  Sun Apr 02 12:36:05 2017 +0300
@@ -4221,6 +4221,11 @@ static njs_unit_test_t  njs_test[] =
  "var y = f(); y()"),
   nxt_string("4") },
 
+{ nxt_string("function f() { var x = 4;"
+ "function g() { if (1) { return 2 + x; } }; return g }"
+ "var y = f(); y()"),
+  nxt_string("6") },
+
 /* Recursive fibonacci. */
 
 { nxt_string("function fibo(n) {"
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Large indexes processing has been fixed in

2017-04-03 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/8f59eeb8ee2d
branches:  
changeset: 327:8f59eeb8ee2d
user:  Igor Sysoev <i...@sysoev.ru>
date:  Sat Apr 01 15:32:04 2017 +0300
description:
Large indexes processing has been fixed in
Array.prototype.reduceRight().

diffstat:

 njs/njs_array.c |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r dc8af19bf47d -r 8f59eeb8ee2d njs/njs_array.c
--- a/njs/njs_array.c   Fri Mar 31 14:05:44 2017 +0300
+++ b/njs/njs_array.c   Sat Apr 01 15:32:04 2017 +0300
@@ -1716,7 +1716,7 @@ njs_array_prototype_reduce_right_continu
 
 iter = njs_vm_continuation(vm);
 
-if ((int32_t) iter->next_index < 0) {
+if (iter->next_index == NJS_ARRAY_INVALID_INDEX) {
 vm->retval = iter->retval;
 return NXT_OK;
 }
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Array iterators optimizations.

2017-04-03 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/cee288760080
branches:  
changeset: 328:cee288760080
user:  Igor Sysoev <i...@sysoev.ru>
date:  Sun Apr 02 12:35:11 2017 +0300
description:
Array iterators optimizations.

diffstat:

 njs/njs_array.c  |  221 +-
 njs/test/njs_unit_test.c |4 +
 2 files changed, 122 insertions(+), 103 deletions(-)

diffs (498 lines):

diff -r 8f59eeb8ee2d -r cee288760080 njs/njs_array.c
--- a/njs/njs_array.c   Sat Apr 01 15:32:04 2017 +0300
+++ b/njs/njs_array.c   Sun Apr 02 12:35:11 2017 +0300
@@ -44,7 +44,7 @@ typedef struct {
  */
 njs_value_t retval;
 
-uint32_tnext_index;
+uint32_tindex;
 uint32_tlength;
 } njs_array_iter_t;
 
@@ -59,7 +59,6 @@ typedef struct {
 typedef struct {
 njs_array_iter_titer;
 njs_array_t *array;
-uint32_tindex;
 } njs_array_map_t;
 
 
@@ -95,17 +94,20 @@ 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_continuation(njs_vm_t *vm,
 njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
+static nxt_noinline uint32_t njs_array_prototype_map_index(njs_array_t *array,
+njs_array_map_t *map);
+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_index(njs_array_t *array,
+njs_array_iter_t *iter);
+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 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);
-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, uint32_t n);
+static uint32_t njs_array_reduce_right_index(njs_array_t *array,
+njs_array_iter_t *iter);
 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);
 
@@ -1222,11 +1224,14 @@ 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)
 {
+uint32_t  index;
 njs_array_iter_t  *iter;
 
 iter = njs_vm_continuation(vm);
 
-if (iter->next_index >= args[0].data.u.array->length) {
+index = njs_array_iterator_index(args[0].data.u.array, iter);
+
+if (index == NJS_ARRAY_INVALID_INDEX) {
 vm->retval = njs_value_void;
 return NXT_OK;
 }
@@ -1259,6 +1264,7 @@ 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)
 {
+uint32_t   index;
 njs_array_iter_t   *iter;
 const njs_value_t  *retval;
 
@@ -1267,11 +1273,15 @@ njs_array_prototype_some_continuation(nj
 if (njs_is_true(>retval)) {
 retval = _value_true;
 
-} else if (iter->next_index >= args[0].data.u.array->length) {
-retval = _value_false;
-
 } else {
-return njs_array_iterator_apply(vm, iter, args, nargs);
+index = njs_array_iterator_index(args[0].data.u.array, iter);
+
+if (index == NJS_ARRAY_INVALID_INDEX) {
+retval = _value_false;
+
+} else {
+return njs_array_iterator_apply(vm, iter, args, nargs);
+}
 }
 
 vm->retval = *retval;
@@ -1304,6 +1314,7 @@ 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)
 {
+uint32_t   index;
 njs_array_iter_t   *iter;
 const njs_value_t  *retval;
 
@@ -1312,11 +1323,15 @@ njs_array_prototype_every_continuation(n
 if (!njs_is_true(>retval)) {
 retval = _value_false;
 
-} else if (iter->next_index >= args[0].data.u.array->length) {
-retval = _value_true;
-
 } else {
-return njs_array_iterator_apply(vm, iter, args, nargs);
+index = njs_array_iterator_index(args[0].data.u.array, iter);
+
+if (index == NJS_ARRAY_INVALID_INDEX) {
+retval = _value_true;
+
+} else {
+return njs_array_iterator_apply(vm, iter, args, nargs);
+}
 }
 
 vm->retval = *retval;
@@ -1417,6 +1432,7 @@ static njs_ret_t
 njs_array_prototype_fil

[njs] Style fixes.

2017-03-31 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/dc8af19bf47d
branches:  
changeset: 326:dc8af19bf47d
user:  Andrey Zelenkov 
date:  Fri Mar 31 14:05:44 2017 +0300
description:
Style fixes.

diffstat:

 njs/njs_regexp.c |  2 +-
 njs/njs_string.c |  2 +-
 njs/njs_vm.c |  6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)

diffs (54 lines):

diff -r 8e20f235b71e -r dc8af19bf47d njs/njs_regexp.c
--- a/njs/njs_regexp.c  Fri Mar 31 14:02:38 2017 +0300
+++ b/njs/njs_regexp.c  Fri Mar 31 14:05:44 2017 +0300
@@ -565,7 +565,7 @@ njs_regexp_prototype_to_string(njs_vm_t 
 
 value = [0];
 
-if (value->type == NJS_REGEXP) {
+if (njs_is_regexp(value)) {
 pattern = value->data.u.regexp->pattern;
 source = pattern->source;
 
diff -r 8e20f235b71e -r dc8af19bf47d njs/njs_string.c
--- a/njs/njs_string.c  Fri Mar 31 14:02:38 2017 +0300
+++ b/njs/njs_string.c  Fri Mar 31 14:05:44 2017 +0300
@@ -3573,7 +3573,7 @@ njs_values_hash_test(nxt_lvlhsh_query_t 
 return NXT_OK;
 }
 
-if (value->type == NJS_STRING
+if (njs_is_string(value)
 && value->data.string_size == lhq->key.length
 && memcmp(value->data.u.string->start, lhq->key.start, lhq->key.length)
== 0)
diff -r 8e20f235b71e -r dc8af19bf47d njs/njs_vm.c
--- a/njs/njs_vm.c  Fri Mar 31 14:02:38 2017 +0300
+++ b/njs/njs_vm.c  Fri Mar 31 14:05:44 2017 +0300
@@ -292,7 +292,7 @@ njs_value_retain(njs_value_t *value)
 {
 njs_string_t  *string;
 
-if (value->type == NJS_STRING) {
+if (njs_is_string(value)) {
 
 if (value->data.external0 != 0xff) {
 string = value->data.u.string;
@@ -313,7 +313,7 @@ njs_value_release(njs_vm_t *vm, njs_valu
 {
 njs_string_t  *string;
 
-if (value->type == NJS_STRING) {
+if (njs_is_string(value)) {
 
 if (value->data.external0 != 0xff) {
 string = value->data.u.string;
@@ -2071,7 +2071,7 @@ njs_values_strict_equal(const njs_value_
 
 if (njs_is_numeric(val1)) {
 
-if (val1->type == NJS_VOID) {
+if (njs_is_void(val1)) {
 return 1;
 }
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed Number.prototype.toString() method.

2017-03-31 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/8e20f235b71e
branches:  
changeset: 325:8e20f235b71e
user:  Andrey Zelenkov 
date:  Fri Mar 31 14:02:38 2017 +0300
description:
Fixed Number.prototype.toString() method.

Found with afl-fuzz.

diffstat:

 njs/njs_number.c |  34 +++---
 njs/test/njs_unit_test.c |  36 
 2 files changed, 55 insertions(+), 15 deletions(-)

diffs (127 lines):

diff -r b7d65eb7d6fa -r 8e20f235b71e njs/njs_number.c
--- a/njs/njs_number.c  Thu Mar 30 22:01:17 2017 +0300
+++ b/njs/njs_number.c  Fri Mar 31 14:02:38 2017 +0300
@@ -34,7 +34,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);
+double number, uint32_t radix);
 
 
 double
@@ -483,7 +483,7 @@ static njs_ret_t
 njs_number_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
 nxt_uint_t nargs, njs_index_t unused)
 {
-double   radix;
+double   number, radix;
 njs_value_t  *value;
 
 value = [0];
@@ -499,18 +499,22 @@ njs_number_prototype_to_string(njs_vm_t 
 }
 }
 
-if (nargs == 1 || args[1].data.u.number == 10) {
-return njs_number_to_string(vm, >retval, value);
+if (nargs > 1) {
+radix = args[1].data.u.number;
+
+if (radix < 2 || radix > 36 || radix != (int) radix) {
+vm->exception = _exception_range_error;
+return NXT_ERROR;
+}
+
+number = value->data.u.number;
+
+if (radix != 10 && !isnan(number) && !isinf(number)) {
+return njs_number_to_string_radix(vm, >retval, number, radix);
+}
 }
 
-radix = args[1].data.u.number;
-
-if (radix < 2 || radix > 36 || radix != (int) radix) {
-vm->exception = _exception_range_error;
-return NXT_ERROR;
-}
-
-return njs_number_to_string_radix(vm, >retval, value, radix);
+return njs_number_to_string(vm, >retval, value);
 }
 
 
@@ -527,7 +531,7 @@ njs_number_prototype_to_string(njs_vm_t 
 
 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)
+double number, uint32_t radix)
 {
 u_char   *p, *f, *end;
 double   n, next;
@@ -540,7 +544,7 @@ njs_number_to_string_radix(njs_vm_t *vm,
 end = buf + NJS_STRING_RADIX_LEN;
 p = buf + NJS_STRING_RADIX_INTERGRAL_LEN;
 
-n = number->data.u.number;
+n = number;
 
 if (n < 0) {
 n = -n;
@@ -553,7 +557,7 @@ njs_number_to_string_radix(njs_vm_t *vm,
 n = next;
 } while (n != 0);
 
-n = number->data.u.number;
+n = number;
 
 if (n < 0) {
 *(--p) = '-';
diff -r b7d65eb7d6fa -r 8e20f235b71e njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Thu Mar 30 22:01:17 2017 +0300
+++ b/njs/test/njs_unit_test.c  Fri Mar 31 14:02:38 2017 +0300
@@ -156,6 +156,42 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("1845449130881..toString(36)"),
   nxt_string("njscript") },
 
+{ nxt_string("Infinity.toString()"),
+  nxt_string("Infinity") },
+
+{ nxt_string("Infinity.toString(2)"),
+  nxt_string("Infinity") },
+
+{ nxt_string("Infinity.toString(10)"),
+  nxt_string("Infinity") },
+
+{ nxt_string("Infinity.toString(NaN)"),
+  nxt_string("RangeError") },
+
+{ nxt_string("Infinity.toString({})"),
+  nxt_string("RangeError") },
+
+{ nxt_string("Infinity.toString(Infinity)"),
+  nxt_string("RangeError") },
+
+{ nxt_string("NaN.toString()"),
+  nxt_string("NaN") },
+
+{ nxt_string("NaN.toString(2)"),
+  nxt_string("NaN") },
+
+{ nxt_string("NaN.toString(10)"),
+  nxt_string("NaN") },
+
+{ nxt_string("NaN.toString(Infinity)"),
+  nxt_string("RangeError") },
+
+{ nxt_string("NaN.toString({})"),
+  nxt_string("RangeError") },
+
+{ nxt_string("NaN.toString(NaN)"),
+  nxt_string("RangeError") },
+
 /* An object "valueOf/toString" methods. */
 
 { nxt_string("var a = { valueOf: function() { return 1 } };+a"),
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Large indexes processing has been fixed in array iterator

2017-03-29 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/8cdbd57379e8
branches:  
changeset: 322:8cdbd57379e8
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Mar 29 15:54:33 2017 +0300
description:
Large indexes processing has been fixed in array iterator
functions.

diffstat:

 njs/njs_array.c  |  26 +-
 njs/njs_array.h  |   4 
 njs/njs_vm.c |  16 +++-
 njs/test/njs_unit_test.c |   9 +
 4 files changed, 37 insertions(+), 18 deletions(-)

diffs (168 lines):

diff -r a095dc0cd361 -r 8cdbd57379e8 njs/njs_array.c
--- a/njs/njs_array.c   Tue Mar 28 07:50:05 2017 +0300
+++ b/njs/njs_array.c   Wed Mar 29 15:54:33 2017 +0300
@@ -75,7 +75,7 @@ typedef struct {
 njs_value_t retval;
 
 njs_function_t  *function;
-int32_t index;
+uint32_tindex;
 uint32_tcurrent;
 } njs_array_sort_t;
 
@@ -105,7 +105,7 @@ static nxt_noinline uint32_t njs_array_i
 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);
+static uint32_t njs_array_reduce_right_next(njs_array_t *array, uint32_t n);
 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);
 
@@ -1520,7 +1520,7 @@ 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)
 {
-nxt_int_t n;
+uint32_t  n;
 njs_array_t   *array;
 njs_value_t   arguments[5];
 njs_array_iter_t  *iter;
@@ -1588,7 +1588,7 @@ njs_array_iterator_next(njs_array_t *arr
 n++;
 }
 
-return -1;
+return NJS_ARRAY_INVALID_INDEX;
 }
 
 
@@ -1596,7 +1596,7 @@ 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)
 {
-nxt_int_tn;
+uint32_t n;
 njs_array_t  *array;
 njs_value_t  arguments[4];
 
@@ -1632,7 +1632,7 @@ 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;
+uint32_t  n;
 njs_array_t   *array;
 njs_array_iter_t  *iter;
 
@@ -1652,7 +1652,7 @@ njs_array_prototype_reduce_right(njs_vm_
 } else {
 n = iter->next_index;
 
-if (n < 0) {
+if (n == NJS_ARRAY_INVALID_INDEX) {
 goto type_error;
 }
 
@@ -1675,7 +1675,7 @@ 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)
 {
-nxt_int_t n;
+uint32_t  n;
 njs_array_t   *array;
 njs_value_t   arguments[5];
 njs_array_iter_t  *iter;
@@ -1708,11 +1708,11 @@ njs_array_prototype_reduce_right_continu
 
 
 static nxt_noinline uint32_t
-njs_array_reduce_right_next(njs_array_t *array, int32_t n)
+njs_array_reduce_right_next(njs_array_t *array, uint32_t n)
 {
-n = nxt_min(n, (int32_t) array->length) - 1;
-
-while (n >= 0) {
+n = nxt_min(n, array->length) - 1;
+
+while (n != NJS_ARRAY_INVALID_INDEX) {
 if (njs_is_valid(>start[n])) {
 return n;
 }
@@ -1789,7 +1789,7 @@ 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_int_t n;
+uint32_t  n;
 njs_array_t   *array;
 njs_value_t   value, *start, arguments[3];
 njs_array_sort_t  *sort;
diff -r a095dc0cd361 -r 8cdbd57379e8 njs/njs_array.h
--- a/njs/njs_array.h   Tue Mar 28 07:50:05 2017 +0300
+++ b/njs/njs_array.h   Wed Mar 29 15:54:33 2017 +0300
@@ -8,6 +8,10 @@
 #define _NJS_ARRAY_H_INCLUDED_
 
 
+#define NJS_ARRAY_MAX_LENGTH 0x
+/* The maximum valid array index is the maximum array length minus 1. */
+#define NJS_ARRAY_INVALID_INDEX  NJS_ARRAY_MAX_LENGTH
+
 #define NJS_ARRAY_SPARE  8
 
 
diff -r a095dc0cd361 -r 8cdbd57379e8 njs/njs_vm.c
--- a/njs/njs_vm.c  Tue Mar 28 07:50:05 2017 +0300
+++ b/njs/njs_vm.c  Wed Mar 29 15:54:33 2017 +0300
@@ -944,9 +944,10 @@ njs_property_query(njs_vm_t *vm, njs_pro
 njs_value_t *property)
 {
 double  num;
-int32_t index;
+uint32_tindex;
 uint32_t(*hash)(const void *, size_t);
 njs_ret_t   ret;
+nxt_bool_t  valid;
 njs_extern_t*ext;
 njs_object_t*obj;
 njs_function_t  *function;
@@ -983,10 +984,15 @@ njs_property_query(njs_vm_t *vm, njs_pro
 return NJS_TRAP_PROPERTY;
 }
 
-index = (int) num;
-
-if (nxt_fast_path(index >= 0 && (double) index == num)) {
-ret

[njs] A small Array.prototype.sort() optimization.

2017-03-29 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/90743d1bb614
branches:  
changeset: 323:90743d1bb614
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Mar 29 15:54:37 2017 +0300
description:
A small Array.prototype.sort() optimization.

diffstat:

 njs/njs_array.c |  34 ++
 1 files changed, 18 insertions(+), 16 deletions(-)

diffs (52 lines):

diff -r 8cdbd57379e8 -r 90743d1bb614 njs/njs_array.c
--- a/njs/njs_array.c   Wed Mar 29 15:54:33 2017 +0300
+++ b/njs/njs_array.c   Wed Mar 29 15:54:37 2017 +0300
@@ -1802,9 +1802,9 @@ njs_array_prototype_sort_continuation(nj
 if (njs_is_number(>retval)) {
 
 /*
- * The sort function is impelemented with the insertion sort algorithm.
+ * The sort function is implemented with the insertion sort algorithm.
  * Its worst and average computational complexity is O^2.  This point
- * should be considired as return point from comparison function so
+ * should be considered as return point from comparison function so
  * "goto next" moves control to the appropriate step of the algorithm.
  * The first iteration also goes there because sort->retval is zero.
  */
@@ -1824,20 +1824,22 @@ njs_array_prototype_sort_continuation(nj
 do {
 if (n > 0) {
 
-if (njs_is_valid([n]) && njs_is_valid([n - 1])) {
-arguments[0] = njs_value_void;
-
-/* GC: array elt, array */
-arguments[1] = start[n - 1];
-arguments[2] = start[n];
-
-sort->index = n;
-
-return njs_function_apply(vm, sort->function, arguments, 3,
-  (njs_index_t) >retval);
-}
-
-if (!njs_is_valid([n - 1]) && njs_is_valid([n])) {
+if (njs_is_valid([n])) {
+
+if (njs_is_valid([n - 1])) {
+arguments[0] = njs_value_void;
+
+/* GC: array elt, array */
+arguments[1] = start[n - 1];
+arguments[2] = start[n];
+
+sort->index = n;
+
+return njs_function_apply(vm, sort->function,
+  arguments, 3,
+  (njs_index_t) >retval);
+}
+
 /* Move invalid values to the end of array. */
 goto swap;
 }
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Closures support.

2017-03-28 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/a095dc0cd361
branches:  
changeset: 321:a095dc0cd361
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Mar 28 07:50:05 2017 +0300
description:
Closures support.

diffstat:

 njs/njs_array.c  |2 +-
 njs/njs_boolean.c|2 +-
 njs/njs_date.c   |4 +-
 njs/njs_function.c   |  159 +++-
 njs/njs_function.h   |   29 +++-
 njs/njs_generator.c  |  109 +---
 njs/njs_number.c |2 +-
 njs/njs_parser.c |   87 -
 njs/njs_parser.h |   26 ++-
 njs/njs_string.c |2 +-
 njs/njs_variable.c   |  291 ++
 njs/njs_variable.h   |   18 +-
 njs/njs_vm.c |  237 -
 njs/njs_vm.h |   68 +++---
 njs/njscript.c   |   14 +-
 njs/test/njs_unit_test.c |   35 +-
 16 files changed, 773 insertions(+), 312 deletions(-)

diffs (truncated from 2072 to 1000 lines):

diff -r 0bde7f156477 -r a095dc0cd361 njs/njs_array.c
--- a/njs/njs_array.c   Sat Mar 25 13:42:40 2017 +0300
+++ b/njs/njs_array.c   Tue Mar 28 07:50:05 2017 +0300
@@ -725,7 +725,7 @@ njs_array_prototype_to_string_continuati
 nxt_uint_t nargs, njs_index_t retval)
 {
 /* Skip retval update. */
-vm->frame->skip = 1;
+vm->top_frame->skip = 1;
 
 return NXT_OK;
 }
diff -r 0bde7f156477 -r a095dc0cd361 njs/njs_boolean.c
--- a/njs/njs_boolean.c Sat Mar 25 13:42:40 2017 +0300
+++ b/njs/njs_boolean.c Tue Mar 28 07:50:05 2017 +0300
@@ -34,7 +34,7 @@ njs_boolean_constructor(njs_vm_t *vm, nj
 value = njs_is_true([1]) ? _value_true : _value_false;
 }
 
-if (vm->frame->ctor) {
+if (vm->top_frame->ctor) {
 object = njs_object_value_alloc(vm, value, value->type);
 if (nxt_slow_path(object == NULL)) {
 return NXT_ERROR;
diff -r 0bde7f156477 -r a095dc0cd361 njs/njs_date.c
--- a/njs/njs_date.cSat Mar 25 13:42:40 2017 +0300
+++ b/njs/njs_date.cTue Mar 28 07:50:05 2017 +0300
@@ -91,7 +91,7 @@ njs_date_constructor(njs_vm_t *vm, njs_v
 njs_date_t  *date;
 struct tm   tm;
 
-if (vm->frame->ctor) {
+if (vm->top_frame->ctor) {
 
 if (nargs == 1) {
 time = njs_gettime();
@@ -1892,7 +1892,7 @@ njs_date_prototype_to_json_continuation(
 nxt_uint_t nargs, njs_index_t retval)
 {
 /* Skip retval update. */
-vm->frame->skip = 1;
+vm->top_frame->skip = 1;
 
 return NXT_OK;
 }
diff -r 0bde7f156477 -r a095dc0cd361 njs/njs_function.c
--- a/njs/njs_function.cSat Mar 25 13:42:40 2017 +0300
+++ b/njs/njs_function.cTue Mar 28 07:50:05 2017 +0300
@@ -60,7 +60,9 @@ njs_function_alloc(njs_vm_t *vm)
 njs_function_t *
 njs_function_value_copy(njs_vm_t *vm, njs_value_t *value)
 {
-njs_function_t  *function;
+size_t  size;
+nxt_uint_t  n, nesting;
+njs_function_t  *function, *copy;
 
 function = value->data.u.function;
 
@@ -68,17 +70,36 @@ njs_function_value_copy(njs_vm_t *vm, nj
 return function;
 }
 
-function = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_function_t));
+nesting = (function->native) ? 0 : function->u.lambda->nesting;
 
-if (nxt_fast_path(function != NULL)) {
-*function = *value->data.u.function;
-function->object.__proto__ =
->prototypes[NJS_PROTOTYPE_FUNCTION].object;
-function->object.shared = 0;
-value->data.u.function = function;
+size = sizeof(njs_function_t) + nesting * sizeof(njs_closure_t *);
+
+copy = nxt_mem_cache_alloc(vm->mem_cache_pool, size);
+if (nxt_slow_path(copy == NULL)) {
+return copy;
 }
 
-return function;
+value->data.u.function = copy;
+
+*copy = *function;
+copy->object.__proto__ = >prototypes[NJS_PROTOTYPE_FUNCTION].object;
+copy->object.shared = 0;
+
+if (nesting == 0) {
+return copy;
+}
+
+copy->closure = 1;
+
+n = 0;
+
+do {
+/* GC: retain closure. */
+copy->closures[n] = vm->active_frame->closures[n];
+n++;
+} while (n < nesting);
+
+return copy;
 }
 
 
@@ -107,6 +128,7 @@ njs_function_native_frame(njs_vm_t *vm, 
 frame->ctor = ctor;
 
 value = (njs_value_t *) (njs_continuation(frame) + reserve);
+frame->arguments = value;
 
 bound = function->bound;
 
@@ -124,7 +146,6 @@ njs_function_native_frame(njs_vm_t *vm, 
 } while (n != 0);
 }
 
-frame->arguments = value;
 vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = value;
 
 if (args != NULL) {
@@ -140,17 +161,23 @@ njs_function_frame(njs_vm_t *vm, njs_fun
 const njs_value_t *this, njs_value_t *args, nxt_uint_t nargs,
 nxt_bool_t ctor)
 {
-size_t  size;
-nxt_uint_t  n, max

[njs] The "typeof" operation changes.

2017-03-28 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/0bde7f156477
branches:  
changeset: 320:0bde7f156477
user:  Igor Sysoev <i...@sysoev.ru>
date:  Sat Mar 25 13:42:40 2017 +0300
description:
The "typeof" operation changes.

diffstat:

 njs/njs_variable.c |  19 +++
 njs/njs_vm.c   |   7 ++-
 2 files changed, 9 insertions(+), 17 deletions(-)

diffs (86 lines):

diff -r 8e1030bce13c -r 0bde7f156477 njs/njs_variable.c
--- a/njs/njs_variable.cTue Mar 21 16:35:36 2017 +0300
+++ b/njs/njs_variable.cSat Mar 25 13:42:40 2017 +0300
@@ -176,14 +176,12 @@ njs_variable_t *
 njs_variable_get(njs_vm_t *vm, njs_parser_node_t *node,
 njs_name_reference_t reference)
 {
-nxt_int_t   ret;
 nxt_array_t *values;
 njs_index_t index;
 njs_value_t *value;
 njs_variable_t  *var;
 njs_parser_scope_t  *scope, *parent, *inclusive;
 nxt_lvlhsh_query_t  lhq;
-const njs_value_t   *initial;
 
 lhq.key_hash = node->variable_name_hash;
 lhq.key = node->u.variable_name;
@@ -209,8 +207,6 @@ njs_variable_get(njs_vm_t *vm, njs_parse
 }
 }
 
-initial = _value_void;
-
 goto found;
 }
 
@@ -229,23 +225,14 @@ njs_variable_get(njs_vm_t *vm, njs_parse
 goto not_found;
 }
 
-/* Add variable referenced by typeof to the global scope. */
-
 var = njs_variable_alloc(vm, , NJS_VARIABLE_TYPEOF);
 if (nxt_slow_path(var == NULL)) {
 return NULL;
 }
 
-lhq.replace = 0;
-lhq.value = var;
-lhq.pool = vm->mem_cache_pool;
+var->index = NJS_INDEX_NONE;
 
-ret = nxt_lvlhsh_insert(>variables, );
-if (nxt_slow_path(ret != NXT_OK)) {
-return NULL;
-}
-
-initial = _value_invalid;
+return var;
 
 found:
 
@@ -285,7 +272,7 @@ found:
 *value = var->value;
 
 } else {
-*value = *initial;
+*value = njs_value_void;
 }
 
 index = scope->next_index;
diff -r 8e1030bce13c -r 0bde7f156477 njs/njs_vm.c
--- a/njs/njs_vm.c  Tue Mar 21 16:35:36 2017 +0300
+++ b/njs/njs_vm.c  Sat Mar 25 13:42:40 2017 +0300
@@ -1444,6 +1444,8 @@ njs_vmcode_post_decrement(njs_vm_t *vm, 
 njs_ret_t
 njs_vmcode_typeof(njs_vm_t *vm, njs_value_t *value, njs_value_t *invld)
 {
+nxt_uint_t  type;
+
 /* ECMAScript 5.1: null, array and regexp are objects. */
 
 static const njs_value_t  *types[] = {
@@ -1466,7 +1468,10 @@ njs_vmcode_typeof(njs_vm_t *vm, njs_valu
 _string_object,
 };
 
-vm->retval = *types[value->type];
+/* A zero index means non-declared variable. */
+type = (value != NULL) ? value->type : NJS_VOID;
+
+vm->retval = *types[type];
 
 return sizeof(njs_vmcode_2addr_t);
 }
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Miscellaneous changes.

2017-03-21 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/6887b2d46f87
branches:  
changeset: 317:6887b2d46f87
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Mar 21 16:14:16 2017 +0300
description:
Miscellaneous changes.

diffstat:

 njs/njs_array.c |  6 +++---
 nxt/test/rbtree_unit_test.c |  2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diffs (35 lines):

diff -r ee391489a56d -r 6887b2d46f87 njs/njs_array.c
--- a/njs/njs_array.c   Tue Mar 21 16:09:09 2017 +0300
+++ b/njs/njs_array.c   Tue Mar 21 16:14:16 2017 +0300
@@ -1295,7 +1295,7 @@ static njs_ret_t
 njs_array_prototype_fill(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 njs_index_t unused)
 {
-nxt_int_tstart, end, length;
+nxt_int_ti, start, end, length;
 njs_array_t  *array;
 
 vm->retval = args[0];
@@ -1346,8 +1346,8 @@ njs_array_prototype_fill(njs_vm_t *vm, n
}
 }
 
-while (start < end) {
-array->start[start++] = args[1];
+for (i = start; i < end; i++) {
+array->start[i] = args[1];
 }
 
 return NXT_OK;
diff -r ee391489a56d -r 6887b2d46f87 nxt/test/rbtree_unit_test.c
--- a/nxt/test/rbtree_unit_test.c   Tue Mar 21 16:09:09 2017 +0300
+++ b/nxt/test/rbtree_unit_test.c   Tue Mar 21 16:14:16 2017 +0300
@@ -51,7 +51,7 @@ rbtree_unit_test(nxt_uint_t n)
 
 keys = malloc(n * sizeof(uint32_t));
 if (keys == NULL) {
-free(keys);
+free(items);
 return NXT_ERROR;
 }
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed building on modern Linux.

2017-03-21 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/9ee2a6eb381c
branches:  
changeset: 315:9ee2a6eb381c
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Mar 21 16:02:03 2017 +0300
description:
Fixed building on modern Linux.

diffstat:

 nxt/nxt_random.c |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r 5c42125bd99c -r 9ee2a6eb381c nxt/nxt_random.c
--- a/nxt/nxt_random.c  Fri Mar 17 18:18:01 2017 +0300
+++ b/nxt/nxt_random.c  Tue Mar 21 16:02:03 2017 +0300
@@ -70,7 +70,7 @@ nxt_random_stir(nxt_random_t *r, nxt_pid
 
 /* Linux 3.17 getrandom(), it is not available in Glibc. */
 
-n = syscall(SYS_getrandom, key, NXT_RANDOM_KEY_SIZE, 0);
+n = syscall(SYS_getrandom, , NXT_RANDOM_KEY_SIZE, 0);
 
 #endif
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Miscellaneous non-functional changes in nxt_mem_cache_pool.

2017-03-13 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/243c9c96511a
branches:  
changeset: 313:243c9c96511a
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon Mar 13 16:32:40 2017 +0300
description:
Miscellaneous non-functional changes in nxt_mem_cache_pool.

diffstat:

 nxt/nxt_mem_cache_pool.c |  125 +++---
 1 files changed, 72 insertions(+), 53 deletions(-)

diffs (238 lines):

diff -r 6bda82d5bd54 -r 243c9c96511a nxt/nxt_mem_cache_pool.c
--- a/nxt/nxt_mem_cache_pool.c  Sun Mar 12 22:40:13 2017 +0300
+++ b/nxt/nxt_mem_cache_pool.c  Mon Mar 13 16:32:40 2017 +0300
@@ -21,21 +21,20 @@
  * size.  Page size must be a power of 2.  A page can be used entirely or
  * can be divided on chunks of equal size.  Chunk size must be a power of 2.
  * A cluster can contains pages with different chunk sizes.  Cluster size
- * must be multiple of page size and may be not a power of 2.  Allocations
+ * must be a multiple of page size and may be not a power of 2.  Allocations
  * greater than page are allocated outside clusters.  Start addresses and
- * sizes of clusters and large allocations are stored in rbtree to find
- * them on free operations.  The rbtree nodes are sorted by start addresses.
+ * sizes of the clusters and large allocations are stored in rbtree blocks
+ * to find them on free operations.  The rbtree nodes are sorted by start
+ * addresses.
  */
 
 
-typedef struct nxt_mem_cache_page_s  nxt_mem_cache_page_t;
-
-struct nxt_mem_cache_page_s {
-/* Chunk bitmap.  There can be no more than 32 chunks in a page. */
-uint8_t map[4];
-
-/* Number of free chunks of a chunked page. */
-uint8_t chunks;
+typedef struct {
+/*
+ * Used to link pages with free chunks in pool chunk slot list
+ * or to link free pages in clusters.
+ */
+nxt_queue_link_tlink;
 
 /*
  * Size of chunks or page shifted by pool->chunk_size_shift.
@@ -45,37 +44,60 @@ struct nxt_mem_cache_page_s {
 
 /*
  * Page number in page cluster.
- * There can be no more than 65536 pages in a cluster.
+ * There can be no more than 256 pages in a cluster.
  */
-uint16_tnumber;
+uint8_t number;
 
+/* Number of free chunks of a chunked page. */
+uint8_t chunks;
+
+uint8_t _unused;
+
+/* Chunk bitmap.  There can be no more than 32 chunks in a page. */
+uint8_t map[4];
+} nxt_mem_cache_page_t;
+
+
+typedef enum {
+/* Block of cluster.  The block is allocated apart of the cluster. */
+NXT_MEM_CACHE_CLUSTER_BLOCK = 0,
 /*
- * Used to link pages with free chunks in pool chunk slot list
- * or to link free pages in clusters.
+ * Block of large allocation.
+ * The block is allocated apart of the allocation.
  */
-nxt_queue_link_tlink;
-};
+NXT_MEM_CACHE_DISCRETE_BLOCK,
+/*
+ * Block of large allocation.
+ * The block is allocated just after of the allocation.
+ */
+NXT_MEM_CACHE_EMBEDDED_BLOCK,
+} nxt_mem_cache_block_type_t;
 
 
 typedef struct {
 NXT_RBTREE_NODE (node);
-uint8_t type;
+nxt_mem_cache_block_type_t  type:8;
+
+/* Block size must be less than 4G. */
 uint32_tsize;
 
 u_char  *start;
-nxt_mem_cache_page_t pages[];
+nxt_mem_cache_page_tpages[];
 } nxt_mem_cache_block_t;
 
 
 typedef struct {
 nxt_queue_t pages;
+
+/* Size of page chunks. */
 #if (NXT_64BIT)
 uint32_tsize;
-uint32_tchunks;
 #else
 uint16_tsize;
-uint16_tchunks;
 #endif
+
+/* Maximum number of free chunks in chunked page. */
+uint8_t chunks;
 } nxt_mem_cache_slot_t;
 
 
@@ -99,18 +121,6 @@ struct nxt_mem_cache_pool_s {
 };
 
 
-/* A cluster cache block. */
-#define NXT_MEM_CACHE_CLUSTER_BLOCK   0
-
-/* A discrete cache block of large allocation. */
-#define NXT_MEM_CACHE_DISCRETE_BLOCK  1
-/*
- * An embedded cache block allocated together with large allocation
- * just after the allocation.
- */
-#define NXT_MEM_CACHE_EMBEDDED_BLOCK  2
-
-
 #define nxt_mem_cache_chunk_is_free(map, chunk)   \
 ((map[chunk / 8] & (0x80 >> (chunk & 7))) == 0)
 
@@ -123,6 +133,10 @@ struct nxt_mem_cache_pool_s {
 memset((p), 0x5A, size)
 
 
+#define nxt_is_power_of_two(value)\
+value) - 1) & (value)) == 0)
+
+
 static nxt_uint_t nxt_mem_cache_shift(nxt_uint_t n);
 #if !(NXT_DEBUG_MEMORY)
 static void *nxt_mem_cache_alloc_small(nxt_mem_cache_pool_t *pool, size_t 
size);
@@ -149,9 +163,9 @@ nxt_mem_cache_pool_create(const nxt_mem_
 {
 /* Alignment and sizes must be a power of 2. 

[njs] Using nxt_rbtree_destroy_next() iterator for nxt_mem_cache_pool

2017-03-13 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/6bda82d5bd54
branches:  
changeset: 312:6bda82d5bd54
user:  Igor Sysoev <i...@sysoev.ru>
date:  Sun Mar 12 22:40:13 2017 +0300
description:
Using nxt_rbtree_destroy_next() iterator for nxt_mem_cache_pool
destruction without rbtree rebalancing.

diffstat:

 nxt/nxt_mem_cache_pool.c |  13 +
 nxt/nxt_rbtree.c |  34 ++
 nxt/nxt_rbtree.h |  11 +++
 3 files changed, 50 insertions(+), 8 deletions(-)

diffs (90 lines):

diff -r 214afa2466a0 -r 6bda82d5bd54 nxt/nxt_mem_cache_pool.c
--- a/nxt/nxt_mem_cache_pool.c  Wed Feb 01 11:33:05 2017 +0300
+++ b/nxt/nxt_mem_cache_pool.c  Sun Mar 12 22:40:13 2017 +0300
@@ -257,20 +257,17 @@ nxt_mem_cache_pool_is_empty(nxt_mem_cach
 void
 nxt_mem_cache_pool_destroy(nxt_mem_cache_pool_t *pool)
 {
-void  *p;
+void   *p;
 nxt_rbtree_node_t  *node, *next;
 nxt_mem_cache_block_t  *block;
 
-for (node = nxt_rbtree_min(>blocks);
- nxt_rbtree_is_there_successor(>blocks, node);
- node = next)
-{
-next = nxt_rbtree_node_successor(>blocks, node);
+next = nxt_rbtree_root(>blocks);
 
+while (next != nxt_rbtree_sentinel(>blocks)) {
+
+node = nxt_rbtree_destroy_next(>blocks, );
 block = (nxt_mem_cache_block_t *) node;
 
-nxt_rbtree_delete(>blocks, >node);
-
 p = block->start;
 
 if (block->type != NXT_MEM_CACHE_EMBEDDED_BLOCK) {
diff -r 214afa2466a0 -r 6bda82d5bd54 nxt/nxt_rbtree.c
--- a/nxt/nxt_rbtree.c  Wed Feb 01 11:33:05 2017 +0300
+++ b/nxt/nxt_rbtree.c  Sun Mar 12 22:40:13 2017 +0300
@@ -495,3 +495,37 @@ nxt_rbtree_parent_relink(nxt_rbtree_node
 link = (node == parent->left) ? >left : >right;
 *link = subst;
 }
+
+
+nxt_rbtree_node_t *
+nxt_rbtree_destroy_next(nxt_rbtree_t *tree, nxt_rbtree_node_t **next)
+{
+nxt_rbtree_node_t  *node, *subst, *parent, *sentinel;
+
+sentinel = nxt_rbtree_sentinel(tree);
+
+/* Find the leftmost node. */
+for (node = *next; node->left != sentinel; node = node->left);
+
+/* Replace the leftmost node with its right child. */
+subst = node->right;
+parent = node->parent;
+
+parent->left = subst;
+subst->parent = parent;
+
+/*
+ * The right child is used as the next start node.  If the right child
+ * is the sentinel then parent of the leftmost node is used as the next
+ * start node.  The parent of the root node is the sentinel so after
+ * the single root node will be replaced with the sentinel, the next
+ * start node will be equal to the sentinel and iteration will stop.
+ */
+if (subst == sentinel) {
+subst = parent;
+}
+
+*next = subst;
+
+return node;
+}
diff -r 214afa2466a0 -r 6bda82d5bd54 nxt/nxt_rbtree.h
--- a/nxt/nxt_rbtree.h  Wed Feb 01 11:33:05 2017 +0300
+++ b/nxt/nxt_rbtree.h  Sun Mar 12 22:40:13 2017 +0300
@@ -111,5 +111,16 @@ NXT_EXPORT nxt_rbtree_node_t
 nxt_rbtree_part_t *node);
 NXT_EXPORT void nxt_rbtree_delete(nxt_rbtree_t *tree, nxt_rbtree_part_t *node);
 
+/*
+ * nxt_rbtree_destroy_next() is iterator to use only while rbtree destruction.
+ * It deletes a node from rbtree and returns the node.  The rbtree is not
+ * rebalanced after deletion.  At the beginning the "next" parameter should
+ * be equal to rbtree root.  The iterator should be called in loop until
+ * the "next" parameter will be equal to the rbtree sentinel.  No other
+ * operations must be performed on the rbtree while destruction.
+ */
+NXT_EXPORT nxt_rbtree_node_t *nxt_rbtree_destroy_next(nxt_rbtree_t *tree,
+nxt_rbtree_node_t **next);
+
 
 #endif /* _NXT_RBTREE_H_INCLUDED_ */
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Version 0.1.9.

2017-02-01 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/5bd283398822
branches:  
changeset: 310:5bd283398822
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Feb 01 11:29:47 2017 +0300
description:
Version 0.1.9.

diffstat:

 CHANGES  |  38 ++
 Makefile |   2 +-
 2 files changed, 39 insertions(+), 1 deletions(-)

diffs (52 lines):

diff -r c9308fed683e -r 5bd283398822 CHANGES
--- /dev/null   Thu Jan 01 00:00:00 1970 +
+++ b/CHANGES   Wed Feb 01 11:29:47 2017 +0300
@@ -0,0 +1,38 @@
+
+Changes with nJScript 0.1.9  01 Feb 2017
+
+*) Bugfix: global variables were not initialized when nJScript was used
+   in nginx.
+
+Changes with nJScript 0.1.8  24 Jan 2017
+
+*) Change: the "strict" mode is enforced, variables must be explicitly
+   declared.
+
+*) Feature: "for" and "for-in" loops support variable declaration.
+
+*) Bugfix: global and function scopes have been fixed.
+
+*) Bugfix: now "for-in" loop does not discard the last value of property
+   variable.
+
+*) Bugfix: miscellaneous bugs and segmentation faults have been fixed.
+
+Changes with nJScript 0.1.7  27 Dec 2016
+
+*) Change: the "js_include" directive has been disabled at server and
+   location levels.
+
+*) Feature: exponentiation operators.
+
+*) Bugfix: miscellaneous bugs and segmentation faults have been fixed.
+
+Changes with nJScript 0.1.6  13 Dec 2016
+
+*) Change: the "js_set" directive has been disabled at server and
+   location levels.
+
+*) Feature: ES6 Math methods.
+
+*) Bugfix: miscellaneous bugs and segmentation faults have been fixed.
+
diff -r c9308fed683e -r 5bd283398822 Makefile
--- a/Makefile  Wed Feb 01 10:06:28 2017 +0300
+++ b/Makefile  Wed Feb 01 11:29:47 2017 +0300
@@ -1,5 +1,5 @@
 
-NJS_VER =  0.1.8
+NJS_VER =  0.1.9
 
 NXT_LIB =  nxt
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] 2017 year.

2017-02-01 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/c9308fed683e
branches:  
changeset: 309:c9308fed683e
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Feb 01 10:06:28 2017 +0300
description:
2017 year.

diffstat:

 LICENSE |  4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diffs (12 lines):

diff -r 67d4bcb5823f -r c9308fed683e LICENSE
--- a/LICENSE   Tue Jan 31 20:22:01 2017 +0300
+++ b/LICENSE   Wed Feb 01 10:06:28 2017 +0300
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2015-2016 Igor Sysoev
- * Copyright (C) 2015-2016 NGINX, Inc.
+ * Copyright (C) 2015-2017 Igor Sysoev
+ * Copyright (C) 2015-2017 NGINX, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Added tag 0.1.9 for changeset 5bd283398822

2017-02-01 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/214afa2466a0
branches:  
changeset: 311:214afa2466a0
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Feb 01 11:33:05 2017 +0300
description:
Added tag 0.1.9 for changeset 5bd283398822

diffstat:

 .hgtags |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (8 lines):

diff -r 5bd283398822 -r 214afa2466a0 .hgtags
--- a/.hgtags   Wed Feb 01 11:29:47 2017 +0300
+++ b/.hgtags   Wed Feb 01 11:33:05 2017 +0300
@@ -7,3 +7,4 @@ 9c813c2bb2acfd5b6e9d1e9b6699af928baea15a
 44b524f7e313369cd062a387511ea6fdc427875f 0.1.6
 15dc54100400f99c3ec044d8fb0175dd3d69adcb 0.1.7
 a29f29d481125db6101ecdc23dc20187c143cdc9 0.1.8
+5bd2833988222900f60ad9b330ebc44df3b30662 0.1.9
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Version 0.1.8.

2017-01-24 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/a29f29d48112
branches:  
changeset: 304:a29f29d48112
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Jan 24 14:38:48 2017 +0300
description:
Version 0.1.8.

diffstat:

 Makefile |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (10 lines):

diff -r 8401ae77cf40 -r a29f29d48112 Makefile
--- a/Makefile  Fri Jan 20 16:10:48 2017 +0300
+++ b/Makefile  Tue Jan 24 14:38:48 2017 +0300
@@ -1,5 +1,5 @@
 
-NJS_VER =  0.1.7
+NJS_VER =  0.1.8
 
 NXT_LIB =  nxt
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Added tag 0.1.8 for changeset a29f29d48112

2017-01-24 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/f136239eebff
branches:  
changeset: 305:f136239eebff
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Jan 24 14:38:59 2017 +0300
description:
Added tag 0.1.8 for changeset a29f29d48112

diffstat:

 .hgtags |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (8 lines):

diff -r a29f29d48112 -r f136239eebff .hgtags
--- a/.hgtags   Tue Jan 24 14:38:48 2017 +0300
+++ b/.hgtags   Tue Jan 24 14:38:59 2017 +0300
@@ -6,3 +6,4 @@ 508689c1fb94c23f6b24be087c1dc63b2f9e6654
 9c813c2bb2acfd5b6e9d1e9b6699af928baea15a 0.1.5
 44b524f7e313369cd062a387511ea6fdc427875f 0.1.6
 15dc54100400f99c3ec044d8fb0175dd3d69adcb 0.1.7
+a29f29d481125db6101ecdc23dc20187c143cdc9 0.1.8
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] A small rbtree insert fixup optimization.

2017-01-20 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/8401ae77cf40
branches:  
changeset: 303:8401ae77cf40
user:  Igor Sysoev <i...@sysoev.ru>
date:  Fri Jan 20 16:10:48 2017 +0300
description:
A small rbtree insert fixup optimization.

Thanks to ??? (Hong Zhi Dao).

diffstat:

 nxt/nxt_rbtree.c |  11 ---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (28 lines):

diff -r 5db6d7af16b4 -r 8401ae77cf40 nxt/nxt_rbtree.c
--- a/nxt/nxt_rbtree.c  Mon Jan 16 18:14:01 2017 +0300
+++ b/nxt/nxt_rbtree.c  Fri Jan 20 16:10:48 2017 +0300
@@ -135,8 +135,12 @@ nxt_rbtree_insert_fixup(nxt_rbtree_node_
 grandparent = parent->parent;
 grandparent->color = NXT_RBTREE_RED;
 nxt_rbtree_right_rotate(grandparent);
-
-continue;
+/*
+ * nxt_rbtree_right_rotate() does not change node->parent
+ * color which is now black, so testing color is not required
+ * to return from function.
+ */
+return;
 }
 
 } else {
@@ -156,7 +160,8 @@ nxt_rbtree_insert_fixup(nxt_rbtree_node_
 grandparent->color = NXT_RBTREE_RED;
 nxt_rbtree_left_rotate(grandparent);
 
-continue;
+/* See the comment in the symmetric branch above. */
+return;
 }
 }
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] A scope has been added to literal nodes.

2017-01-16 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/5db6d7af16b4
branches:  
changeset: 302:5db6d7af16b4
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon Jan 16 18:14:01 2017 +0300
description:
A scope has been added to literal nodes.

Found with afl-fuzz.

diffstat:

 njs/njs_parser.c |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (11 lines):

diff -r 6cc16ad934a4 -r 5db6d7af16b4 njs/njs_parser.c
--- a/njs/njs_parser.c  Mon Jan 16 17:32:10 2017 +0300
+++ b/njs/njs_parser.c  Mon Jan 16 18:14:01 2017 +0300
@@ -1778,6 +1778,7 @@ njs_parser_terminal(njs_vm_t *vm, njs_pa
 }
 
 node->token = token;
+node->scope = parser->scope;
 
 switch (token) {
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Comprehensive test of "return" statement location.

2017-01-16 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/6cc16ad934a4
branches:  
changeset: 301:6cc16ad934a4
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon Jan 16 17:32:10 2017 +0300
description:
Comprehensive test of "return" statement location.

Found with afl-fuzz.

diffstat:

 njs/njs_parser.c |  22 ++
 njs/test/njs_unit_test.c |   3 +++
 2 files changed, 17 insertions(+), 8 deletions(-)

diffs (45 lines):

diff -r 07dc20c1206d -r 6cc16ad934a4 njs/njs_parser.c
--- a/njs/njs_parser.c  Mon Jan 16 14:51:29 2017 +0300
+++ b/njs/njs_parser.c  Mon Jan 16 17:32:10 2017 +0300
@@ -697,14 +697,20 @@ njs_parser_function_lambda(njs_vm_t *vm,
 static njs_token_t
 njs_parser_return_statement(njs_vm_t *vm, njs_parser_t *parser)
 {
-njs_token_ttoken;
-njs_parser_node_t  *node;
-
-if (parser->scope->type == NJS_SCOPE_GLOBAL) {
-nxt_alert(>trace, NXT_LEVEL_ERROR,
-  "SyntaxError: Illegal return statement");
-
-return NXT_ERROR;
+njs_token_t token;
+njs_parser_node_t   *node;
+njs_parser_scope_t  *scope;
+
+for (scope = parser->scope;
+ scope->type != NJS_SCOPE_FUNCTION;
+ scope = scope->parent)
+{
+if (scope->type == NJS_SCOPE_GLOBAL) {
+nxt_alert(>trace, NXT_LEVEL_ERROR,
+  "SyntaxError: Illegal return statement");
+
+return NXT_ERROR;
+}
 }
 
 node = njs_parser_node_alloc(vm);
diff -r 07dc20c1206d -r 6cc16ad934a4 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Mon Jan 16 14:51:29 2017 +0300
+++ b/njs/test/njs_unit_test.c  Mon Jan 16 17:32:10 2017 +0300
@@ -3976,6 +3976,9 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("return"),
   nxt_string("SyntaxError: Illegal return statement in 1") },
 
+{ nxt_string("{return}"),
+  nxt_string("SyntaxError: Illegal return statement in 1") },
+
 { nxt_string("function f() { return f() } f()"),
   nxt_string("RangeError: Maximum call stack size exceeded") },
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed parsing semicolons.

2017-01-16 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/07dc20c1206d
branches:  
changeset: 300:07dc20c1206d
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon Jan 16 14:51:29 2017 +0300
description:
Fixed parsing semicolons.

Found with AddressSanitizer.

diffstat:

 njs/njs_parser.c |  26 ++
 1 files changed, 18 insertions(+), 8 deletions(-)

diffs (76 lines):

diff -r e4f695e81689 -r 07dc20c1206d njs/njs_parser.c
--- a/njs/njs_parser.c  Thu Jan 05 15:55:52 2017 +0300
+++ b/njs/njs_parser.c  Mon Jan 16 14:51:29 2017 +0300
@@ -229,11 +229,9 @@ njs_parser_statement_chain(njs_vm_t *vm,
 
 if (nxt_fast_path(token > NJS_TOKEN_ILLEGAL)) {
 
-if (parser->node != last) {
-/*
- * The statement is not empty block, not just semicolon,
- * and not variables declaration without initialization.
- */
+if (parser->node != NULL) {
+/* The statement is not empty block or just semicolon. */
+
 node = njs_parser_node_alloc(vm);
 if (nxt_slow_path(node == NULL)) {
 return NJS_TOKEN_ERROR;
@@ -243,6 +241,15 @@ njs_parser_statement_chain(njs_vm_t *vm,
 node->left = last;
 node->right = parser->node;
 parser->node = node;
+
+while (token == NJS_TOKEN_SEMICOLON
+   || token == NJS_TOKEN_LINE_END)
+{
+token = njs_parser_token(parser);
+if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+break;
+}
+}
 }
 
 } else if (vm->exception == NULL) {
@@ -257,6 +264,8 @@ static njs_token_t
 njs_parser_statement(njs_vm_t *vm, njs_parser_t *parser,
 njs_token_t token)
 {
+parser->node = NULL;
+
 switch (token) {
 
 case NJS_TOKEN_FUNCTION:
@@ -296,7 +305,6 @@ njs_parser_statement(njs_vm_t *vm, njs_p
 return njs_parser_throw_statement(vm, parser);
 
 case NJS_TOKEN_SEMICOLON:
-parser->node = NULL;
 return njs_parser_token(parser);
 
 case NJS_TOKEN_OPEN_BRACE:
@@ -348,13 +356,13 @@ njs_parser_block_statement(njs_vm_t *vm,
 return token;
 }
 
-parser->node = NULL;
-
 ret = njs_parser_scope_begin(vm, parser, NJS_SCOPE_BLOCK);
 if (nxt_slow_path(ret != NXT_OK)) {
 return NJS_TOKEN_ERROR;
 }
 
+parser->node = NULL;
+
 while (token != NJS_TOKEN_CLOSE_BRACE) {
 token = njs_parser_statement_chain(vm, parser, token);
 if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
@@ -836,6 +844,8 @@ njs_parser_var_statement(njs_vm_t *vm, n
 switch (token) {
 
 case NJS_TOKEN_SEMICOLON:
+return njs_parser_token(parser);
+
 case NJS_TOKEN_CLOSE_BRACE:
 case NJS_TOKEN_END:
 return token;
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Removed unused things.

2017-01-05 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/e4f695e81689
branches:  
changeset: 299:e4f695e81689
user:  Igor Sysoev <i...@sysoev.ru>
date:  Thu Jan 05 15:55:52 2017 +0300
description:
Removed unused things.

diffstat:

 njs/njs_parser.c |  20 
 njs/njs_parser.h |   2 --
 njs/njscript.c   |   1 -
 3 files changed, 0 insertions(+), 23 deletions(-)

diffs (60 lines):

diff -r c11a7e133205 -r e4f695e81689 njs/njs_parser.c
--- a/njs/njs_parser.c  Thu Jan 05 15:55:49 2017 +0300
+++ b/njs/njs_parser.c  Thu Jan 05 15:55:52 2017 +0300
@@ -2434,26 +2434,6 @@ invalid:
 }
 
 
-njs_index_t
-njs_parser_index(njs_parser_t *parser, uint32_t scope)
-{
-nxt_uint_t   n;
-njs_index_t  index;
-
-/* Skip absolute scope. */
-n = scope - NJS_INDEX_CACHE;
-
-index = parser->index[n];
-parser->index[n] += sizeof(njs_value_t);
-
-index |= scope;
-
-nxt_thread_log_debug("GET %p", index);
-
-return index;
-}
-
-
 nxt_bool_t
 njs_parser_has_side_effect(njs_parser_node_t *node)
 {
diff -r c11a7e133205 -r e4f695e81689 njs/njs_parser.h
--- a/njs/njs_parser.h  Thu Jan 05 15:55:49 2017 +0300
+++ b/njs/njs_parser.h  Thu Jan 05 15:55:52 2017 +0300
@@ -309,7 +309,6 @@ struct njs_parser_s {
 njs_parser_scope_t  *scope;
 
 nxt_array_t *index_cache;
-njs_index_t index[NJS_SCOPES - NJS_INDEX_CACHE];
 
 uint8_t branch;   /* 1 bit */
 
@@ -354,7 +353,6 @@ njs_token_t njs_parser_property_name(njs
 njs_token_t njs_parser_property_token(njs_parser_t *parser);
 njs_token_t njs_parser_token(njs_parser_t *parser);
 nxt_int_t njs_parser_string_create(njs_vm_t *vm, njs_value_t *value);
-njs_index_t njs_parser_index(njs_parser_t *parser, uint32_t scope);
 njs_ret_t njs_variable_reference(njs_vm_t *vm, njs_parser_t *parser,
 njs_parser_node_t *node);
 njs_variable_t *njs_variable_get(njs_vm_t *vm, njs_parser_node_t *node,
diff -r c11a7e133205 -r e4f695e81689 njs/njscript.c
--- a/njs/njscript.cThu Jan 05 15:55:49 2017 +0300
+++ b/njs/njscript.cThu Jan 05 15:55:52 2017 +0300
@@ -213,7 +213,6 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
 
 parser->code_size = sizeof(njs_vmcode_stop_t);
 parser->scope_offset = NJS_INDEX_GLOBAL_OFFSET;
-parser->index[NJS_SCOPE_GLOBAL - NJS_INDEX_CACHE] = 
NJS_INDEX_GLOBAL_OFFSET;
 
 node = njs_parser(vm, parser);
 if (nxt_slow_path(node == NULL)) {
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Logical "or" and "and" operations should store result in a

2017-01-03 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/fe8027493a08
branches:  
changeset: 297:fe8027493a08
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Jan 03 19:38:17 2017 +0300
description:
Logical "or" and "and" operations should store result in a
temporary destination because they are actually branch operations.

diffstat:

 njs/njs_generator.c  |  4 ++--
 njs/test/njs_unit_test.c |  6 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diffs (37 lines):

diff -r 9672a3c3aaae -r fe8027493a08 njs/njs_generator.c
--- a/njs/njs_generator.c   Mon Jan 02 22:59:33 2017 +0300
+++ b/njs/njs_generator.c   Tue Jan 03 19:38:17 2017 +0300
@@ -1666,7 +1666,7 @@ njs_generate_test_jump_expression(njs_vm
 test_jump->code.retval = NJS_VMCODE_RETVAL;
 test_jump->value = node->left->index;
 
-node->index = njs_generator_dest_index(vm, parser, node);
+node->index = njs_generator_node_temp_index_get(vm, parser, node);
 if (nxt_slow_path(node->index == NJS_INDEX_ERROR)) {
 return node->index;
 }
@@ -1695,7 +1695,7 @@ njs_generate_test_jump_expression(njs_vm
 
 test_jump->offset = parser->code_end - (u_char *) test_jump;
 
-return njs_generator_node_index_release(vm, parser, node->right);
+return njs_generator_children_indexes_release(vm, parser, node);
 }
 
 
diff -r 9672a3c3aaae -r fe8027493a08 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Mon Jan 02 22:59:33 2017 +0300
+++ b/njs/test/njs_unit_test.c  Tue Jan 03 19:38:17 2017 +0300
@@ -568,6 +568,12 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("var a = 1; 1 || (a = 2); a"),
   nxt_string("1") },
 
+{ nxt_string("var x; x = 0 || x; x"),
+  nxt_string("undefined") },
+
+{ nxt_string("var x; x = 1 && x; x"),
+  nxt_string("undefined") },
+
 { nxt_string("1 || 2 || 3"),
   nxt_string("1") },
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] For-in loop does not discard the last value of property variable.

2017-01-03 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/8e1de8ab59e6
branches:  
changeset: 295:8e1de8ab59e6
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon Jan 02 22:59:31 2017 +0300
description:
For-in loop does not discard the last value of property variable.

diffstat:

 njs/njs_generator.c  |   2 +-
 njs/njs_vm.c |  10 +-
 njs/test/njs_unit_test.c |   9 +
 3 files changed, 15 insertions(+), 6 deletions(-)

diffs (82 lines):

diff -r 6c5bebb914ef -r 8e1de8ab59e6 njs/njs_generator.c
--- a/njs/njs_generator.c   Mon Jan 02 22:59:29 2017 +0300
+++ b/njs/njs_generator.c   Mon Jan 02 22:59:31 2017 +0300
@@ -1047,7 +1047,7 @@ njs_generate_for_in_statement(njs_vm_t *
 njs_generate_code(parser, njs_vmcode_prop_next_t, prop_next);
 prop_next->code.operation = njs_vmcode_property_next;
 prop_next->code.operands = NJS_VMCODE_3OPERANDS;
-prop_next->code.retval = NJS_VMCODE_RETVAL;
+prop_next->code.retval = NJS_VMCODE_NO_RETVAL;
 prop_next->retval = foreach->left->index;
 prop_next->object = foreach->right->index;
 prop_next->next = index;
diff -r 6c5bebb914ef -r 8e1de8ab59e6 njs/njs_vm.c
--- a/njs/njs_vm.c  Mon Jan 02 22:59:29 2017 +0300
+++ b/njs/njs_vm.c  Mon Jan 02 22:59:31 2017 +0300
@@ -1227,6 +1227,7 @@ njs_vmcode_property_next(njs_vm_t *vm, n
 {
 njs_ret_t   ret;
 nxt_uint_t  n;
+njs_value_t *retval;
 njs_array_t *array;
 njs_extern_t*ext;
 njs_object_prop_t   *prop;
@@ -1234,6 +1235,7 @@ njs_vmcode_property_next(njs_vm_t *vm, n
 njs_vmcode_prop_next_t  *code;
 
 code = (njs_vmcode_prop_next_t *) vm->current;
+retval = njs_vmcode_operand(vm, code->retval);
 
 if (njs_is_object(object)) {
 next = value->data.u.next;
@@ -1245,7 +1247,7 @@ njs_vmcode_property_next(njs_vm_t *vm, n
 n = next->index++;
 
 if (njs_is_valid(>start[n])) {
-njs_number_set(>retval, n);
+njs_number_set(retval, n);
 
 return code->offset;
 }
@@ -1257,20 +1259,18 @@ njs_vmcode_property_next(njs_vm_t *vm, n
 prop = nxt_lvlhsh_each(>data.u.object->hash, >lhe);
 
 if (prop != NULL) {
-vm->retval = prop->name;
+*retval = prop->name;
 
 return code->offset;
 }
 
 nxt_mem_cache_free(vm->mem_cache_pool, next);
 
-vm->retval = njs_value_void;
-
 } else if (njs_is_external(object)) {
 ext = object->data.u.external;
 
 if (ext->next != NULL) {
-ret = ext->next(vm, >retval, vm->external[ext->object], value);
+ret = ext->next(vm, retval, vm->external[ext->object], value);
 
 if (ret == NXT_OK) {
 return code->offset;
diff -r 6c5bebb914ef -r 8e1de8ab59e6 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Mon Jan 02 22:59:29 2017 +0300
+++ b/njs/test/njs_unit_test.c  Mon Jan 02 22:59:31 2017 +0300
@@ -4519,6 +4519,15 @@ static njs_unit_test_t  njs_test[] =
  "for (var i in o) { s += i }; s"),
   nxt_string("abc") },
 
+{ nxt_string("var o = { a: 1, b: 2, c: 3 }; for (var i in o); i"),
+  nxt_string("c") },
+
+{ nxt_string("var o = {}; i = 7; for (var i in o); i"),
+  nxt_string("7") },
+
+{ nxt_string("var a = [1,2,3]; for (var i in a); i"),
+  nxt_string("2") },
+
 /* RegExp. */
 
 { nxt_string("/./x"),
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed code generation for "in" operation with side effect.

2017-01-03 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/9672a3c3aaae
branches:  
changeset: 296:9672a3c3aaae
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon Jan 02 22:59:33 2017 +0300
description:
Fixed code generation for "in" operation with side effect.

diffstat:

 njs/njs_generator.c  |  41 +
 njs/test/njs_unit_test.c |   3 +++
 2 files changed, 24 insertions(+), 20 deletions(-)

diffs (99 lines):

diff -r 8e1de8ab59e6 -r 9672a3c3aaae njs/njs_generator.c
--- a/njs/njs_generator.c   Mon Jan 02 22:59:31 2017 +0300
+++ b/njs/njs_generator.c   Mon Jan 02 22:59:33 2017 +0300
@@ -81,7 +81,7 @@ static nxt_int_t njs_generate_regexp(njs
 static nxt_int_t njs_generate_test_jump_expression(njs_vm_t *vm,
 njs_parser_t *parser, njs_parser_node_t *node);
 static nxt_int_t njs_generate_3addr_operation(njs_vm_t *vm,
-njs_parser_t *parser, njs_parser_node_t *node);
+njs_parser_t *parser, njs_parser_node_t *node, nxt_bool_t swap);
 static nxt_int_t njs_generate_2addr_operation(njs_vm_t *vm,
 njs_parser_t *parser, njs_parser_node_t *node);
 static nxt_int_t njs_generate_typeof_operation(njs_vm_t *vm,
@@ -128,8 +128,6 @@ static const nxt_str_t  no_label = { 0, 
 static nxt_int_t
 njs_generator(njs_vm_t *vm, njs_parser_t *parser, njs_parser_node_t *node)
 {
-njs_parser_node_t  *left;
-
 if (node == NULL) {
 return NXT_OK;
 }
@@ -195,19 +193,6 @@ njs_generator(njs_vm_t *vm, njs_parser_t
 case NJS_TOKEN_REMAINDER_ASSIGNMENT:
 return njs_generate_operation_assignment(vm, parser, node);
 
-case NJS_TOKEN_IN:
-/*
- * An "in" operation is parsed as standard binary expression
- * by njs_parser_binary_expression().  However, its operands
- * should be swapped to be uniform with other property operations
- * (get/set and delete) to use the property trap.
- */
-left = node->left;
-node->left = node->right;
-node->right = left;
-
-/* Fall through. */
-
 case NJS_TOKEN_BITWISE_OR:
 case NJS_TOKEN_BITWISE_XOR:
 case NJS_TOKEN_BITWISE_AND:
@@ -231,7 +216,16 @@ njs_generator(njs_vm_t *vm, njs_parser_t
 case NJS_TOKEN_REMAINDER:
 case NJS_TOKEN_PROPERTY_DELETE:
 case NJS_TOKEN_PROPERTY:
-return njs_generate_3addr_operation(vm, parser, node);
+return njs_generate_3addr_operation(vm, parser, node, 0);
+
+case NJS_TOKEN_IN:
+/*
+ * An "in" operation is parsed as standard binary expression
+ * by njs_parser_binary_expression().  However, its operands
+ * should be swapped to be uniform with other property operations
+ * (get/set and delete) to use the property trap.
+ */
+return njs_generate_3addr_operation(vm, parser, node, 1);
 
 case NJS_TOKEN_LOGICAL_AND:
 case NJS_TOKEN_LOGICAL_OR:
@@ -1707,7 +1701,7 @@ njs_generate_test_jump_expression(njs_vm
 
 static nxt_int_t
 njs_generate_3addr_operation(njs_vm_t *vm, njs_parser_t *parser,
-njs_parser_node_t *node)
+njs_parser_node_t *node, nxt_bool_t swap)
 {
 nxt_int_t   ret;
 njs_index_t index;
@@ -1751,8 +1745,15 @@ njs_generate_3addr_operation(njs_vm_t *v
 code->code.operation = node->u.operation;
 code->code.operands = NJS_VMCODE_3OPERANDS;
 code->code.retval = NJS_VMCODE_RETVAL;
-code->src1 = left->index;
-code->src2 = right->index;
+
+if (!swap) {
+code->src1 = left->index;
+code->src2 = right->index;
+
+} else {
+code->src1 = right->index;
+code->src2 = left->index;
+}
 
 /*
  * The temporary index of MOVE destination
diff -r 8e1de8ab59e6 -r 9672a3c3aaae njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Mon Jan 02 22:59:31 2017 +0300
+++ b/njs/test/njs_unit_test.c  Mon Jan 02 22:59:33 2017 +0300
@@ -224,6 +224,9 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("var a = 1; function f(x) { a = x; return 2 }; a += f(5)"),
   nxt_string("3") },
 
+{ nxt_string("var x; x in (x = 1, [1, 2, 3])"),
+  nxt_string("false") },
+
 /* Exponentiation. */
 
 { nxt_string("2 ** 3 ** 2"),
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Version 0.1.7.

2016-12-26 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/15dc54100400
branches:  
changeset: 290:15dc54100400
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Dec 27 10:39:53 2016 +0300
description:
Version 0.1.7.

diffstat:

 Makefile |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (10 lines):

diff -r 58342f302de3 -r 15dc54100400 Makefile
--- a/Makefile  Fri Dec 23 19:42:15 2016 +0300
+++ b/Makefile  Tue Dec 27 10:39:53 2016 +0300
@@ -1,5 +1,5 @@
 
-NJS_VER =  0.1.6
+NJS_VER =  0.1.7
 
 NXT_LIB =  nxt
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Added tag 0.1.7 for changeset 15dc54100400

2016-12-26 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/1944eaa4b2cf
branches:  
changeset: 291:1944eaa4b2cf
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Dec 27 10:40:08 2016 +0300
description:
Added tag 0.1.7 for changeset 15dc54100400

diffstat:

 .hgtags |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (8 lines):

diff -r 15dc54100400 -r 1944eaa4b2cf .hgtags
--- a/.hgtags   Tue Dec 27 10:39:53 2016 +0300
+++ b/.hgtags   Tue Dec 27 10:40:08 2016 +0300
@@ -5,3 +5,4 @@ 360449773d51e7f451e5396e27021badc6b86085
 508689c1fb94c23f6b24be087c1dc63b2f9e6654 0.1.4
 9c813c2bb2acfd5b6e9d1e9b6699af928baea15a 0.1.5
 44b524f7e313369cd062a387511ea6fdc427875f 0.1.6
+15dc54100400f99c3ec044d8fb0175dd3d69adcb 0.1.7
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Added tag 0.1.6 for changeset 44b524f7e313

2016-12-13 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/43582218defe
branches:  
changeset: 283:43582218defe
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Dec 13 14:18:40 2016 +0300
description:
Added tag 0.1.6 for changeset 44b524f7e313

diffstat:

 .hgtags |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (8 lines):

diff -r 44b524f7e313 -r 43582218defe .hgtags
--- a/.hgtags   Tue Dec 13 14:18:11 2016 +0300
+++ b/.hgtags   Tue Dec 13 14:18:40 2016 +0300
@@ -4,3 +4,4 @@ 5b066b4db54c17dc0a9a72948474f36957462e87
 360449773d51e7f451e5396e27021badc6b86085 0.1.3
 508689c1fb94c23f6b24be087c1dc63b2f9e6654 0.1.4
 9c813c2bb2acfd5b6e9d1e9b6699af928baea15a 0.1.5
+44b524f7e313369cd062a387511ea6fdc427875f 0.1.6
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Version 0.1.6.

2016-12-13 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/44b524f7e313
branches:  
changeset: 282:44b524f7e313
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Dec 13 14:18:11 2016 +0300
description:
Version 0.1.6.

diffstat:

 Makefile |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (10 lines):

diff -r b54508367550 -r 44b524f7e313 Makefile
--- a/Makefile  Tue Dec 13 14:04:46 2016 +0300
+++ b/Makefile  Tue Dec 13 14:18:11 2016 +0300
@@ -1,5 +1,5 @@
 
-NJS_VER =  0.1.5
+NJS_VER =  0.1.6
 
 NXT_LIB =  nxt
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed building with CFLAGS=-DNXT_DEBUG_MEMORY=1 by some compilers.

2016-12-08 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/6a60530c7b6b
branches:  
changeset: 279:6a60530c7b6b
user:  Igor Sysoev <i...@sysoev.ru>
date:  Thu Dec 08 19:50:03 2016 +0300
description:
Fixed building with CFLAGS=-DNXT_DEBUG_MEMORY=1 by some compilers.

diffstat:

 nxt/nxt_mem_cache_pool.c |  26 +-
 1 files changed, 13 insertions(+), 13 deletions(-)

diffs (43 lines):

diff -r af66e460d7a0 -r 6a60530c7b6b nxt/nxt_mem_cache_pool.c
--- a/nxt/nxt_mem_cache_pool.c  Thu Dec 08 19:29:40 2016 +0300
+++ b/nxt/nxt_mem_cache_pool.c  Thu Dec 08 19:50:03 2016 +0300
@@ -284,19 +284,6 @@ nxt_mem_cache_pool_destroy(nxt_mem_cache
 }
 
 
-nxt_inline u_char *
-nxt_mem_cache_page_addr(nxt_mem_cache_pool_t *pool, nxt_mem_cache_page_t *page)
-{
-nxt_mem_cache_block_t  *block;
-
-block = (nxt_mem_cache_block_t *)
-((u_char *) page - page->number * sizeof(nxt_mem_cache_page_t)
- - offsetof(nxt_mem_cache_block_t, pages));
-
-return block->start + (page->number << pool->page_size_shift);
-}
-
-
 void *
 nxt_mem_cache_alloc(nxt_mem_cache_pool_t *pool, size_t size)
 {
@@ -379,6 +366,19 @@ nxt_mem_cache_zalign(nxt_mem_cache_pool_
 
 #if !(NXT_DEBUG_MEMORY)
 
+nxt_inline u_char *
+nxt_mem_cache_page_addr(nxt_mem_cache_pool_t *pool, nxt_mem_cache_page_t *page)
+{
+nxt_mem_cache_block_t  *block;
+
+block = (nxt_mem_cache_block_t *)
+((u_char *) page - page->number * sizeof(nxt_mem_cache_page_t)
+ - offsetof(nxt_mem_cache_block_t, pages));
+
+return block->start + (page->number << pool->page_size_shift);
+}
+
+
 static void *
 nxt_mem_cache_alloc_small(nxt_mem_cache_pool_t *pool, size_t size)
 {
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Array and object literals did not support assignment expressions.

2016-12-08 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/0315d62a78c2
branches:  
changeset: 277:0315d62a78c2
user:  Igor Sysoev <i...@sysoev.ru>
date:  Thu Dec 08 17:15:54 2016 +0300
description:
Array and object literals did not support assignment expressions.

Thanks to ??? (Hong Zhi Dao).

diffstat:

 njs/njs_parser.c|   4 ++--
 njs/njs_parser.h|   2 +-
 njs/njs_parser_expression.c |  24 +---
 njs/test/njs_unit_test.c|   6 ++
 4 files changed, 26 insertions(+), 10 deletions(-)

diffs (135 lines):

diff -r 2380d725ec7b -r 0315d62a78c2 njs/njs_parser.c
--- a/njs/njs_parser.c  Wed Dec 07 19:34:48 2016 +0300
+++ b/njs/njs_parser.c  Thu Dec 08 17:15:54 2016 +0300
@@ -1829,7 +1829,7 @@ njs_parser_object(njs_vm_t *vm, njs_pars
 return token;
 }
 
-token = njs_parser_conditional_expression(vm, parser, token);
+token = njs_parser_assignment_expression(vm, parser, token);
 if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
 return token;
 }
@@ -1924,7 +1924,7 @@ njs_parser_array(njs_vm_t *vm, njs_parse
 propref->right = node;
 parser->code_size += sizeof(njs_vmcode_3addr_t);
 
-token = njs_parser_conditional_expression(vm, parser, token);
+token = njs_parser_assignment_expression(vm, parser, token);
 if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
 return token;
 }
diff -r 2380d725ec7b -r 0315d62a78c2 njs/njs_parser.h
--- a/njs/njs_parser.h  Wed Dec 07 19:34:48 2016 +0300
+++ b/njs/njs_parser.h  Thu Dec 08 17:15:54 2016 +0300
@@ -334,7 +334,7 @@ njs_token_t njs_parser_expression(njs_vm
 njs_token_t token);
 njs_token_t njs_parser_var_expression(njs_vm_t *vm, njs_parser_t *parser,
 njs_token_t token);
-njs_token_t njs_parser_conditional_expression(njs_vm_t *vm,
+njs_token_t njs_parser_assignment_expression(njs_vm_t *vm,
 njs_parser_t *parser, njs_token_t token);
 njs_token_t njs_parser_terminal(njs_vm_t *vm, njs_parser_t *parser,
 njs_token_t token);
diff -r 2380d725ec7b -r 0315d62a78c2 njs/njs_parser_expression.c
--- a/njs/njs_parser_expression.c   Wed Dec 07 19:34:48 2016 +0300
+++ b/njs/njs_parser_expression.c   Thu Dec 08 17:15:54 2016 +0300
@@ -55,9 +55,11 @@ struct njs_parser_expression_s {
 };
 
 
-static njs_token_t njs_parser_assignment_expression(njs_vm_t *vm,
+static njs_token_t njs_parser_any_expression(njs_vm_t *vm,
 njs_parser_t *parser, const njs_parser_expression_t *expr,
 njs_token_t token);
+static njs_token_t njs_parser_conditional_expression(njs_vm_t *vm,
+njs_parser_t *parser, njs_token_t token);
 static njs_token_t njs_parser_binary_expression(njs_vm_t *vm,
 njs_parser_t *parser, const njs_parser_expression_t *expr,
 njs_token_t token);
@@ -227,7 +229,7 @@ static const njs_parser_expression_t
 static const njs_parser_expression_t
 njs_parser_comma_expression =
 {
-njs_parser_assignment_expression,
+njs_parser_any_expression,
 NULL,
 1, {
 { NJS_TOKEN_COMMA, NULL, 0 },
@@ -346,8 +348,16 @@ njs_parser_var_expression(njs_vm_t *vm, 
 
 
 static njs_token_t
+njs_parser_any_expression(njs_vm_t *vm, njs_parser_t *parser,
+const njs_parser_expression_t *expr, njs_token_t token)
+{
+return njs_parser_assignment_expression(vm, parser, token);
+}
+
+
+njs_token_t
 njs_parser_assignment_expression(njs_vm_t *vm, njs_parser_t *parser,
-const njs_parser_expression_t *expr, njs_token_t token)
+njs_token_t token)
 {
 size_t  size;
 njs_parser_node_t   *node, *pending;
@@ -475,7 +485,7 @@ njs_parser_assignment_expression(njs_vm_
 return token;
 }
 
-token = njs_parser_assignment_expression(vm, parser, NULL, token);
+token = njs_parser_assignment_expression(vm, parser, token);
 if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
 return token;
 }
@@ -568,7 +578,7 @@ njs_parser_conditional_expression(njs_vm
 cond->right = node;
 node->token = NJS_TOKEN_BRANCHING;
 
-token = njs_parser_assignment_expression(vm, parser, NULL, token);
+token = njs_parser_assignment_expression(vm, parser, token);
 if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
 return token;
 }
@@ -585,7 +595,7 @@ njs_parser_conditional_expression(njs_vm
 return token;
 }
 
-token = njs_parser_assignment_expression(vm, parser, NULL, token);
+token = njs_parser_assignment_expression(vm, parser, token);
 if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
 return token;
 }
@@ -1210,7 +1220,7 @@ njs_parser_arguments(njs_vm_t *vm, njs_p
 break;
 }
 
-token = njs_parser_assignment_expression(vm, parser, NULL, token);
+token = njs_parser_assignment_expression(vm, parser, token);
 if (nxt_slow_path(token <= NJS_TOKEN_I

[njs] A user defined object method called as constructor did not

2016-12-07 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/2380d725ec7b
branches:  
changeset: 276:2380d725ec7b
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Dec 07 19:34:48 2016 +0300
description:
A user defined object method called as constructor did not
create correct prototype links in created objects.

Thanks to ??? (Hong Zhi Dao).

diffstat:

 njs/njs_function.c   |7 +-
 njs/njs_function.h   |3 +-
 njs/njs_vm.c |  177 ++
 njs/test/njs_unit_test.c |4 +
 4 files changed, 82 insertions(+), 109 deletions(-)

diffs (298 lines):

diff -r 56d6fc12dc31 -r 2380d725ec7b njs/njs_function.c
--- a/njs/njs_function.cWed Dec 07 15:02:00 2016 +0300
+++ b/njs/njs_function.cWed Dec 07 19:34:48 2016 +0300
@@ -111,12 +111,14 @@ njs_function_native_frame(njs_vm_t *vm, 
 bound = function->bound;
 
 if (bound == NULL) {
+/* GC: njs_retain(this); */
 *value++ = *this;
 
 } else {
 n = function->args_offset;
 
 do {
+/* GC: njs_retain(bound); */
 *value++ = *bound++;
 n--;
 } while (n != 0);
@@ -134,8 +136,9 @@ njs_function_native_frame(njs_vm_t *vm, 
 
 
 nxt_noinline njs_ret_t
-njs_function_frame(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
-njs_value_t *args, nxt_uint_t nargs, nxt_bool_t ctor)
+njs_function_frame(njs_vm_t *vm, njs_function_t *function,
+const njs_value_t *this, njs_value_t *args, nxt_uint_t nargs,
+nxt_bool_t ctor)
 {
 size_t  size;
 nxt_uint_t  n, max_args;
diff -r 56d6fc12dc31 -r 2380d725ec7b njs/njs_function.h
--- a/njs/njs_function.hWed Dec 07 15:02:00 2016 +0300
+++ b/njs/njs_function.hWed Dec 07 19:34:48 2016 +0300
@@ -138,7 +138,8 @@ njs_ret_t njs_function_native_frame(njs_
 const njs_value_t *this, njs_value_t *args, nxt_uint_t nargs,
 size_t reserve, nxt_bool_t ctor);
 njs_ret_t njs_function_frame(njs_vm_t *vm, njs_function_t *function,
-njs_value_t *this, njs_value_t *args, nxt_uint_t nargs, nxt_bool_t ctor);
+const njs_value_t *this, njs_value_t *args, nxt_uint_t nargs,
+nxt_bool_t ctor);
 njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
 
 extern const njs_object_init_t  njs_function_constructor_init;
diff -r 56d6fc12dc31 -r 2380d725ec7b njs/njs_vm.c
--- a/njs/njs_vm.c  Wed Dec 07 15:02:00 2016 +0300
+++ b/njs/njs_vm.c  Wed Dec 07 19:34:48 2016 +0300
@@ -82,9 +82,9 @@ static nxt_noinline njs_ret_t njs_values
 const njs_value_t *val2);
 static nxt_noinline njs_ret_t njs_values_compare(const njs_value_t *val1,
 const njs_value_t *val2);
+static njs_ret_t njs_function_frame_create(njs_vm_t *vm, njs_value_t *value,
+const njs_value_t *this, uintptr_t nargs, nxt_bool_t ctor);
 static njs_object_t *njs_function_new_object(njs_vm_t *vm, njs_value_t *value);
-static njs_ret_t njs_vmcode_method_call(njs_vm_t *vm, njs_value_t *object,
-njs_value_t *value);
 static njs_ret_t njs_vmcode_continuation(njs_vm_t *vm, njs_value_t *invld1,
 njs_value_t *invld2);
 static njs_native_frame_t *
@@ -2127,61 +2127,58 @@ njs_ret_t
 njs_vmcode_function_frame(njs_vm_t *vm, njs_value_t *value, njs_value_t *nargs)
 {
 njs_ret_tret;
-nxt_bool_t   ctor;
-njs_value_t  val, *this;
-njs_object_t *object;
-njs_function_t   *function;
-njs_vmcode_function_frame_t  *func;
+njs_vmcode_function_frame_t  *function;
+
+function = (njs_vmcode_function_frame_t *) vm->current;
+
+/* TODO: external object instead of void this. */
+
+ret = njs_function_frame_create(vm, value, _value_void,
+(uintptr_t) nargs, function->code.ctor);
+
+if (nxt_fast_path(ret == NXT_OK)) {
+return sizeof(njs_vmcode_function_frame_t);
+}
+
+return ret;
+}
+
+
+static njs_ret_t
+njs_function_frame_create(njs_vm_t *vm, njs_value_t *value,
+const njs_value_t *this, uintptr_t nargs, nxt_bool_t ctor)
+{
+njs_value_t val;
+njs_object_t*object;
+njs_function_t  *function;
 
 if (nxt_fast_path(njs_is_function(value))) {
 
-func = (njs_vmcode_function_frame_t *) vm->current;
-ctor = func->code.ctor;
-
 function = value->data.u.function;
 
-if (function->native) {
-if (ctor && !function->ctor) {
-goto fail;
+if (!function->native) {
+
+if (ctor) {
+object = njs_function_new_object(vm, value);
+if (nxt_slow_path(object == NULL)) {
+return NXT_ERROR;
+}
+
+val.data.u.object = object;
+val.type = NJS_OBJECT;
+val.data.truth = 1;
+this = 
 }
 
-ret = njs_fun

[njs] Fixed "return" usage in a true branch of an "if" statement.

2016-12-07 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/56d6fc12dc31
branches:  
changeset: 275:56d6fc12dc31
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Dec 07 15:02:00 2016 +0300
description:
Fixed "return" usage in a true branch of an "if" statement.

diffstat:

 njs/njs_parser.c |   4 
 njs/test/njs_unit_test.c |  15 +++
 2 files changed, 19 insertions(+), 0 deletions(-)

diffs (39 lines):

diff -r 709ac03a4bfd -r 56d6fc12dc31 njs/njs_parser.c
--- a/njs/njs_parser.c  Mon Dec 05 17:47:00 2016 +0300
+++ b/njs/njs_parser.c  Wed Dec 07 15:02:00 2016 +0300
@@ -629,6 +629,10 @@ njs_parser_return_statement(njs_vm_t *vm
 node->right = parser->node;
 parser->node = node;
 
+if (token == NJS_TOKEN_SEMICOLON) {
+return njs_parser_token(parser);
+}
+
 return token;
 }
 }
diff -r 709ac03a4bfd -r 56d6fc12dc31 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Mon Dec 05 17:47:00 2016 +0300
+++ b/njs/test/njs_unit_test.c  Wed Dec 07 15:02:00 2016 +0300
@@ -1514,6 +1514,21 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("var a = [3], b; if (1==1||2==2) { b = '1'+'2'+a[0] }; b }"),
   nxt_string("123") },
 
+{ nxt_string("(function(){ if(true) return 1 else return 0; })()"),
+  nxt_string("1") },
+
+{ nxt_string("(function(){ if(true) return 1; else return 0; })()"),
+  nxt_string("1") },
+
+{ nxt_string("(function(){ if(true) return 1;; else return 0; })()"),
+  nxt_string("SyntaxError: Unexpected token \"else\" in 1") },
+
+{ nxt_string("(function(){ if(true) return 1\n else return 0; })()"),
+  nxt_string("1") },
+
+{ nxt_string("(function(){ if(true) return 1\n;\n else return 0; })()"),
+  nxt_string("1") },
+
 /* do while. */
 
 { nxt_string("do { break } if (false)"),
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


nginScript documentation

2016-12-05 Thread Igor Sysoev
Hi!

We have made recently documentation for nginScript:

http://nginx.org/en/docs/http/ngx_http_js_module.html
http://nginx.org/en/docs/stream/ngx_stream_js_module.html
http://nginx.org/en/docs/njs_about.html


-- 
Igor Sysoev
http://nginx.com

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] RegExp.prototype.toString() should be applied only to RegExp.

2016-12-05 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/709ac03a4bfd
branches:  
changeset: 274:709ac03a4bfd
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon Dec 05 17:47:00 2016 +0300
description:
RegExp.prototype.toString() should be applied only to RegExp.

diffstat:

 njs/njs_regexp.c |  19 ++-
 njs/test/njs_unit_test.c |   3 +++
 2 files changed, 17 insertions(+), 5 deletions(-)

diffs (46 lines):

diff -r 15ec6a09cece -r 709ac03a4bfd njs/njs_regexp.c
--- a/njs/njs_regexp.c  Mon Dec 05 17:45:02 2016 +0300
+++ b/njs/njs_regexp.c  Mon Dec 05 17:47:00 2016 +0300
@@ -560,15 +560,24 @@ njs_regexp_prototype_to_string(njs_vm_t 
 u_char*source;
 int32_t   length;
 uint32_t  size;
+njs_value_t   *value;
 njs_regexp_pattern_t  *pattern;
 
-pattern = args[0].data.u.regexp->pattern;
-source = pattern->source;
+value = [0];
 
-size = strlen((char *) source);
-length = nxt_utf8_length(source, size);
+if (value->type == NJS_REGEXP) {
+pattern = value->data.u.regexp->pattern;
+source = pattern->source;
 
-return njs_regexp_string_create(vm, >retval, source, size, length);
+size = strlen((char *) source);
+length = nxt_utf8_length(source, size);
+
+return njs_regexp_string_create(vm, >retval, source, size, length);
+}
+
+vm->exception = _exception_type_error;
+
+return NXT_ERROR;
 }
 
 
diff -r 15ec6a09cece -r 709ac03a4bfd njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Mon Dec 05 17:45:02 2016 +0300
+++ b/njs/test/njs_unit_test.c  Mon Dec 05 17:47:00 2016 +0300
@@ -4410,6 +4410,9 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("var r = new RegExp('abc', 'i'); r.test('00ABC11')"),
   nxt_string("true") },
 
+{ nxt_string("[0].map(RegExp().toString)"),
+  nxt_string("TypeError") },
+
 /* Non-standard ECMA-262 features. */
 
 /* 0x10400 is not a surrogate pair of 0xD801 and 0xDC00. */
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Native methods called by iterators should run via continuation

2016-12-05 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/eba4f3a30bb4
branches:  
changeset: 272:eba4f3a30bb4
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon Dec 05 17:35:33 2016 +0300
description:
Native methods called by iterators should run via continuation
to normilize arguments.

diffstat:

 njs/njs_function.c   |  12 ++--
 njs/njs_function.h   |   1 +
 njs/njs_vm.c |   8 
 njs/test/njs_unit_test.c |   3 +++
 4 files changed, 14 insertions(+), 10 deletions(-)

diffs (83 lines):

diff -r 7275165c3832 -r eba4f3a30bb4 njs/njs_function.c
--- a/njs/njs_function.cFri Dec 02 17:11:57 2016 +0300
+++ b/njs/njs_function.cMon Dec 05 17:35:33 2016 +0300
@@ -252,21 +252,12 @@ nxt_noinline njs_ret_t
 njs_function_apply(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
 nxt_uint_t nargs, njs_index_t retval)
 {
-size_t  reserve;
 njs_ret_t   ret;
 njs_continuation_t  *cont;
 
 if (function->native) {
-
-if (function->continuation_size == 0 && function->bound == NULL) {
-return function->u.native(vm, args, nargs, retval);
-}
-
-reserve = nxt_align_size(sizeof(njs_continuation_t),
- sizeof(njs_value_t)),
-
 ret = njs_function_native_frame(vm, function, [0], [1],
-nargs - 1, reserve, 0);
+nargs - 1, NJS_CONTINUATION_SIZE, 0);
 if (ret != NJS_OK) {
 return ret;
 }
@@ -274,6 +265,7 @@ njs_function_apply(njs_vm_t *vm, njs_fun
 cont = njs_continuation(vm->frame);
 
 cont->function = function->u.native;
+cont->args_types = function->args_types;
 cont->retval = retval;
 
 cont->return_address = vm->current;
diff -r 7275165c3832 -r eba4f3a30bb4 njs/njs_function.h
--- a/njs/njs_function.hFri Dec 02 17:11:57 2016 +0300
+++ b/njs/njs_function.hMon Dec 05 17:35:33 2016 +0300
@@ -50,6 +50,7 @@ struct njs_function_lambda_s {
 
 typedef struct {
 njs_function_native_t  function;
+uint8_t*args_types;
 u_char *return_address;
 njs_index_tretval;
 } njs_continuation_t;
diff -r 7275165c3832 -r eba4f3a30bb4 njs/njs_vm.c
--- a/njs/njs_vm.c  Fri Dec 02 17:11:57 2016 +0300
+++ b/njs/njs_vm.c  Mon Dec 05 17:35:33 2016 +0300
@@ -2358,6 +2358,7 @@ njs_vmcode_function_call(njs_vm_t *vm, n
 cont = njs_continuation(vm->frame);
 
 cont->function = function->u.native;
+cont->args_types = function->args_types;
 cont->retval = (njs_index_t) retval;
 
 cont->return_address = vm->current + 
sizeof(njs_vmcode_function_call_t);
@@ -2609,6 +2610,13 @@ njs_vmcode_continuation(njs_vm_t *vm, nj
 cont = njs_continuation(frame);
 args = frame->arguments - frame->function->args_offset;
 
+if (cont->args_types != NULL) {
+ret = njs_normalize_args(vm, args, cont->args_types, frame->nargs);
+if (ret != NJS_OK) {
+return ret;
+}
+}
+
 ret = cont->function(vm, args, frame->nargs, cont->retval);
 
 switch (ret) {
diff -r 7275165c3832 -r eba4f3a30bb4 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Fri Dec 02 17:11:57 2016 +0300
+++ b/njs/test/njs_unit_test.c  Mon Dec 05 17:35:33 2016 +0300
@@ -5461,6 +5461,9 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("var d = new Date(); d.__proto__ === Date.prototype"),
   nxt_string("true") },
 
+{ nxt_string("[0].map(new Date().getDate)"),
+  nxt_string("TypeError") },
+
 { nxt_string("new Date(eval)"),
   nxt_string("Invalid Date") },
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Native methods called with Function.prototype.call() and

2016-12-05 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/15ec6a09cece
branches:  
changeset: 273:15ec6a09cece
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon Dec 05 17:45:02 2016 +0300
description:
Native methods called with Function.prototype.call() and
Functon.prototype.apply() should run via continuation to
normilize arguments.

diffstat:

 njs/njs_function.c |  21 -
 1 files changed, 16 insertions(+), 5 deletions(-)

diffs (46 lines):

diff -r eba4f3a30bb4 -r 15ec6a09cece njs/njs_function.c
--- a/njs/njs_function.cMon Dec 05 17:35:33 2016 +0300
+++ b/njs/njs_function.cMon Dec 05 17:45:02 2016 +0300
@@ -484,18 +484,29 @@ static njs_ret_t
 njs_function_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t 
*this,
 njs_value_t *args, nxt_uint_t nargs, njs_index_t retval)
 {
-njs_ret_t  ret;
+njs_ret_t   ret;
+njs_continuation_t  *cont;
 
 if (function->native) {
-ret = njs_function_native_frame(vm, function, this, args,
-nargs, 0, 0);
+ret = njs_function_native_frame(vm, function, this, args, nargs,
+NJS_CONTINUATION_SIZE, 0);
 if (nxt_slow_path(ret != NXT_OK)) {
 return ret;
 }
 
-/* Skip the "apply" method frame. */
+/* Skip the "call/apply" method frame. */
 vm->frame->previous->skip = 1;
 
+cont = njs_continuation(vm->frame);
+
+cont->function = function->u.native;
+cont->args_types = function->args_types;
+cont->retval = retval;
+
+cont->return_address = vm->current
+   + sizeof(njs_vmcode_function_call_t);;
+vm->current = (u_char *) njs_continuation_nexus;
+
 return NJS_APPLIED;
 }
 
@@ -505,7 +516,7 @@ njs_function_activate(njs_vm_t *vm, njs_
 return ret;
 }
 
-/* Skip the "apply" method frame. */
+/* Skip the "call/apply" method frame. */
 vm->frame->previous->skip = 1;
 
 return njs_function_call(vm, retval, sizeof(njs_vmcode_function_call_t));
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Using short string values where they are enough.

2016-12-01 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/f8f20b27724e
branches:  
changeset: 270:f8f20b27724e
user:  Igor Sysoev <i...@sysoev.ru>
date:  Thu Dec 01 19:45:19 2016 +0300
description:
Using short string values where they are enough.

diffstat:

 njs/njs_date.c   |  28 ++--
 njs/njs_object.c |   3 +--
 2 files changed, 15 insertions(+), 16 deletions(-)

diffs (136 lines):

diff -r 6d0d4a92fa02 -r f8f20b27724e njs/njs_date.c
--- a/njs/njs_date.cThu Dec 01 18:56:35 2016 +0300
+++ b/njs/njs_date.cThu Dec 01 19:45:19 2016 +0300
@@ -2097,7 +2097,7 @@ static const njs_object_prop_t  njs_date
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setTime"),
+.name = njs_string("setTime"),
 .value = njs_native_function(njs_date_prototype_set_time, 0,
  NJS_DATE_ARG, NJS_NUMBER_ARG),
 },
@@ -2118,21 +2118,21 @@ static const njs_object_prop_t  njs_date
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setSeconds"),
+.name = njs_string("setSeconds"),
 .value = njs_native_function(njs_date_prototype_set_seconds, 0,
  NJS_DATE_ARG, NJS_NUMBER_ARG),
 },
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setUTCSeconds"),
+.name = njs_string("setUTCSeconds"),
 .value = njs_native_function(njs_date_prototype_set_seconds, 0,
  NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
 },
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setMinutes"),
+.name = njs_string("setMinutes"),
 .value = njs_native_function(njs_date_prototype_set_minutes, 0,
  NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
  NJS_NUMBER_ARG),
@@ -2140,7 +2140,7 @@ static const njs_object_prop_t  njs_date
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setUTCMinutes"),
+.name = njs_string("setUTCMinutes"),
 .value = njs_native_function(njs_date_prototype_set_utc_minutes, 0,
  NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
  NJS_NUMBER_ARG),
@@ -2148,7 +2148,7 @@ static const njs_object_prop_t  njs_date
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setHours"),
+.name = njs_string("setHours"),
 .value = njs_native_function(njs_date_prototype_set_hours, 0,
  NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
  NJS_NUMBER_ARG, NJS_NUMBER_ARG),
@@ -2156,7 +2156,7 @@ static const njs_object_prop_t  njs_date
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setUTCHours"),
+.name = njs_string("setUTCHours"),
 .value = njs_native_function(njs_date_prototype_set_utc_hours, 0,
  NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
  NJS_NUMBER_ARG, NJS_NUMBER_ARG),
@@ -2164,35 +2164,35 @@ static const njs_object_prop_t  njs_date
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setDate"),
+.name = njs_string("setDate"),
 .value = njs_native_function(njs_date_prototype_set_date, 0,
  NJS_DATE_ARG, NJS_NUMBER_ARG),
 },
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setUTCDate"),
+.name = njs_string("setUTCDate"),
 .value = njs_native_function(njs_date_prototype_set_utc_date, 0,
  NJS_DATE_ARG, NJS_NUMBER_ARG),
 },
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setMonth"),
+.name = njs_string("setMonth"),
 .value = njs_native_function(njs_date_prototype_set_month, 0,
  NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
 },
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setUTCMonth"),
+.name = njs_string("setUTCMonth"),
 .value = njs_native_function(njs_date_prototype_set_utc_month, 0,
  NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG),
 },
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setFullYear"),
+.name = njs_string("setFullYear"),
 .value = njs_native_function(njs_date_prototype_set_full_year, 0,
  NJS_DATE_ARG, NJS_NUMBER_ARG, NJS_NUMBER_ARG,
  NJS_NUMBER_ARG),
@@ -2200,7 +2200,7 @@ static const njs_object_prop_t  njs_date
 
 {
 .type = NJS_METHOD,
-.name = njs_long_string("setUTCFullYear"),
+.name = njs_string("setUTCFullYear"),
 .value = njs_native_function(njs_date_prototype_set_utc_full_year, 0,
  NJS_DATE_ARG, NJS_

[njs] Added more dependencies on nxt_auto_config.h.

2016-11-30 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/86c35adbd3f9
branches:  
changeset: 268:86c35adbd3f9
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Nov 30 14:53:15 2016 +0300
description:
Added more dependencies on nxt_auto_config.h.

diffstat:

 Makefile   |  14 +++---
 nxt/Makefile   |   1 +
 nxt/auto/configure |   7 ---
 nxt/test/Makefile  |   1 +
 4 files changed, 9 insertions(+), 14 deletions(-)

diffs (67 lines):

diff -r adfb758ad872 -r 86c35adbd3f9 Makefile
--- a/Makefile  Wed Nov 30 14:10:49 2016 +0300
+++ b/Makefile  Wed Nov 30 14:53:15 2016 +0300
@@ -7,14 +7,8 @@ NXT_LIB =  nxt
 
 NXT_BUILDDIR = build
 
-unconfigured:
-   @echo
-   @echo " Please run ./configure before make"
-   @echo
-
-main:  $(NXT_BUILDDIR)/libnjs.a
-
 $(NXT_BUILDDIR)/libnjs.a: \
+   $(NXT_LIB)/nxt_auto_config.h \
$(NXT_BUILDDIR)/njscript.o \
$(NXT_BUILDDIR)/njs_vm.o \
$(NXT_BUILDDIR)/njs_boolean.o \
@@ -97,6 +91,12 @@ dist:
tar czf njs-$(NJS_VER).tar.gz njs-$(NJS_VER)
rm -rf njs-$(NJS_VER)
 
+$(NXT_LIB)/nxt_auto_config.h:
+   @echo
+   @echo " Please run ./configure before make"
+   @echo
+   @exit 1
+
 $(NXT_BUILDDIR)/njscript.o: \
$(NXT_BUILDDIR)/libnxt.a \
njs/njs_vm.h \
diff -r adfb758ad872 -r 86c35adbd3f9 nxt/Makefile
--- a/nxt/Makefile  Wed Nov 30 14:10:49 2016 +0300
+++ b/nxt/Makefile  Wed Nov 30 14:53:15 2016 +0300
@@ -3,6 +3,7 @@ NXT_LIB =   nxt
 
 
 $(NXT_BUILDDIR)/libnxt.a: \
+   $(NXT_LIB)/nxt_auto_config.h \
$(NXT_BUILDDIR)/nxt_djb_hash.o \
$(NXT_BUILDDIR)/nxt_utf8.o \
$(NXT_BUILDDIR)/nxt_array.o \
diff -r adfb758ad872 -r 86c35adbd3f9 nxt/auto/configure
--- a/nxt/auto/configureWed Nov 30 14:10:49 2016 +0300
+++ b/nxt/auto/configureWed Nov 30 14:53:15 2016 +0300
@@ -55,10 +55,3 @@ END
 . ${NXT_AUTO}memalign
 . ${NXT_AUTO}getrandom
 . ${NXT_AUTO}pcre
-
-
-cat << END >> $NXT_MAKEFILE_CONF
-
-target:main
-
-END
diff -r adfb758ad872 -r 86c35adbd3f9 nxt/test/Makefile
--- a/nxt/test/Makefile Wed Nov 30 14:10:49 2016 +0300
+++ b/nxt/test/Makefile Wed Nov 30 14:53:15 2016 +0300
@@ -1,5 +1,6 @@
 
 lib_test: \
+   $(NXT_LIB)/nxt_auto_config.h \
$(NXT_BUILDDIR)/random_unit_test \
$(NXT_BUILDDIR)/rbtree_unit_test \
$(NXT_BUILDDIR)/lvlhsh_unit_test \

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed nginx modules building introduced in 9b37882ad552.

2016-11-30 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/adfb758ad872
branches:  
changeset: 267:adfb758ad872
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Nov 30 14:10:49 2016 +0300
description:
Fixed nginx modules building introduced in 9b37882ad552.
Removed old third party module addition method.

diffstat:

 nginx/config |  4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diffs (23 lines):

diff -r fd2a05f9eacf -r adfb758ad872 nginx/config
--- a/nginx/config  Tue Nov 22 00:06:46 2016 +0300
+++ b/nginx/config  Wed Nov 30 14:10:49 2016 +0300
@@ -4,6 +4,7 @@ if [ $HTTP != NO ]; then
 ngx_module_type=HTTP
 ngx_module_name=ngx_http_js_module
 ngx_module_incs="$ngx_addon_dir/../nxt $ngx_addon_dir/../njs"
+ngx_module_deps="$ngx_addon_dir/../build/libnjs.a"
 ngx_module_srcs="$ngx_addon_dir/ngx_http_js_module.c"
 ngx_module_libs="PCRE $ngx_addon_dir/../build/libnjs.a -lm"
 
@@ -14,10 +15,9 @@ if [ $STREAM != NO ]; then
 ngx_module_type=STREAM
 ngx_module_name=ngx_stream_js_module
 ngx_module_incs="$ngx_addon_dir/../nxt $ngx_addon_dir/../njs"
+ngx_module_deps="$ngx_addon_dir/../build/libnjs.a"
 ngx_module_srcs="$ngx_addon_dir/ngx_stream_js_module.c"
 ngx_module_libs="PCRE $ngx_addon_dir/../build/libnjs.a -lm"
 
 . auto/module
 fi
-
-LINK_DEPS="$LINK_DEPS $ngx_addon_dir/../build/libnjs.a"

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Version 0.1.5.

2016-11-15 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/9c813c2bb2ac
branches:  
changeset: 255:9c813c2bb2ac
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Nov 15 18:28:18 2016 +0300
description:
Version 0.1.5.

diffstat:

 Makefile |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (10 lines):

diff -r d2ab98ea87ad -r 9c813c2bb2ac Makefile
--- a/Makefile  Tue Nov 15 17:43:05 2016 +0300
+++ b/Makefile  Tue Nov 15 18:28:18 2016 +0300
@@ -1,5 +1,5 @@
 
-NJS_VER =  0.1.4
+NJS_VER =  0.1.5
 
 NXT_LIB =  nxt
 

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Added tag 0.1.5 for changeset 9c813c2bb2ac

2016-11-15 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/9b9f46b55de2
branches:  
changeset: 256:9b9f46b55de2
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Nov 15 18:28:35 2016 +0300
description:
Added tag 0.1.5 for changeset 9c813c2bb2ac

diffstat:

 .hgtags |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (8 lines):

diff -r 9c813c2bb2ac -r 9b9f46b55de2 .hgtags
--- a/.hgtags   Tue Nov 15 18:28:18 2016 +0300
+++ b/.hgtags   Tue Nov 15 18:28:35 2016 +0300
@@ -3,3 +3,4 @@ 0039a747d25a3e08792c23c43b75768896724031
 5b066b4db54c17dc0a9a72948474f36957462e87 0.1.2
 360449773d51e7f451e5396e27021badc6b86085 0.1.3
 508689c1fb94c23f6b24be087c1dc63b2f9e6654 0.1.4
+9c813c2bb2acfd5b6e9d1e9b6699af928baea15a 0.1.5

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Native methods and non-constructor functions must throw

2016-11-15 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/d2ab98ea87ad
branches:  
changeset: 254:d2ab98ea87ad
user:  Igor Sysoev <i...@sysoev.ru>
date:  Tue Nov 15 17:43:05 2016 +0300
description:
Native methods and non-constructor functions must throw
TypeError exception if they are called as constructor.

diffstat:

 njs/njs_builtin.c|   1 +
 njs/njs_vm.c |  22 +-
 njs/njs_vm.h |  16 +++-
 njs/test/njs_unit_test.c |   6 ++
 4 files changed, 27 insertions(+), 18 deletions(-)

diffs (127 lines):

diff -r 91640c0405f4 -r d2ab98ea87ad njs/njs_builtin.c
--- a/njs/njs_builtin.c Fri Nov 11 18:12:13 2016 +0300
+++ b/njs/njs_builtin.c Tue Nov 15 17:43:05 2016 +0300
@@ -237,6 +237,7 @@ njs_builtin_objects_create(njs_vm_t *vm)
 for (i = NJS_CONSTRUCTOR_OBJECT; i < NJS_CONSTRUCTOR_MAX; i++) {
 constructors[i].object.shared = 0;
 constructors[i].native = 1;
+constructors[i].ctor = 1;
 constructors[i].args_offset = 1;
 constructors[i].u.native = native_constructors[i].native;
 constructors[i].args_types[0] = native_constructors[i].args_types[0];
diff -r 91640c0405f4 -r d2ab98ea87ad njs/njs_vm.c
--- a/njs/njs_vm.c  Fri Nov 11 18:12:13 2016 +0300
+++ b/njs/njs_vm.c  Tue Nov 15 17:43:05 2016 +0300
@@ -2152,6 +2152,7 @@ njs_ret_t
 njs_vmcode_function_frame(njs_vm_t *vm, njs_value_t *value, njs_value_t *nargs)
 {
 njs_ret_tret;
+nxt_bool_t   ctor;
 njs_value_t  val, *this;
 njs_object_t *object;
 njs_function_t   *function;
@@ -2160,13 +2161,17 @@ njs_vmcode_function_frame(njs_vm_t *vm, 
 if (nxt_fast_path(njs_is_function(value))) {
 
 func = (njs_vmcode_function_frame_t *) vm->current;
+ctor = func->code.ctor;
 
 function = value->data.u.function;
 
 if (function->native) {
+if (ctor && !function->ctor) {
+goto fail;
+}
+
 ret = njs_function_native_frame(vm, function, _value_void,
-NULL, (uintptr_t) nargs, 0,
-func->code.ctor);
+NULL, (uintptr_t) nargs, 0, ctor);
 
 if (nxt_fast_path(ret == NXT_OK)) {
 return sizeof(njs_vmcode_function_frame_t);
@@ -2175,7 +2180,7 @@ njs_vmcode_function_frame(njs_vm_t *vm, 
 return ret;
 }
 
-if (func->code.ctor) {
+if (ctor) {
 object = njs_function_new_object(vm, value);
 if (nxt_slow_path(object == NULL)) {
 return NXT_ERROR;
@@ -2191,7 +2196,7 @@ njs_vmcode_function_frame(njs_vm_t *vm, 
 }
 
 ret = njs_function_frame(vm, function, this, NULL, (uintptr_t) nargs,
- func->code.ctor);
+ ctor);
 
 if (nxt_fast_path(ret == NXT_OK)) {
 return sizeof(njs_vmcode_function_frame_t);
@@ -2200,6 +2205,8 @@ njs_vmcode_function_frame(njs_vm_t *vm, 
 return ret;
 }
 
+fail:
+
 vm->exception = _exception_type_error;
 
 return NXT_ERROR;
@@ -2329,8 +2336,13 @@ njs_vmcode_method_call(njs_vm_t *vm, njs
 return ret;
 }
 
+if (method->code.ctor) {
+vm->exception = _exception_type_error;
+return NXT_ERROR;
+}
+
 ret = njs_function_native_frame(vm, function, object, NULL, method->nargs,
-0, method->code.ctor);
+0, 0);
 
 if (nxt_fast_path(ret == NXT_OK)) {
 njs_retain(object);
diff -r 91640c0405f4 -r d2ab98ea87ad njs/njs_vm.h
--- a/njs/njs_vm.h  Fri Nov 11 18:12:13 2016 +0300
+++ b/njs/njs_vm.h  Tue Nov 15 17:43:05 2016 +0300
@@ -230,20 +230,10 @@ struct njs_function_s {
 
 uint8_t   args_types[NJS_ARGS_TYPES_MAX];
 uint8_t   args_offset;
-
-/*
- * TODO Shared
- * When function object is used as value: in assignments,
- * as function argument, as property and as object to get properties.
- */
+uint8_t   continuation_size;
 
-#if (NXT_64BIT)
-uint8_t   native;
-uint8_t   continuation_size;
-#else
-uint8_t   native;
-uint8_t   continuation_size;
-#endif
+uint8_t   native:1;
+uint8_t   ctor:1;
 
 union {
 njs_function_lambda_t *lambda;
diff -r 91640c0405f4 -r d2ab98ea87ad njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Fri Nov 11 18:12:13 2016 +0300
+++ b/njs/test/njs_unit_test.c  Tue Nov 15 17:43:05 2016 +0300
@@ -4223,6 +4223,12 @@ static njs_unit_test_t  njs_test[] =

[njs] Removed irrelevant overhead in clone/destroy benchmark.

2016-11-11 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/91640c0405f4
branches:  
changeset: 253:91640c0405f4
user:  Igor Sysoev <i...@sysoev.ru>
date:  Fri Nov 11 18:12:13 2016 +0300
description:
Removed irrelevant overhead in clone/destroy benchmark.

diffstat:

 njs/test/njs_unit_test.c |  4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diffs (14 lines):

diff -r 9f66db825663 -r 91640c0405f4 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Fri Nov 11 17:28:47 2016 +0300
+++ b/njs/test/njs_unit_test.c  Fri Nov 11 18:12:13 2016 +0300
@@ -6198,8 +6198,8 @@ main(int argc, char **argv)
 {
 nxt_bool_t  disassemble;
 
-static nxt_str_t  script = nxt_string("1");
-static nxt_str_t  result = nxt_string("1");
+static nxt_str_t  script = nxt_string("null");
+static nxt_str_t  result = nxt_string("null");
 
 static nxt_str_t  fibo_number = nxt_string(
 "function fibo(n) {"

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Now the empty regexp pattern is created on compile stage only.

2016-11-11 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/9f66db825663
branches:  
changeset: 252:9f66db825663
user:  Igor Sysoev <i...@sysoev.ru>
date:  Fri Nov 11 17:28:47 2016 +0300
description:
Now the empty regexp pattern is created on compile stage only.

This speeds up njs_vm_clone() operation twice.

diffstat:

 njs/njs_builtin.c |   2 +-
 njs/njs_regexp.c  |  31 +++
 njs/njs_string.c  |  23 ++-
 njs/njs_vm.h  |   3 ++-
 njs/njscript.c|  13 +++--
 5 files changed, 43 insertions(+), 29 deletions(-)

diffs (164 lines):

diff -r 0939df226d5c -r 9f66db825663 njs/njs_builtin.c
--- a/njs/njs_builtin.c Thu Nov 10 19:09:13 2016 +0300
+++ b/njs/njs_builtin.c Fri Nov 11 17:28:47 2016 +0300
@@ -230,7 +230,7 @@ njs_builtin_objects_create(njs_vm_t *vm)
 }
 
 prototypes[NJS_PROTOTYPE_REGEXP].regexp.pattern =
- vm->empty_regexp.data.u.regexp->pattern;
+  vm->shared->empty_regexp_pattern;
 
 constructors = vm->shared->constructors;
 
diff -r 0939df226d5c -r 9f66db825663 njs/njs_regexp.c
--- a/njs/njs_regexp.c  Thu Nov 10 19:09:13 2016 +0300
+++ b/njs/njs_regexp.c  Fri Nov 11 17:28:47 2016 +0300
@@ -65,8 +65,7 @@ njs_regexp_init(njs_vm_t *vm)
 
 vm->regex_context->trace = >trace;
 
-return njs_regexp_create(vm, >empty_regexp, (u_char *) "(?:)",
- sizeof("(?:)") - 1, 0);
+return NXT_OK;
 }
 
 
@@ -128,25 +127,25 @@ njs_regexp_create(njs_vm_t *vm, njs_valu
 
 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;
-}
+if (nxt_slow_path(pattern == NULL)) {
+return NXT_ERROR;
 }
 
-return NXT_ERROR;
+} else {
+pattern = vm->shared->empty_regexp_pattern;
 }
 
-*value = vm->empty_regexp;
+regexp = njs_regexp_alloc(vm, pattern);
 
-return NXT_OK;
+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;
 }
 
 
diff -r 0939df226d5c -r 9f66db825663 njs/njs_string.c
--- a/njs/njs_string.c  Thu Nov 10 19:09:13 2016 +0300
+++ b/njs/njs_string.c  Fri Nov 11 17:28:47 2016 +0300
@@ -1946,9 +1946,11 @@ njs_string_prototype_match(njs_vm_t *vm,
 njs_string_prop_t string;
 njs_regexp_pattern_t  *pattern;
 
-arguments[0] = vm->empty_regexp;
 arguments[1] = args[0];
 
+string.start = NULL;
+string.size = 0;
+
 if (nargs > 1) {
 
 if (njs_is_regexp([1])) {
@@ -1964,21 +1966,24 @@ njs_string_prototype_match(njs_vm_t *vm,
  */
 arguments[0] = args[1];
 
-} else if (njs_is_string([1])) {
+goto match;
+}
+
+if (njs_is_string([1])) {
 /* string1.match(string2) is the same as /string2/.exec(string1). 
*/
-
 (void) njs_string_prop(, [1]);
-
-ret = njs_regexp_create(vm, [0], string.start,
-string.size, 0);
-if (nxt_slow_path(ret != NXT_OK)) {
-return ret;
-}
 }
 
 /* A void value. */
 }
 
+ret = njs_regexp_create(vm, [0], string.start, string.size, 0);
+if (nxt_slow_path(ret != NXT_OK)) {
+return ret;
+}
+
+match:
+
 return njs_regexp_prototype_exec(vm, arguments, nargs, unused);
 }
 
diff -r 0939df226d5c -r 9f66db825663 njs/njs_vm.h
--- a/njs/njs_vm.h  Thu Nov 10 19:09:13 2016 +0300
+++ b/njs/njs_vm.h  Fri Nov 11 17:28:47 2016 +0300
@@ -845,7 +845,6 @@ struct njs_vm_s {
 
 nxt_regex_context_t  *regex_context;
 nxt_regex_match_data_t   *single_match_data;
-njs_value_t  empty_regexp;
 
 nxt_array_t  *code;  /* of njs_vm_code_t */
 
@@ -875,6 +874,8 @@ struct njs_vm_shared_s {
  */
 njs_object_prototype_t   prototypes[NJS_PROTOTYPE_MAX];
 njs_function_t   constructors[NJS_CONSTRUCTOR_MAX];
+
+njs_regexp_pattern_t *empty_regexp_pattern;
 };
 
 
diff -r 0939df226d5c -r 9f66db825663 njs/njscript.c
--- a/njs/njscript.cThu Nov 10 19:09:13 2016 +0300
+++ b/njs/njscript.cFri Nov 11 17:28:47 2016 +0300
@@ -102,8 +102,9 @@ njs_vm_t *
 njs_vm_create(nxt_mem_cache_pool_t *mcp, njs_vm_shared_t **shared,
 nxt_lvlhsh_t *externals)
 {
-njs_vm_t   *vm;
-nxt_int_t  ret;
+njs_vm_t  *vm;
+nxt_int_t ret;
+njs_regexp_pattern_t  *pattern;
 

[njs] Style and small miscellaneous fixes.

2016-11-09 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/7a42d1e83ae2
branches:  
changeset: 245:7a42d1e83ae2
user:  Igor Sysoev <i...@sysoev.ru>
date:  Wed Nov 09 15:04:40 2016 +0300
description:
Style and small miscellaneous fixes.

diffstat:

 njs/njs_disassembler.c  |   2 +-
 njs/njs_string.c|   3 +--
 njs/njs_vm.c|  14 +++---
 njs/njs_vm.h|   3 ++-
 njs/test/njs_unit_test.c|   3 ++-
 nxt/nxt_rbtree.c|  11 +++
 nxt/nxt_utf8.h  |   1 -
 nxt/test/random_unit_test.c |   2 +-
 8 files changed, 17 insertions(+), 22 deletions(-)

diffs (157 lines):

diff -r c8862eb2eb94 -r 7a42d1e83ae2 njs/njs_disassembler.c
--- a/njs/njs_disassembler.cWed Nov 09 14:34:32 2016 +0300
+++ b/njs/njs_disassembler.cWed Nov 09 15:04:40 2016 +0300
@@ -151,7 +151,7 @@ njs_disassembler(njs_vm_t *vm)
 code = vm->code->start;
 n = vm->code->items;
 
-while(n != 0) {
+while (n != 0) {
 njs_disassemble(code->start, code->end);
 code++;
 n--;
diff -r c8862eb2eb94 -r 7a42d1e83ae2 njs/njs_string.c
--- a/njs/njs_string.c  Wed Nov 09 14:34:32 2016 +0300
+++ b/njs/njs_string.c  Wed Nov 09 15:04:40 2016 +0300
@@ -607,7 +607,6 @@ njs_string_prototype_concat(njs_vm_t *vm
 }
 
 for (i = 0; i < nargs; i++) {
-
 if (!njs_is_string([i])) {
 vm->frame->trap_scratch.data.u.value = [i];
 
@@ -3210,7 +3209,7 @@ static const njs_object_prop_t  njs_stri
 .type = NJS_METHOD,
 .name = njs_string("match"),
 .value = njs_native_function(njs_string_prototype_match, 0,
- NJS_STRING_ARG, NJS_REGEXP_ARG),
+ NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG),
 },
 
 {
diff -r c8862eb2eb94 -r 7a42d1e83ae2 njs/njs_vm.c
--- a/njs/njs_vm.c  Wed Nov 09 14:34:32 2016 +0300
+++ b/njs/njs_vm.c  Wed Nov 09 15:04:40 2016 +0300
@@ -79,10 +79,10 @@ static njs_ret_t njs_object_property_que
 static njs_ret_t njs_method_private_copy(njs_vm_t *vm,
 njs_property_query_t *pq);
 static nxt_noinline uint32_t njs_integer_value(double num);
-static nxt_noinline njs_ret_t njs_values_equal(njs_value_t *val1,
-njs_value_t *val2);
-static nxt_noinline njs_ret_t njs_values_compare(njs_value_t *val1,
-njs_value_t *val2);
+static nxt_noinline njs_ret_t njs_values_equal(const njs_value_t *val1,
+const njs_value_t *val2);
+static nxt_noinline njs_ret_t njs_values_compare(const njs_value_t *val1,
+const njs_value_t *val2);
 static njs_object_t *njs_function_new_object(njs_vm_t *vm, njs_value_t *value);
 static njs_ret_t njs_vmcode_method_call(njs_vm_t *vm, njs_value_t *object,
 njs_value_t *value);
@@ -1879,7 +1879,7 @@ njs_vmcode_not_equal(njs_vm_t *vm, njs_v
 
 
 static nxt_noinline njs_ret_t
-njs_values_equal(njs_value_t *val1, njs_value_t *val2)
+njs_values_equal(const njs_value_t *val1, const njs_value_t *val2)
 {
 /* Void and null are equal and not comparable with anything else. */
 if (njs_is_null_or_void(val1)) {
@@ -1967,7 +1967,7 @@ njs_vmcode_greater_or_equal(njs_vm_t *vm
  */
 
 static nxt_noinline njs_ret_t
-njs_values_compare(njs_value_t *val1, njs_value_t *val2)
+njs_values_compare(const njs_value_t *val1, const njs_value_t *val2)
 {
 if (nxt_fast_path(njs_is_numeric(val1) || njs_is_numeric(val2))) {
 
@@ -2030,7 +2030,7 @@ njs_vmcode_strict_not_equal(njs_vm_t *vm
 
 
 nxt_noinline nxt_bool_t
-njs_values_strict_equal(njs_value_t *val1, njs_value_t *val2)
+njs_values_strict_equal(const njs_value_t *val1, const njs_value_t *val2)
 {
 size_tsize;
 const u_char  *start1, *start2;
diff -r c8862eb2eb94 -r 7a42d1e83ae2 njs/njs_vm.h
--- a/njs/njs_vm.h  Wed Nov 09 14:34:32 2016 +0300
+++ b/njs/njs_vm.h  Wed Nov 09 15:04:40 2016 +0300
@@ -1007,7 +1007,8 @@ njs_ret_t njs_vmcode_catch(njs_vm_t *vm,
 njs_ret_t njs_vmcode_finally(njs_vm_t *vm, njs_value_t *invld,
 njs_value_t *retval);
 
-nxt_bool_t njs_values_strict_equal(njs_value_t *val1, njs_value_t *val2);
+nxt_bool_t njs_values_strict_equal(const njs_value_t *val1,
+const njs_value_t *val2);
 
 njs_ret_t njs_normalize_args(njs_vm_t *vm, njs_value_t *args,
 uint8_t *args_types, nxt_uint_t nargs);
diff -r c8862eb2eb94 -r 7a42d1e83ae2 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Wed Nov 09 14:34:32 2016 +0300
+++ b/njs/test/njs_unit_test.c  Wed Nov 09 15:04:40 2016 +0300
@@ -6218,10 +6218,11 @@ main(int argc, char **argv)
 "fibo(32).length");
 
 static nxt_str_t  fibo_bytes = nxt_string(
+"var a = '\\x80'.toBytes();"
 "function fibo(n) {"
 "if (n > 1)"
 "return fibo(n - 1) + fibo(n - 2)"
-"return '\\x80'.toBytes()"
+"return a"
 "}"
 "fibo(32).length");
 
diff -r c8862eb2eb94 -r 7a42d1e83ae2 nxt/n

[njs] Function expressions did not have prototypes.

2016-11-04 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/53d2024f6ca3
branches:  
changeset: 239:53d2024f6ca3
user:  Igor Sysoev <i...@sysoev.ru>
date:  Fri Nov 04 23:45:35 2016 +0300
description:
Function expressions did not have prototypes.

diffstat:

 njs/njs_vm.c |   1 +
 njs/test/njs_unit_test.c |  11 +++
 2 files changed, 12 insertions(+), 0 deletions(-)

diffs (32 lines):

diff -r 109932e1d3c8 -r 53d2024f6ca3 njs/njs_vm.c
--- a/njs/njs_vm.c  Fri Nov 04 18:25:55 2016 +0300
+++ b/njs/njs_vm.c  Fri Nov 04 23:45:35 2016 +0300
@@ -414,6 +414,7 @@ njs_vmcode_function(njs_vm_t *vm, njs_va
 function = nxt_mem_cache_zalloc(vm->mem_cache_pool, 
sizeof(njs_function_t));
 
 if (nxt_fast_path(function != NULL)) {
+function->object.shared_hash = vm->shared->function_prototype_hash;
 function->object.__proto__ =
 >prototypes[NJS_PROTOTYPE_FUNCTION].object;
 function->args_offset = 1;
diff -r 109932e1d3c8 -r 53d2024f6ca3 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Fri Nov 04 18:25:55 2016 +0300
+++ b/njs/test/njs_unit_test.c  Fri Nov 04 23:45:35 2016 +0300
@@ -4167,6 +4167,17 @@ static njs_unit_test_t  njs_test[] =
  "o.constructor === F"),
   nxt_string("true") },
 
+{ nxt_string("function F() { return }"
+ "var o = new F();"
+ "o.__proto__ === F.prototype"),
+  nxt_string("true") },
+
+{ nxt_string("function F(){}; typeof F.prototype"),
+  nxt_string("object") },
+
+{ nxt_string("var F = function (){}; typeof F.prototype"),
+  nxt_string("object") },
+
 { nxt_string("function F() { return Number }"
  "var o = new (F())(5);"
  "typeof o +' '+ o"),

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] String.prototype.repeat() did not check the count parameter

2016-11-04 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/e16086a85f0b
branches:  
changeset: 235:e16086a85f0b
user:  Igor Sysoev <i...@sysoev.ru>
date:  Fri Nov 04 16:22:56 2016 +0300
description:
String.prototype.repeat() did not check the count parameter
for single character strings.  The count parameter should be
checked also for empty string.

In collaboration with Andrey Zelenkov and Valentin Bartenev.

diffstat:

 njs/njs_string.c |  22 --
 njs/test/njs_unit_test.c |  31 +++
 2 files changed, 43 insertions(+), 10 deletions(-)

diffs (78 lines):

diff -r ff8f717db1be -r e16086a85f0b njs/njs_string.c
--- a/njs/njs_string.c  Thu Nov 03 18:12:10 2016 +0300
+++ b/njs/njs_string.c  Fri Nov 04 16:22:56 2016 +0300
@@ -1756,21 +1756,23 @@ njs_string_prototype_repeat(njs_vm_t *vm
 
 (void) njs_string_prop(, [0]);
 
+if (nargs > 1) {
+max = (string.size > 1) ? NJS_STRING_MAX_LENGTH / string.size
+: NJS_STRING_MAX_LENGTH;
+
+n = args[1].data.u.number;
+
+if (nxt_slow_path(n < 0 || n >= max)) {
+vm->exception = _exception_range_error;
+return NXT_ERROR;
+}
+}
+
 if (string.size == 0) {
 vm->retval = njs_string_empty;
 return NXT_OK;
 }
 
-if (nargs > 1) {
-max = NJS_STRING_MAX_LENGTH / string.size;
-n = args[1].data.u.number;
-
-if (nxt_slow_path(n < 0 || n > max)) {
-vm->exception = _exception_range_error;
-return NXT_ERROR;
-}
-}
-
 size = string.size * n;
 length = string.length * n;
 
diff -r ff8f717db1be -r e16086a85f0b njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Thu Nov 03 18:12:10 2016 +0300
+++ b/njs/test/njs_unit_test.c  Fri Nov 04 16:22:56 2016 +0300
@@ -3633,6 +3633,37 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("'abc'.repeat(-1)"),
   nxt_string("RangeError") },
 
+{ nxt_string("''.repeat(-1)"),
+  nxt_string("RangeError") },
+
+{ nxt_string("'a'.repeat(2147483647)"),
+  nxt_string("RangeError") },
+
+{ nxt_string("'a'.repeat(2147483648)"),
+  nxt_string("RangeError") },
+
+{ nxt_string("'a'.repeat(Infinity)"),
+  nxt_string("RangeError") },
+
+{ nxt_string("'a'.repeat(NaN)"),
+  nxt_string("") },
+
+{ nxt_string("''.repeat(2147483646)"),
+  nxt_string("") },
+
+/* ES6: "". */
+{ nxt_string("''.repeat(2147483647)"),
+  nxt_string("RangeError") },
+
+{ nxt_string("''.repeat(2147483648)"),
+  nxt_string("RangeError") },
+
+{ nxt_string("''.repeat(Infinity)"),
+  nxt_string("RangeError") },
+
+{ nxt_string("''.repeat(NaN)"),
+  nxt_string("") },
+
 { nxt_string("encodeURI()"),
   nxt_string("undefined")},
 

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] A possible memory leak has been fixed.

2016-10-31 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/f0ac27f59e58
branches:  
changeset: 230:f0ac27f59e58
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon Oct 31 15:51:12 2016 +0300
description:
A possible memory leak has been fixed.

Thanks to ??? (Hong Zhi Dao).

diffstat:

 nxt/nxt_mem_cache_pool.c |  3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diffs (19 lines):

diff -r a1cd4104df67 -r f0ac27f59e58 nxt/nxt_mem_cache_pool.c
--- a/nxt/nxt_mem_cache_pool.c  Sat Oct 29 00:04:29 2016 +0300
+++ b/nxt/nxt_mem_cache_pool.c  Mon Oct 31 15:51:12 2016 +0300
@@ -574,14 +574,13 @@ nxt_mem_cache_alloc_large(nxt_mem_cache_
 
 } else {
 block = pool->proto->alloc(pool->mem, sizeof(nxt_mem_cache_block_t));
-
 if (nxt_slow_path(block == NULL)) {
-pool->proto->free(pool->mem, block);
 return NULL;
 }
 
 p = pool->proto->align(pool->mem, alignment, size);
 if (nxt_slow_path(p == NULL)) {
+pool->proto->free(pool->mem, block);
 return NULL;
 }
 

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] A surplus check has been removed.

2016-10-31 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/b0b46036d54e
branches:  
changeset: 231:b0b46036d54e
user:  Igor Sysoev <i...@sysoev.ru>
date:  Mon Oct 31 15:56:49 2016 +0300
description:
A surplus check has been removed.

Found by Coverity Scan.

diffstat:

 njs/njscript.c |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r f0ac27f59e58 -r b0b46036d54e njs/njscript.c
--- a/njs/njscript.cMon Oct 31 15:51:12 2016 +0300
+++ b/njs/njscript.cMon Oct 31 15:56:49 2016 +0300
@@ -346,7 +346,7 @@ njs_vm_clone(njs_vm_t *vm, nxt_mem_cache
 
 fail:
 
-if (mcp == NULL && nmcp != NULL) {
+if (mcp == NULL) {
 nxt_mem_cache_pool_destroy(nmcp);
 }
 

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed building on modern Linux kernels.

2016-10-28 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/a1cd4104df67
branches:  
changeset: 229:a1cd4104df67
user:  Igor Sysoev <i...@sysoev.ru>
date:  Sat Oct 29 00:04:29 2016 +0300
description:
Fixed building on modern Linux kernels.

diffstat:

 nxt/nxt_random.c |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r 9b37882ad552 -r a1cd4104df67 nxt/nxt_random.c
--- a/nxt/nxt_random.c  Fri Oct 28 19:29:38 2016 +0300
+++ b/nxt/nxt_random.c  Sat Oct 29 00:04:29 2016 +0300
@@ -70,7 +70,7 @@ nxt_random_stir(nxt_random_t *r, nxt_pid
 
 /* Linux 3.17 getrandom(), it is not available in Glibc. */
 
-n = syscall(SYS_getrandom, key, NXT_RANDOM_KEY_SIZE, 0));
+n = syscall(SYS_getrandom, key, NXT_RANDOM_KEY_SIZE, 0);
 
 #endif
 

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] String.prototype.trim() method.

2016-10-28 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/5de122a4031a
branches:  
changeset: 226:5de122a4031a
user:  Igor Sysoev <i...@sysoev.ru>
date:  Fri Oct 28 13:32:33 2016 +0300
description:
String.prototype.trim() method.

In collaboration with Valentin Bartenev.

diffstat:

 njs/njs_string.c |  136 +++
 njs/test/njs_unit_test.c |   30 ++
 2 files changed, 166 insertions(+), 0 deletions(-)

diffs (193 lines):

diff -r d84e34c2dbde -r 5de122a4031a njs/njs_string.c
--- a/njs/njs_string.c  Thu Oct 27 16:38:05 2016 +0300
+++ b/njs/njs_string.c  Fri Oct 28 13:32:33 2016 +0300
@@ -1614,6 +1614,135 @@ njs_string_prototype_to_upper_case(njs_v
 }
 
 
+static njs_ret_t
+njs_string_prototype_trim(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+njs_index_t unused)
+{
+uint32_t   u, trim, length;
+const u_char   *p, *prev, *start, *end;
+njs_string_prop_t  string;
+
+trim = 0;
+
+njs_string_prop(, [0]);
+
+p = string.start;
+end = string.start + string.size;
+
+if (string.length == 0 || string.length == string.size) {
+/* Byte or ASCII string. */
+
+while (p < end) {
+
+switch (*p) {
+case 0x09:  /*   */
+case 0x0A:  /**/
+case 0x0B:  /**/
+case 0x0C:  /**/
+case 0x0D:  /**/
+case 0x20:  /**/
+case 0xA0:  /*  */
+trim++;
+p++;
+continue;
+
+default:
+start = p;
+p = end;
+
+for ( ;; ) {
+p--;
+
+switch (*p) {
+case 0x09:  /*   */
+case 0x0A:  /**/
+case 0x0B:  /**/
+case 0x0C:  /**/
+case 0x0D:  /**/
+case 0x20:  /**/
+case 0xA0:  /*  */
+trim++;
+continue;
+
+default:
+p++;
+goto done;
+}
+}
+}
+}
+
+} else {
+/* UTF-8 string. */
+
+while (p < end) {
+prev = p;
+u = nxt_utf8_decode(, end);
+
+switch (u) {
+case 0x0009:  /*   */
+case 0x000A:  /**/
+case 0x000B:  /**/
+case 0x000C:  /**/
+case 0x000D:  /**/
+case 0x0020:  /**/
+case 0x00A0:  /*  */
+case 0x2028:  /**/
+case 0x2029:  /**/
+case 0xFEFF:  /*   */
+trim++;
+continue;
+
+default:
+start = prev;
+prev = end;
+
+for ( ;; ) {
+prev = nxt_utf8_prev(prev);
+p = prev;
+u = nxt_utf8_decode(, end);
+
+switch (u) {
+case 0x0009:  /*   */
+case 0x000A:  /**/
+case 0x000B:  /**/
+case 0x000C:  /**/
+case 0x000D:  /**/
+case 0x0020:  /**/
+case 0x00A0:  /*  */
+case 0x2028:  /**/
+case 0x2029:  /**/
+case 0xFEFF:  /*   */
+trim++;
+continue;
+
+default:
+goto done;
+}
+}
+}
+}
+}
+
+vm->retval = njs_string_empty;
+
+return NXT_OK;
+
+done:
+
+if (trim == 0) {
+/* GC: retain. */
+vm->retval = args[0];
+
+return NXT_OK;
+}
+
+length = (string.length != 0) ? string.length - trim : 0;
+
+return njs_string_new(vm, >retval, start, p - start, length);
+}
+
+
 /*
  * String.search([regexp])
  */
@@ -2908,6 +3037,13 @@ static const njs_object_prop_t  njs_stri
 
 {
 .type = NJS_METHOD,
+.name = njs_string("trim"),
+.value = njs_native_function(njs_string_prototype_trim, 0,
+ NJS_STRING_OBJECT_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 d84e34c2dbde -r 5de122a4031a njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Thu Oct 27 16:38:05 2016 +0300
+++ b/njs/test/njs_unit_test.c  Fri Oct 28 13:32:33 2016 +0300
@@ -3326,6 +3326,36 @@ static njs_unit_test_t  njs_test[] =
  "} a"),
   nxt_string("304,453,456,459,498,1012,7838,8486,8490,8491") },
 
+{ nxt_string(&qu

[njs] String.prototype.lastIndexOf() method fix.

2016-10-27 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/d84e34c2dbde
branches:  
changeset: 225:d84e34c2dbde
user:  Igor Sysoev <i...@sysoev.ru>
date:  Thu Oct 27 16:38:05 2016 +0300
description:
String.prototype.lastIndexOf() method fix.

In collaboration with Valentin Bartenev.

diffstat:

 njs/njs_string.c |  24 +---
 1 files changed, 13 insertions(+), 11 deletions(-)

diffs (63 lines):

diff -r 86fd59307356 -r d84e34c2dbde njs/njs_string.c
--- a/njs/njs_string.c  Thu Oct 27 11:14:46 2016 +0300
+++ b/njs/njs_string.c  Thu Oct 27 16:38:05 2016 +0300
@@ -1290,12 +1290,14 @@ njs_string_prototype_last_index_of(njs_v
 const u_char   *p, *end;
 njs_string_prop_t  string, search;
 
+index = -1;
+
 if (nargs > 1) {
 length = njs_string_prop(, [0]);
 search_length = njs_string_prop(, [1]);
 
 if (length < search_length) {
-goto small;
+goto done;
 }
 
 index = NJS_STRING_MAX_LENGTH;
@@ -1328,10 +1330,10 @@ njs_string_prototype_last_index_of(njs_v
 goto done;
 }
 
-p--;
 index--;
-
-} while (index >= 0);
+p--;
+
+} while (p >= string.start);
 
 } else {
 /* UTF-8 string. */
@@ -1345,22 +1347,22 @@ njs_string_prototype_last_index_of(njs_v
 p = nxt_utf8_prev(p);
 }
 
-do {
+for ( ;; ) {
 if (memcmp(p, search.start, search.size) == 0) {
 goto done;
 }
 
-p = nxt_utf8_prev(p);
 index--;
 
-} while (index >= 0);
+if (p <= string.start) {
+break;
+}
+
+p = nxt_utf8_prev(p);
+}
 }
 }
 
-small:
-
-index = -1;
-
 done:
 
 njs_number_set(>retval, index);

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] String.prototype.lastIndexOf() method fixes and optimizati...

2016-10-27 Thread Igor Sysoev
details:   http://hg.nginx.org/njs/rev/da63e61ecef4
branches:  
changeset: 223:da63e61ecef4
user:  Igor Sysoev <i...@sysoev.ru>
date:  Thu Oct 27 10:56:54 2016 +0300
description:
String.prototype.lastIndexOf() method fixes and optimizations.

In collaboration with Valentin Bartenev.

diffstat:

 njs/njs_string.c |  129 ++
 njs/test/njs_unit_test.c |   41 ++-
 nxt/nxt_utf8.h   |   27 -
 3 files changed, 123 insertions(+), 74 deletions(-)

diffs (274 lines):

diff -r 74785cebd8df -r da63e61ecef4 njs/njs_string.c
--- a/njs/njs_string.c  Thu Oct 27 10:47:48 2016 +0300
+++ b/njs/njs_string.c  Thu Oct 27 10:56:54 2016 +0300
@@ -83,8 +83,6 @@ static nxt_noinline void njs_string_slic
 njs_value_t *args, nxt_uint_t nargs);
 static njs_ret_t njs_string_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);
 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,
@@ -1288,91 +1286,86 @@ static njs_ret_t
 njs_string_prototype_last_index_of(njs_vm_t *vm, njs_value_t *args,
 nxt_uint_t nargs, njs_index_t unused)
 {
-ssize_t  ret, index, last;
-
-index = -1;
-
-if (nargs > 1) {
-last = NJS_STRING_MAX_LENGTH;
-
-if (nargs > 2) {
-last = args[2].data.u.number;
-
-if (last < 0) {
-last = 0;
-}
-}
-
-ret = 0;
-
-for ( ;; ) {
-ret = njs_string_index_of(vm, [0], [1], ret);
-
-if (ret < 0 || ret >= last) {
-break;
-}
-
-index = ret++;
-}
-}
-
-njs_number_set(>retval, index);
-
-return NXT_OK;
-}
-
-
-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)
-{
-size_t length;
+ssize_tindex, start, length, search_length;
 const u_char   *p, *end;
 njs_string_prop_t  string, search;
 
-(void) njs_string_prop(, search_string);
-
-length = njs_string_prop(, src);
-
-if (index < length) {
-
-if (string.size == length) {
+if (nargs > 1) {
+length = njs_string_prop(, [0]);
+search_length = njs_string_prop(, [1]);
+
+if (length < search_length) {
+goto small;
+}
+
+index = NJS_STRING_MAX_LENGTH;
+
+if (nargs > 2) {
+index = args[2].data.u.number;
+
+if (index < 0) {
+index = 0;
+}
+}
+
+if (index > length) {
+index = length;
+}
+
+if (string.size == (size_t) length) {
 /* Byte or ASCII string. */
+
+start = length - search.size;
+
+if (index > start) {
+index = start;
+}
+
 p = string.start + index;
-end = (string.start + string.size) - (search.size - 1);
-
-while (p < end) {
+
+do {
 if (memcmp(p, search.start, search.size) == 0) {
-return index;
+goto done;
 }
 
-index++;
-p++;
-}
+p--;
+index--;
+
+} while (index >= 0);
 
 } else {
 /* UTF-8 string. */
+
 end = string.start + string.size;
-
 p = njs_string_offset(string.start, end, index);
-
-end -= search.size - 1;
-
-while (p < end) {
+end -= search.size;
+
+while (p > end) {
+index--;
+p = nxt_utf8_prev(p);
+}
+
+do {
 if (memcmp(p, search.start, search.size) == 0) {
-return index;
+goto done;
 }
 
-index++;
-p = nxt_utf8_next(p, end);
-}
+p = nxt_utf8_prev(p);
+index--;
+
+} while (index >= 0);
 }
-
-} else if (search.size == 0) {
-return length;
 }
 
-return -1;
+small:
+
+index = -1;
+
+done:
+
+njs_number_set(>retval, index);
+
+return NXT_OK;
 }
 
 
diff -r 74785cebd8df -r da63e61ecef4 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Thu Oct 27 10:47:48 2016 +0300
+++ b/njs/test/njs_unit_test.c  Thu Oct 27 10:56:54 2016 +0300
@@ -3224,6 +3224,9 @@ static njs_unit_test_t  njs_test[] =
 { nxt_string("''.indexOf.call(12345, 45, '0')"),
   nxt_string("3") },
 
+{ nxt_string("'abc'.lastIndexOf('abcdef

  1   2   3   >