mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
Track line and column numbers for expressions (#781)
Commit 73cc00e
reduced the number of emitted source locations a great
deal but it resulted in at least one observable regression:
export default async function f() {
return "abc" + x
}
f() // ReferenceError should point to 2:20 but pointed to 1:1
Emit source locations for expressions again. Increases the average
number of source locations by about 15%. Non-scientifically tested
by counting source locations emitted when parsing the test suite
before and after.
No test because we currently cannot easily test stack traces coming
from module imports.
Fixes: https://github.com/quickjs-ng/quickjs/issues/779
This commit is contained in:
parent
5b609f15af
commit
ac4cd17bb5
5 changed files with 9 additions and 8 deletions
Binary file not shown.
Binary file not shown.
BIN
gen/test_fib.c
BIN
gen/test_fib.c
Binary file not shown.
|
@ -20414,8 +20414,8 @@ static void emit_source_loc(JSParseState *s)
|
|||
DynBuf *bc = &fd->byte_code;
|
||||
|
||||
dbuf_putc(bc, OP_source_loc);
|
||||
dbuf_put_u32(bc, s->last_line_num);
|
||||
dbuf_put_u32(bc, s->last_col_num);
|
||||
dbuf_put_u32(bc, s->token.line_num);
|
||||
dbuf_put_u32(bc, s->token.col_num);
|
||||
}
|
||||
|
||||
static void emit_op(JSParseState *s, uint8_t val)
|
||||
|
@ -24424,6 +24424,7 @@ static __exception int js_parse_expr_binary(JSParseState *s, int level,
|
|||
}
|
||||
if (next_token(s))
|
||||
return -1;
|
||||
emit_source_loc(s);
|
||||
if (js_parse_expr_binary(s, level - 1, parse_flags))
|
||||
return -1;
|
||||
emit_op(s, opcode);
|
||||
|
|
|
@ -7,12 +7,12 @@ function test_exception_source_pos()
|
|||
var e;
|
||||
|
||||
try {
|
||||
throw new Error(""); // line 10, column 15
|
||||
throw new Error(""); // line 10, column 19
|
||||
} catch(_e) {
|
||||
e = _e;
|
||||
}
|
||||
|
||||
assert(e.stack.includes("test_builtin.js:10:15"));
|
||||
assert(e.stack.includes("test_builtin.js:10:19"));
|
||||
}
|
||||
|
||||
// Keep this at the top; it tests source positions.
|
||||
|
@ -36,7 +36,7 @@ function test_exception_prepare_stack()
|
|||
};
|
||||
|
||||
try {
|
||||
throw new Error(""); // line 39, column 15
|
||||
throw new Error(""); // line 39, column 19
|
||||
} catch(_e) {
|
||||
e = _e;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ function test_exception_prepare_stack()
|
|||
assert(f.getFunctionName(), 'test_exception_prepare_stack');
|
||||
assert(f.getFileName().endsWith('test_builtin.js'));
|
||||
assert(f.getLineNumber(), 39);
|
||||
assert(f.getColumnNumber(), 15);
|
||||
assert(f.getColumnNumber(), 19);
|
||||
assert(!f.isNative());
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ function test_exception_stack_size_limit()
|
|||
};
|
||||
|
||||
try {
|
||||
throw new Error(""); // line 67, column 15
|
||||
throw new Error(""); // line 67, column 19
|
||||
} catch(_e) {
|
||||
e = _e;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ function test_exception_stack_size_limit()
|
|||
assert(f.getFunctionName(), 'test_exception_stack_size_limit');
|
||||
assert(f.getFileName().endsWith('test_builtin.js'));
|
||||
assert(f.getLineNumber(), 67);
|
||||
assert(f.getColumnNumber(), 15);
|
||||
assert(f.getColumnNumber(), 19);
|
||||
assert(!f.isNative());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue