Skip to content

Commit 23ffb9e

Browse files
authoredDec 11, 2023
Record source column positions (#193)
And: - display them in stack traces - expose them as Function.prototype.columnNumber OP_line_num is renamed to OP_source_loc and the pc2line data structure is extended with the column number in zigzag encoding. The bytecode version number BC_VERSION is incremented because pc2line data is read and written by JS_ReadObject() and JS_WriteObject() when it is present. Fixes: quickjs-ng/quickjs#149
1 parent 51860b5 commit 23ffb9e

File tree

4 files changed

+412
-188
lines changed

4 files changed

+412
-188
lines changed
 

‎quickjs-atom.h

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ DEF(empty_string, "")
8181
DEF(length, "length")
8282
DEF(fileName, "fileName")
8383
DEF(lineNumber, "lineNumber")
84+
DEF(columnNumber, "columnNumber")
8485
DEF(message, "message")
8586
DEF(cause, "cause")
8687
DEF(errors, "errors")

‎quickjs-opcode.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ FMT(loc)
4444
FMT(arg)
4545
FMT(var_ref)
4646
FMT(u32)
47+
FMT(u32x2)
4748
FMT(i32)
4849
FMT(const)
4950
FMT(label)
@@ -281,7 +282,7 @@ def(scope_put_private_field, 7, 2, 0, atom_u16) /* obj value ->, emitted in phas
281282

282283
def( set_class_name, 5, 1, 1, u32) /* emitted in phase 1, removed in phase 2 */
283284

284-
def( line_num, 5, 0, 0, u32) /* emitted in phase 1, removed in phase 3 */
285+
def( source_loc, 9, 0, 0, u32x2) /* emitted in phase 1, removed in phase 3 */
285286

286287
DEF( push_minus1, 1, 0, 1, none_int)
287288
DEF( push_0, 1, 0, 1, none_int)

‎quickjs.c

+384-187
Large diffs are not rendered by default.

‎tests/test_builtin.js

+25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
import * as os from "os";
22

3+
// Keep this at the top; it tests source positions.
4+
function test_exception_source_pos()
5+
{
6+
var e;
7+
8+
try {
9+
throw new Error(""); // line 9, column 19
10+
} catch(_e) {
11+
e = _e;
12+
}
13+
14+
assert(e.stack.includes("test_builtin.js:9:19"));
15+
}
16+
17+
// Keep this at the top; it tests source positions.
18+
function test_function_source_pos() // line 18, column 1
19+
{
20+
function inner() {} // line 20, column 5
21+
var f = eval("function f() {} f");
22+
assert(`${test_function_source_pos.lineNumber}:${test_function_source_pos.columnNumber}`, "18:1");
23+
assert(`${inner.lineNumber}:${inner.columnNumber}`, "20:5");
24+
assert(`${f.lineNumber}:${f.columnNumber}`, "1:1");
25+
}
326

427
function assert(actual, expected, message) {
528
if (arguments.length == 1)
@@ -758,3 +781,5 @@ test_weak_map();
758781
test_weak_set();
759782
test_generator();
760783
test_proxy_is_array();
784+
test_exception_source_pos();
785+
test_function_source_pos();

0 commit comments

Comments
 (0)
Please sign in to comment.