From 7a7484cc7f602cee2e612490bbc133a1cc6e96c4 Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Tue, 30 Jun 2020 18:22:18 +0300 Subject: [PATCH] Fixed index generation for global objects. In c75a8fc6d534 "GLOBAL GET" instruction was introduced to handle unresolved references. The issue was that the "GLOBAL GET" instruction erroneously used the assignment variable index as a destination index. The result was that a variable was assigned the retval of a "GLOBAL GET" instruction. The fix is to use a separate temporary index for "GLOBAL GET". This closes #289 issue on GitHub. --- src/njs_generator.c | 2 +- src/test/njs_unit_test.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/njs_generator.c b/src/njs_generator.c index 8a163ffe..88790aac 100644 --- a/src/njs_generator.c +++ b/src/njs_generator.c @@ -3384,7 +3384,7 @@ njs_generate_global_reference(njs_vm_t *vm, njs_generator_t *generator, njs_vmcode_prop_get_t *prop_get; const njs_lexer_entry_t *lex_entry; - index = njs_generate_dest_index(vm, generator, node); + index = njs_generate_temp_index_get(vm, generator, node); if (njs_slow_path(index == NJS_INDEX_ERROR)) { return NJS_ERROR; } diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 283e6a62..3604d76e 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -17043,6 +17043,12 @@ static njs_unit_test_t njs_test[] = { njs_str("for (;1-;) {}"), njs_str("SyntaxError: Unexpected token \";\" in 1") }, + + { njs_str("var str = String(str); str"), + njs_str("undefined") }, + + { njs_str("var t = \"123\"; t = parseInt(t); t"), + njs_str("123") }, }; -- 2.47.3