From: Dmitry Volyntsev Date: Sun, 12 Apr 2020 12:56:25 +0000 (+0000) Subject: Added "lineNumber" and "fileName" to SyntaxError. X-Git-Tag: 0.4.0~10 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=c86140720634beef632c5fec44c0f3fb1a4fa4d9;p=njs.git Added "lineNumber" and "fileName" to SyntaxError. --- diff --git a/src/njs_parser.c b/src/njs_parser.c index 27194eab..2f953c35 100644 --- a/src/njs_parser.c +++ b/src/njs_parser.c @@ -2320,10 +2320,15 @@ static void njs_parser_scope_error(njs_vm_t *vm, njs_parser_scope_t *scope, njs_object_type_t type, uint32_t line, const char *fmt, va_list args) { - size_t width; - u_char msg[NJS_MAX_ERROR_STR]; - u_char *p, *end; - njs_str_t *file; + size_t width; + u_char msg[NJS_MAX_ERROR_STR]; + u_char *p, *end; + njs_str_t *file; + njs_int_t ret; + njs_value_t value; + + static const njs_value_t file_name = njs_string("fileName"); + static const njs_value_t line_number = njs_string("lineNumber"); file = &scope->file; @@ -2346,6 +2351,18 @@ njs_parser_scope_error(njs_vm_t *vm, njs_parser_scope_t *scope, } njs_error_new(vm, &vm->retval, type, msg, p - msg); + + njs_set_number(&value, line); + njs_value_property_set(vm, &vm->retval, njs_value_arg(&line_number), + &value); + + if (file->length != 0) { + ret = njs_string_set(vm, &value, file->start, file->length); + if (ret == NJS_OK) { + njs_value_property_set(vm, &vm->retval, njs_value_arg(&file_name), + &value); + } + } }