[njs] Fixed index generation for global objects.
Alexander Borisov
alexander.borisov at nginx.com
Tue Jun 30 15:22:59 UTC 2020
details: https://hg.nginx.org/njs/rev/52dd845c0a36
branches:
changeset: 1441:52dd845c0a36
user: Alexander Borisov <alexander.borisov at nginx.com>
date: Tue Jun 30 18:22:18 2020 +0300
description:
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.
diffstat:
src/njs_generator.c | 2 +-
src/test/njs_unit_test.c | 6 ++++++
2 files changed, 7 insertions(+), 1 deletions(-)
diffs (28 lines):
diff -r fac632b520fa -r 52dd845c0a36 src/njs_generator.c
--- a/src/njs_generator.c Thu Jun 25 13:10:04 2020 +0300
+++ b/src/njs_generator.c Tue Jun 30 18:22:18 2020 +0300
@@ -3384,7 +3384,7 @@ njs_generate_global_reference(njs_vm_t *
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 -r fac632b520fa -r 52dd845c0a36 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Thu Jun 25 13:10:04 2020 +0300
+++ b/src/test/njs_unit_test.c Tue Jun 30 18:22:18 2020 +0300
@@ -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") },
};
More information about the nginx-devel
mailing list