]> git.kaiwu.me - njs.git/commitdiff
Fixed function value initialization.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 2 Jun 2022 04:54:32 +0000 (21:54 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 2 Jun 2022 04:54:32 +0000 (21:54 -0700)
This closes #470 issue on Github.

src/njs_vmcode.c
src/test/njs_unit_test.c

index ae1d1bb4f7e20810e886e4ec1f8c6463d6096d4a..9833ada03073b7bad9e71c9cda4e8d45a1be5254 100644 (file)
@@ -1259,9 +1259,9 @@ njs_vmcode_function_copy(njs_vm_t *vm, njs_value_t *value, njs_index_t retidx)
     njs_value_t     *retval;
     njs_function_t  *function;
 
-    retval = njs_scope_valid_value(vm, retidx);
+    retval = njs_scope_value(vm, retidx);
 
-    if (njs_is_undefined(retval)) {
+    if (!njs_is_valid(retval)) {
         *retval = *value;
 
         function = njs_function_value_copy(vm, retval);
index 502e3fb8de00727887505e7603a4f154a5c144a1..958b0049fb8928d09a550a25ac71dc7a054117b1 100644 (file)
@@ -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]") },