From: Dmitry Volyntsev Date: Thu, 28 Feb 2019 16:30:32 +0000 (+0300) Subject: Fixed lexer referencing in runtime. X-Git-Tag: 0.3.0~32 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=51cb370af005ca6c77a427b4d16d107a4ab17a0e;p=njs.git Fixed lexer referencing in runtime. --- diff --git a/njs/njs.c b/njs/njs.c index 284a66fa..e3140e70 100644 --- a/njs/njs.c +++ b/njs/njs.c @@ -255,6 +255,8 @@ njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end) 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_ptr_t 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 --git a/njs/njs_parser.c b/njs/njs_parser.c index d8249ba7..483778a5 100644 --- a/njs/njs_parser.c +++ b/njs/njs_parser.c @@ -2771,7 +2771,7 @@ njs_parser_trace_handler(nxt_trace_t *trace, nxt_trace_data_t *td, 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 --git a/njs/njs_regexp.c b/njs/njs_regexp.c index bce162ce..457836b4 100644 --- a/njs/njs_regexp.c +++ b/njs/njs_regexp.c @@ -376,7 +376,7 @@ njs_regexp_compile_trace_handler(nxt_trace_t *trace, nxt_trace_data_t *td, 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 --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 3c5ab0bd..f468c077 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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") },