From: Alexander Borisov Date: Tue, 30 Jun 2020 15:22:18 +0000 (+0300) Subject: Fixed index generation for global objects. X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=7a7484cc7f602cee2e612490bbc133a1cc6e96c4;p=njs.git 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. --- 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") }, };