Skip to content

Instantly share code, notes, and snippets.

@xeioex
Created February 28, 2019 13:56
Show Gist options
  • Save xeioex/b7d0d6472f002cc1f04f8207bbd625ce to your computer and use it in GitHub Desktop.
Save xeioex/b7d0d6472f002cc1f04f8207bbd625ce to your computer and use it in GitHub Desktop.
# HG changeset patch
# User Dmitry Volyntsev <[email protected]>
# Date 1551362098 -10800
# Thu Feb 28 16:54:58 2019 +0300
# Node ID e78f10a666cc3cff690f6dcd046bfb7393344dee
# Parent 21925caaa3c5f7e019a9ce4b6c48048006522e84
Fixed lexer referencing in runtime.
diff --git a/njs/njs.c b/njs/njs.c
--- a/njs/njs.c
+++ b/njs/njs.c
@@ -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 --git a/njs/njs_parser.c b/njs/njs_parser.c
--- a/njs/njs_parser.c
+++ b/njs/njs_parser.c
@@ -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 --git a/njs/njs_regexp.c b/njs/njs_regexp.c
--- a/njs/njs_regexp.c
+++ b/njs/njs_regexp.c
@@ -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 --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c
--- 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") },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment