]> git.kaiwu.me - njs.git/commitdiff
Added "lineNumber" and "fileName" to SyntaxError.
authorDmitry Volyntsev <xeioex@nginx.com>
Sun, 12 Apr 2020 12:56:25 +0000 (12:56 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Sun, 12 Apr 2020 12:56:25 +0000 (12:56 +0000)
src/njs_parser.c

index 27194eab55fa5fe1d87b2e31ad1ec7be4a33cb1d..2f953c35a9c88acad3459ff6000d847ef7de41c2 100644 (file)
@@ -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);
+        }
+    }
 }