Skip to content

Commit 1a220e7

Browse files
committed
Improve column number tracking
- simplify column number tracking using a single pointer to the beginning of line - add `js_parse_error_pos` to report syntax errors with correct column number for token parsing errors - runtime errors on calls report the column number of the `)̀`. this could be fixed with some extra code. - update tests/test_builtin,js with more informative messages - improve `assert()` and tests/test_language.js tests
1 parent 5a7e578 commit 1a220e7

File tree

6 files changed

+197
-166
lines changed

6 files changed

+197
-166
lines changed

gen/function_source.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "quickjs-libc.h"
44

5-
const uint32_t qjsc_function_source_size = 384;
5+
const uint32_t qjsc_function_source_size = 408;
66

7-
const uint8_t qjsc_function_source[384] = {
7+
const uint8_t qjsc_function_source[408] = {
88
0x0c, 0x06, 0x0c, 0x61, 0x63, 0x74, 0x75, 0x61,
99
0x6c, 0x02, 0x66, 0x30, 0x74, 0x65, 0x73, 0x74,
1010
0x73, 0x2f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69,
@@ -47,12 +47,15 @@ const uint8_t qjsc_function_source[384] = {
4747
0x38, 0xdc, 0x00, 0x00, 0x00, 0xaf, 0xe9, 0x0b,
4848
0x38, 0x92, 0x00, 0x00, 0x00, 0x62, 0x03, 0x00,
4949
0xee, 0x2f, 0x68, 0x03, 0x00, 0x68, 0x02, 0x00,
50-
0xc4, 0x28, 0xb6, 0x03, 0x01, 0x01, 0x28, 0x60,
50+
0xc4, 0x28, 0xb6, 0x03, 0x01, 0x01, 0x40, 0x60,
5151
0x01, 0x49, 0x02, 0x21, 0x1a, 0x1b, 0x04, 0x1e,
52-
0x1d, 0x12, 0x26, 0x49, 0x1d, 0x0c, 0x06, 0x11,
53-
0x18, 0x2a, 0x1c, 0x37, 0x41, 0x21, 0x1c, 0x34,
54-
0x18, 0x1b, 0x04, 0x26, 0x11, 0x3f, 0x1d, 0x0c,
55-
0x06, 0x11, 0x18, 0x2a, 0x1c, 0x53, 0x41, 0x00,
52+
0x1d, 0x12, 0x26, 0x1b, 0x02, 0x1b, 0x14, 0x17,
53+
0x33, 0x0c, 0x08, 0x11, 0x16, 0x20, 0x0c, 0x0c,
54+
0x10, 0x1b, 0x0c, 0x11, 0x0c, 0x0f, 0x59, 0x21,
55+
0x1c, 0x1b, 0x0a, 0x1b, 0x0e, 0x1b, 0x04, 0x07,
56+
0x06, 0x21, 0x17, 0x11, 0x02, 0x1b, 0x14, 0x17,
57+
0x33, 0x0c, 0x08, 0x11, 0x16, 0x20, 0x0c, 0x0c,
58+
0x10, 0x1b, 0x0c, 0x11, 0x0c, 0x2b, 0x59, 0x00,
5659
};
5760

5861
static JSContext *JS_NewCustomContext(JSRuntime *rt)

gen/hello.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "quickjs-libc.h"
44

5-
const uint32_t qjsc_hello_size = 89;
5+
const uint32_t qjsc_hello_size = 97;
66

7-
const uint8_t qjsc_hello[89] = {
7+
const uint8_t qjsc_hello[97] = {
88
0x0c, 0x04, 0x0e, 0x63, 0x6f, 0x6e, 0x73, 0x6f,
99
0x6c, 0x65, 0x06, 0x6c, 0x6f, 0x67, 0x16, 0x48,
1010
0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72,
@@ -15,7 +15,8 @@ const uint8_t qjsc_hello[89] = {
1515
0x14, 0x01, 0xa0, 0x01, 0x00, 0x00, 0x00, 0x38,
1616
0xd9, 0x00, 0x00, 0x00, 0x42, 0xda, 0x00, 0x00,
1717
0x00, 0x04, 0xdb, 0x00, 0x00, 0x00, 0x24, 0x01,
18-
0x00, 0xcc, 0x28, 0xb8, 0x03, 0x01, 0x01, 0x00,
18+
0x00, 0xcc, 0x28, 0xb8, 0x03, 0x01, 0x01, 0x08,
19+
0x1b, 0x0e, 0x1b, 0x08, 0x1b, 0x1c, 0x11, 0x02,
1920
0x00,
2021
};
2122

gen/hello_module.c

+36-32
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "quickjs-libc.h"
44

5-
const uint32_t qjsc_fib_module_size = 310;
5+
const uint32_t qjsc_fib_module_size = 322;
66

7-
const uint8_t qjsc_fib_module[310] = {
7+
const uint8_t qjsc_fib_module[322] = {
88
0x0c, 0x03, 0x2c, 0x65, 0x78, 0x61, 0x6d, 0x70,
99
0x6c, 0x65, 0x73, 0x2f, 0x66, 0x69, 0x62, 0x5f,
1010
0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x6a,
@@ -19,36 +19,38 @@ const uint8_t qjsc_fib_module[310] = {
1919
0xb3, 0x28, 0xd0, 0xb4, 0xac, 0xe9, 0x03, 0xb4,
2020
0x28, 0xdc, 0xd0, 0xb4, 0x9e, 0xee, 0xdc, 0xd0,
2121
0xb5, 0x9e, 0xee, 0x9d, 0x28, 0xb2, 0x03, 0x02,
22-
0x08, 0x20, 0x04, 0x00, 0x07, 0x06, 0x07, 0x06,
23-
0x12, 0x09, 0x08, 0x07, 0x07, 0x10, 0x07, 0x06,
24-
0x07, 0x06, 0x12, 0x13, 0x08, 0x07, 0x08, 0x16,
25-
0x0c, 0x0c, 0x07, 0x04, 0x0c, 0x0a, 0x0c, 0x0c,
26-
0x07, 0x04, 0x8d, 0x01, 0x66, 0x75, 0x6e, 0x63,
27-
0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x69, 0x62,
28-
0x28, 0x6e, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20,
29-
0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x6e, 0x20,
30-
0x3c, 0x3d, 0x20, 0x30, 0x29, 0x0a, 0x20, 0x20,
31-
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65,
32-
0x74, 0x75, 0x72, 0x6e, 0x20, 0x30, 0x3b, 0x0a,
33-
0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65,
34-
0x20, 0x69, 0x66, 0x20, 0x28, 0x6e, 0x20, 0x3d,
35-
0x3d, 0x20, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x20,
36-
0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74,
37-
0x75, 0x72, 0x6e, 0x20, 0x31, 0x3b, 0x0a, 0x20,
38-
0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a,
39-
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
40-
0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66,
41-
0x69, 0x62, 0x28, 0x6e, 0x20, 0x2d, 0x20, 0x31,
42-
0x29, 0x20, 0x2b, 0x20, 0x66, 0x69, 0x62, 0x28,
43-
0x6e, 0x20, 0x2d, 0x20, 0x32, 0x29, 0x3b, 0x0a,
44-
0x7d, 0x08, 0xe9, 0x05, 0xbe, 0x00, 0xe0, 0x29,
45-
0x06, 0x2e, 0xb2, 0x03, 0x01, 0x01, 0x06, 0x01,
46-
0x01, 0x00, 0x07, 0x14, 0x02, 0x00,
22+
0x08, 0x2c, 0x04, 0x02, 0x07, 0x04, 0x07, 0x06,
23+
0x07, 0x02, 0x0d, 0x0b, 0x08, 0x07, 0x07, 0x12,
24+
0x07, 0x04, 0x07, 0x06, 0x07, 0x02, 0x0d, 0x15,
25+
0x08, 0x07, 0x08, 0x16, 0x07, 0x08, 0x07, 0x04,
26+
0x07, 0x04, 0x07, 0x02, 0x07, 0x08, 0x07, 0x08,
27+
0x07, 0x04, 0x07, 0x04, 0x07, 0x02, 0x8d, 0x01,
28+
0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
29+
0x20, 0x66, 0x69, 0x62, 0x28, 0x6e, 0x29, 0x0a,
30+
0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66,
31+
0x20, 0x28, 0x6e, 0x20, 0x3c, 0x3d, 0x20, 0x30,
32+
0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
33+
0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e,
34+
0x20, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20,
35+
0x65, 0x6c, 0x73, 0x65, 0x20, 0x69, 0x66, 0x20,
36+
0x28, 0x6e, 0x20, 0x3d, 0x3d, 0x20, 0x31, 0x29,
37+
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
38+
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20,
39+
0x31, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65,
40+
0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x20,
41+
0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75,
42+
0x72, 0x6e, 0x20, 0x66, 0x69, 0x62, 0x28, 0x6e,
43+
0x20, 0x2d, 0x20, 0x31, 0x29, 0x20, 0x2b, 0x20,
44+
0x66, 0x69, 0x62, 0x28, 0x6e, 0x20, 0x2d, 0x20,
45+
0x32, 0x29, 0x3b, 0x0a, 0x7d, 0x08, 0xe9, 0x05,
46+
0xbe, 0x00, 0xe0, 0x29, 0x06, 0x2e, 0xb2, 0x03,
47+
0x01, 0x01, 0x06, 0x01, 0x01, 0x00, 0x07, 0x14,
48+
0x02, 0x00,
4749
};
4850

49-
const uint32_t qjsc_hello_module_size = 177;
51+
const uint32_t qjsc_hello_module_size = 195;
5052

51-
const uint8_t qjsc_hello_module[177] = {
53+
const uint8_t qjsc_hello_module[195] = {
5254
0x0c, 0x07, 0x30, 0x65, 0x78, 0x61, 0x6d, 0x70,
5355
0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c, 0x6c,
5456
0x6f, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
@@ -69,9 +71,11 @@ const uint8_t qjsc_hello_module[177] = {
6971
0x00, 0x00, 0x00, 0x42, 0xdd, 0x00, 0x00, 0x00,
7072
0x04, 0xdf, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00,
7173
0xbb, 0x0a, 0xee, 0x24, 0x02, 0x00, 0x0e, 0x06,
72-
0x2e, 0xb2, 0x03, 0x01, 0x01, 0x0a, 0x01, 0x01,
73-
0x00, 0x04, 0x0a, 0x02, 0x62, 0x00, 0x4d, 0x30,
74-
0x00,
74+
0x2e, 0xb2, 0x03, 0x01, 0x01, 0x1c, 0x01, 0x01,
75+
0x00, 0x04, 0x0a, 0x02, 0x1b, 0x0e, 0x1b, 0x08,
76+
0x1b, 0x1c, 0x17, 0x31, 0x1b, 0x0e, 0x1b, 0x08,
77+
0x1b, 0x1a, 0x11, 0x06, 0x0c, 0x06, 0x07, 0x02,
78+
0x16, 0x02, 0x00,
7579
};
7680

7781
static JSContext *JS_NewCustomContext(JSRuntime *rt)

gen/test_fib.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "quickjs-libc.h"
44

5-
const uint32_t qjsc_test_fib_size = 166;
5+
const uint32_t qjsc_test_fib_size = 184;
66

7-
const uint8_t qjsc_test_fib[166] = {
7+
const uint8_t qjsc_test_fib[184] = {
88
0x0c, 0x07, 0x28, 0x65, 0x78, 0x61, 0x6d, 0x70,
99
0x6c, 0x65, 0x73, 0x2f, 0x74, 0x65, 0x73, 0x74,
1010
0x5f, 0x66, 0x69, 0x62, 0x2e, 0x6a, 0x73, 0x10,
@@ -24,8 +24,10 @@ const uint8_t qjsc_test_fib[166] = {
2424
0x42, 0xdd, 0x00, 0x00, 0x00, 0x04, 0xdf, 0x00,
2525
0x00, 0x00, 0x65, 0x00, 0x00, 0xbb, 0x0a, 0xee,
2626
0x24, 0x02, 0x00, 0x0e, 0x06, 0x2e, 0xb2, 0x03,
27-
0x01, 0x01, 0x0a, 0x01, 0x01, 0x00, 0x04, 0x0a,
28-
0x02, 0x62, 0x00, 0x4d, 0x30, 0x00,
27+
0x01, 0x01, 0x1c, 0x01, 0x01, 0x00, 0x04, 0x0a,
28+
0x02, 0x1b, 0x0e, 0x1b, 0x08, 0x1b, 0x1c, 0x17,
29+
0x31, 0x1b, 0x0e, 0x1b, 0x08, 0x1b, 0x1a, 0x11,
30+
0x06, 0x0c, 0x06, 0x07, 0x02, 0x16, 0x02, 0x00,
2931
};
3032

3133
static JSContext *JS_NewCustomContext(JSRuntime *rt)

0 commit comments

Comments
 (0)