]> git.kaiwu.me - njs.git/commitdiff
Fixed index generation for global objects.
authorAlexander Borisov <alexander.borisov@nginx.com>
Tue, 30 Jun 2020 15:22:18 +0000 (18:22 +0300)
committerAlexander Borisov <alexander.borisov@nginx.com>
Tue, 30 Jun 2020 15:22:18 +0000 (18:22 +0300)
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
src/test/njs_unit_test.c

index 8a163ffe3b71b79c44c9342eefd744aa0d3fa602..88790aacd49c2854427a65a32bb846cbefeb468a 100644 (file)
@@ -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;
     }
index 283e6a6251f2484ac00f0ef8baae402798f6e14b..3604d76e593c846a5bbf0a1702a5cd93eeab36c8 100644 (file)
@@ -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") },
 };