From 04f59f9defeeb618260e620bb11466741c0e41e5 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Wed, 1 Jun 2022 21:54:32 -0700 Subject: [PATCH] Fixed function value initialization. This closes #470 issue on Github. --- src/njs_vmcode.c | 4 ++-- src/test/njs_unit_test.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/njs_vmcode.c b/src/njs_vmcode.c index ae1d1bb4..9833ada0 100644 --- a/src/njs_vmcode.c +++ b/src/njs_vmcode.c @@ -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); diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 502e3fb8..958b0049 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -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]") }, -- 2.47.3