[njs] Fixed lexer referencing in runtime.

Dmitry Volyntsev xeioex at nginx.com
Thu Feb 28 17:35:08 UTC 2019


details:   https://hg.nginx.org/njs/rev/33c663d84114
branches:  
changeset: 814:33c663d84114
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Feb 28 19:30:32 2019 +0300
description:
Fixed lexer referencing in runtime.

diffstat:

 njs/njs.c                |  4 ++++
 njs/njs_parser.c         |  2 +-
 njs/njs_regexp.c         |  2 +-
 njs/test/njs_unit_test.c |  3 +++
 4 files changed, 9 insertions(+), 2 deletions(-)

diffs (59 lines):

diff -r 21925caaa3c5 -r 33c663d84114 njs/njs.c
--- a/njs/njs.c	Thu Feb 28 15:32:15 2019 +0300
+++ b/njs/njs.c	Thu Feb 28 19:30:32 2019 +0300
@@ -255,6 +255,8 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
         goto fail;
     }
 
+    parser->lexer = NULL;
+
     scope = parser->scope;
 
     ret = njs_variables_scope_reference(vm, scope);
@@ -327,7 +329,9 @@ njs_vm_clone(njs_vm_t *vm, njs_external_
         nvm->mem_pool = nmp;
 
         nvm->shared = vm->shared;
+
         nvm->trace = vm->trace;
+        nvm->trace.data = nvm;
 
         nvm->variables_hash = vm->variables_hash;
         nvm->values_hash = vm->values_hash;
diff -r 21925caaa3c5 -r 33c663d84114 njs/njs_parser.c
--- a/njs/njs_parser.c	Thu Feb 28 15:32:15 2019 +0300
+++ b/njs/njs_parser.c	Thu Feb 28 19:30:32 2019 +0300
@@ -2771,7 +2771,7 @@ njs_parser_trace_handler(nxt_trace_t *tr
     trace = trace->next;
     p = trace->handler(trace, td, p);
 
-    if (vm->parser != NULL) {
+    if (vm->parser != NULL && vm->parser->lexer != NULL) {
         lexer = vm->parser->lexer;
 
         if (lexer->file.length != 0) {
diff -r 21925caaa3c5 -r 33c663d84114 njs/njs_regexp.c
--- a/njs/njs_regexp.c	Thu Feb 28 15:32:15 2019 +0300
+++ b/njs/njs_regexp.c	Thu Feb 28 19:30:32 2019 +0300
@@ -376,7 +376,7 @@ njs_regexp_compile_trace_handler(nxt_tra
     trace = trace->next;
     p = trace->handler(trace, td, start);
 
-    if (vm->parser != NULL) {
+    if (vm->parser != NULL && vm->parser->lexer != NULL) {
         njs_syntax_error(vm, "%*s in %uD", p - start, start,
                          vm->parser->lexer->line);
 
diff -r 21925caaa3c5 -r 33c663d84114 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Thu Feb 28 15:32:15 2019 +0300
+++ b/njs/test/njs_unit_test.c	Thu Feb 28 19:30:32 2019 +0300
@@ -6651,6 +6651,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("new RegExp('', 'x')"),
       nxt_string("SyntaxError: Invalid RegExp flags \"x\"") },
 
+    { nxt_string("new RegExp('[')"),
+      nxt_string("SyntaxError: pcre_compile(\"[\") failed: missing terminating ] for character class") },
+
     { nxt_string("[0].map(RegExp().toString)"),
       nxt_string("TypeError: \"this\" argument is not a regexp") },
 


More information about the nginx-devel mailing list