[njs] Fixed function value initialization.

Dmitry Volyntsev xeioex at nginx.com
Thu Jun 2 04:55:48 UTC 2022


details:   https://hg.nginx.org/njs/rev/ddec2f61c6d4
branches:  
changeset: 1872:ddec2f61c6d4
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Jun 01 21:54:32 2022 -0700
description:
Fixed function value initialization.

This closes #470 issue on Github.

diffstat:

 src/njs_vmcode.c         |  6 +++---
 src/test/njs_unit_test.c |  6 ++++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diffs (34 lines):

diff -r 2774fed7b864 -r ddec2f61c6d4 src/njs_vmcode.c
--- a/src/njs_vmcode.c	Tue May 31 21:48:46 2022 -0700
+++ b/src/njs_vmcode.c	Wed Jun 01 21:54:32 2022 -0700
@@ -1259,9 +1259,9 @@ njs_vmcode_function_copy(njs_vm_t *vm, n
     njs_value_t     *retval;
     njs_function_t  *function;
 
-    retval = njs_scope_valid_value(vm, retidx);
-
-    if (njs_is_undefined(retval)) {
+    retval = njs_scope_value(vm, retidx);
+
+    if (!njs_is_valid(retval)) {
         *retval = *value;
 
         function = njs_function_value_copy(vm, retval);
diff -r 2774fed7b864 -r ddec2f61c6d4 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Tue May 31 21:48:46 2022 -0700
+++ b/src/test/njs_unit_test.c	Wed Jun 01 21:54:32 2022 -0700
@@ -10200,10 +10200,12 @@ static njs_unit_test_t  njs_test[] =
                  "c()()()"),
       njs_str("1") },
 
-#if 0
     { njs_str("function f() {}; f += 1; f"),
       njs_str("[object Function]1") },
-#endif
+
+    { njs_str("function f() { function g() { g = undefined; }; g(); g(); };"
+              "f()"),
+      njs_str("TypeError: undefined is not a function") },
 
     { njs_str("function f() {}; function g() { return f }; g()"),
       njs_str("[object Function]") },



More information about the nginx-devel mailing list