Skip to content

Commit 37fe427

Browse files
authored
Add resizable ArrayBuffers (#646)
This commit implements resizable ArrayBuffers - RABs for short - and extends typed arrays (TAs) to support fixed-length and length-tracking modes. SharedArrayBuffers (SABs) also support the maxByteLength option now but I cheated and allocate all memory upfront because atomically resizing memory allocations is hard and this commit is already big and complex. The lion's share is updating all the TA prototype methods to deal with RABs resizing underneath them. Method arguments can be arbitrary objects with arbitrary .valueOf methods and arbitrary side effects, like... resizing the RAB we're currently operating on. Fixes: #477
1 parent e569f39 commit 37fe427

File tree

10 files changed

+1998
-1536
lines changed

10 files changed

+1998
-1536
lines changed

gen/function_source.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const uint32_t qjsc_function_source_size = 338;
66

77
const uint8_t qjsc_function_source[338] = {
8-
0x10, 0x05, 0x01, 0x30, 0x74, 0x65, 0x73, 0x74,
8+
0x11, 0x05, 0x01, 0x30, 0x74, 0x65, 0x73, 0x74,
99
0x73, 0x2f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69,
1010
0x6f, 0x6e, 0x5f, 0x73, 0x6f, 0x75, 0x72, 0x63,
1111
0x65, 0x2e, 0x6a, 0x73, 0x01, 0x0c, 0x61, 0x63,
@@ -14,35 +14,35 @@ const uint8_t qjsc_function_source[338] = {
1414
0x34, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f,
1515
0x6e, 0x20, 0x66, 0x28, 0x29, 0x20, 0x7b, 0x20,
1616
0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x34,
17-
0x32, 0x20, 0x7d, 0x0d, 0xba, 0x03, 0x00, 0x00,
17+
0x32, 0x20, 0x7d, 0x0d, 0xbc, 0x03, 0x00, 0x00,
1818
0x00, 0x00, 0x00, 0x0c, 0x20, 0xfa, 0x01, 0xa2,
1919
0x01, 0x00, 0x05, 0x00, 0x03, 0x02, 0x01, 0x74,
20-
0x05, 0xbc, 0x03, 0x02, 0x00, 0x30, 0xbe, 0x03,
21-
0x04, 0x00, 0x70, 0xbc, 0x03, 0x04, 0x02, 0x70,
20+
0x05, 0xbe, 0x03, 0x02, 0x00, 0x30, 0xc0, 0x03,
21+
0x04, 0x00, 0x70, 0xbe, 0x03, 0x04, 0x02, 0x70,
2222
0x10, 0x00, 0x01, 0x00, 0xe4, 0x01, 0x00, 0x01,
23-
0x00, 0xc0, 0x03, 0x00, 0x0d, 0xbe, 0x03, 0x01,
24-
0x01, 0x0c, 0x43, 0xfa, 0x01, 0xbe, 0x03, 0x00,
23+
0x00, 0xc2, 0x03, 0x00, 0x0d, 0xc0, 0x03, 0x01,
24+
0x01, 0x0c, 0x43, 0xfa, 0x01, 0xc0, 0x03, 0x00,
2525
0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0xbc,
26-
0x2a, 0x28, 0xba, 0x03, 0x03, 0x01, 0x04, 0x02,
26+
0x2a, 0x28, 0xbc, 0x03, 0x03, 0x01, 0x04, 0x02,
2727
0x1e, 0x0c, 0x0e, 0x1a, 0x66, 0x75, 0x6e, 0x63,
2828
0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x28, 0x29,
2929
0x20, 0x7b, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72,
3030
0x6e, 0x20, 0x34, 0x32, 0x20, 0x7d, 0x0c, 0x03,
3131
0xc2, 0x04, 0x08, 0xcc, 0x08, 0xea, 0x05, 0xbf,
32-
0x00, 0xe2, 0x29, 0x04, 0xe1, 0x00, 0x00, 0x00,
32+
0x00, 0xe2, 0x29, 0x04, 0xe2, 0x00, 0x00, 0x00,
3333
0xe1, 0x61, 0x00, 0x00, 0xde, 0x42, 0x38, 0x00,
3434
0x00, 0x00, 0x24, 0x00, 0x00, 0xc9, 0x62, 0x00,
3535
0x00, 0x65, 0x00, 0x00, 0xaf, 0xea, 0x0b, 0x38,
36-
0x94, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0xef,
36+
0x95, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0xef,
3737
0x2f, 0x61, 0x02, 0x00, 0x61, 0x01, 0x00, 0x38,
3838
0x3b, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x04,
39-
0xdf, 0x00, 0x00, 0x00, 0x9d, 0x31, 0x01, 0x00,
39+
0xe0, 0x00, 0x00, 0x00, 0x9d, 0x31, 0x01, 0x00,
4040
0x03, 0x00, 0xca, 0x62, 0x01, 0x00, 0x42, 0x38,
4141
0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0xcb, 0x62,
4242
0x02, 0x00, 0x65, 0x00, 0x00, 0xaf, 0xea, 0x0b,
43-
0x38, 0x94, 0x00, 0x00, 0x00, 0x62, 0x02, 0x00,
43+
0x38, 0x95, 0x00, 0x00, 0x00, 0x62, 0x02, 0x00,
4444
0xef, 0x2f, 0x68, 0x02, 0x00, 0x68, 0x01, 0x00,
45-
0x06, 0x2e, 0xba, 0x03, 0x01, 0x01, 0x22, 0x1f,
45+
0x06, 0x2e, 0xbc, 0x03, 0x01, 0x01, 0x22, 0x1f,
4646
0x01, 0x27, 0x1c, 0x1b, 0x04, 0x0a, 0x1d, 0x12,
4747
0x26, 0x35, 0x17, 0x11, 0x18, 0x20, 0x1c, 0x37,
4848
0x41, 0x21, 0x1c, 0x2a, 0x18, 0x1b, 0x04, 0x26,

gen/hello.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
const uint32_t qjsc_hello_size = 105;
66

77
const uint8_t qjsc_hello[105] = {
8-
0x10, 0x04, 0x01, 0x22, 0x65, 0x78, 0x61, 0x6d,
8+
0x11, 0x04, 0x01, 0x22, 0x65, 0x78, 0x61, 0x6d,
99
0x70, 0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c,
1010
0x6c, 0x6f, 0x2e, 0x6a, 0x73, 0x01, 0x0e, 0x63,
1111
0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x01, 0x06,
1212
0x6c, 0x6f, 0x67, 0x01, 0x16, 0x48, 0x65, 0x6c,
1313
0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64,
14-
0x0d, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
14+
0x0d, 0xbc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
1515
0x0c, 0x20, 0xfa, 0x01, 0xa2, 0x01, 0x00, 0x00,
1616
0x00, 0x03, 0x00, 0x00, 0x19, 0x00, 0x08, 0xea,
17-
0x02, 0x29, 0x38, 0xde, 0x00, 0x00, 0x00, 0x42,
18-
0xdf, 0x00, 0x00, 0x00, 0x04, 0xe0, 0x00, 0x00,
19-
0x00, 0x24, 0x01, 0x00, 0x0e, 0x06, 0x2e, 0xba,
17+
0x02, 0x29, 0x38, 0xdf, 0x00, 0x00, 0x00, 0x42,
18+
0xe0, 0x00, 0x00, 0x00, 0x04, 0xe1, 0x00, 0x00,
19+
0x00, 0x24, 0x01, 0x00, 0x0e, 0x06, 0x2e, 0xbc,
2020
0x03, 0x01, 0x01, 0x04, 0x01, 0x01, 0x17, 0x02,
2121
0x00,
2222
};

gen/hello_module.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
const uint32_t qjsc_fib_module_size = 314;
66

77
const uint8_t qjsc_fib_module[314] = {
8-
0x10, 0x03, 0x01, 0x2c, 0x65, 0x78, 0x61, 0x6d,
8+
0x11, 0x03, 0x01, 0x2c, 0x65, 0x78, 0x61, 0x6d,
99
0x70, 0x6c, 0x65, 0x73, 0x2f, 0x66, 0x69, 0x62,
1010
0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e,
1111
0x6a, 0x73, 0x01, 0x06, 0x66, 0x69, 0x62, 0x01,
12-
0x02, 0x6e, 0x0d, 0xba, 0x03, 0x00, 0x01, 0x00,
13-
0x00, 0xbc, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x20,
12+
0x02, 0x6e, 0x0d, 0xbc, 0x03, 0x00, 0x01, 0x00,
13+
0x00, 0xbe, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x20,
1414
0xfa, 0x01, 0xa2, 0x01, 0x00, 0x00, 0x00, 0x01,
15-
0x01, 0x01, 0x09, 0x00, 0xbc, 0x03, 0x00, 0x01,
16-
0x0c, 0x43, 0xfa, 0x01, 0xbc, 0x03, 0x01, 0x00,
17-
0x01, 0x04, 0x01, 0x00, 0x1a, 0x01, 0xbe, 0x03,
18-
0x00, 0x01, 0x00, 0xbc, 0x03, 0x00, 0x00, 0xd1,
15+
0x01, 0x01, 0x09, 0x00, 0xbe, 0x03, 0x00, 0x01,
16+
0x0c, 0x43, 0xfa, 0x01, 0xbe, 0x03, 0x01, 0x00,
17+
0x01, 0x04, 0x01, 0x00, 0x1a, 0x01, 0xc0, 0x03,
18+
0x00, 0x01, 0x00, 0xbe, 0x03, 0x00, 0x00, 0xd1,
1919
0xb4, 0xa7, 0xea, 0x03, 0xb4, 0x28, 0xd1, 0xb5,
2020
0xac, 0xea, 0x03, 0xb5, 0x28, 0xdd, 0xd1, 0xb5,
2121
0x9e, 0xef, 0xdd, 0xd1, 0xb6, 0x9e, 0xef, 0x9d,
22-
0x28, 0xba, 0x03, 0x02, 0x08, 0x20, 0x04, 0x00,
22+
0x28, 0xbc, 0x03, 0x02, 0x08, 0x20, 0x04, 0x00,
2323
0x07, 0x06, 0x07, 0x06, 0x12, 0x09, 0x08, 0x07,
2424
0x07, 0x10, 0x07, 0x06, 0x07, 0x06, 0x12, 0x13,
2525
0x08, 0x07, 0x08, 0x16, 0x0c, 0x0c, 0x07, 0x04,
@@ -42,15 +42,15 @@ const uint8_t qjsc_fib_module[314] = {
4242
0x20, 0x2d, 0x20, 0x31, 0x29, 0x20, 0x2b, 0x20,
4343
0x66, 0x69, 0x62, 0x28, 0x6e, 0x20, 0x2d, 0x20,
4444
0x32, 0x29, 0x3b, 0x0a, 0x7d, 0x08, 0xea, 0x05,
45-
0xbf, 0x00, 0xe1, 0x29, 0x06, 0x2e, 0xba, 0x03,
45+
0xbf, 0x00, 0xe1, 0x29, 0x06, 0x2e, 0xbc, 0x03,
4646
0x01, 0x01, 0x06, 0x01, 0x01, 0x00, 0x07, 0x14,
4747
0x02, 0x00,
4848
};
4949

5050
const uint32_t qjsc_hello_module_size = 185;
5151

5252
const uint8_t qjsc_hello_module[185] = {
53-
0x10, 0x07, 0x01, 0x30, 0x65, 0x78, 0x61, 0x6d,
53+
0x11, 0x07, 0x01, 0x30, 0x65, 0x78, 0x61, 0x6d,
5454
0x70, 0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c,
5555
0x6c, 0x6f, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c,
5656
0x65, 0x2e, 0x6a, 0x73, 0x01, 0x1e, 0x2e, 0x2f,
@@ -61,17 +61,17 @@ const uint8_t qjsc_hello_module[185] = {
6161
0x01, 0x16, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20,
6262
0x57, 0x6f, 0x72, 0x6c, 0x64, 0x01, 0x10, 0x66,
6363
0x69, 0x62, 0x28, 0x31, 0x30, 0x29, 0x3d, 0x0d,
64-
0xba, 0x03, 0x01, 0xbc, 0x03, 0x00, 0x00, 0x01,
65-
0x00, 0xbe, 0x03, 0x00, 0x00, 0x0c, 0x20, 0xfa,
64+
0xbc, 0x03, 0x01, 0xbe, 0x03, 0x00, 0x00, 0x01,
65+
0x00, 0xc0, 0x03, 0x00, 0x00, 0x0c, 0x20, 0xfa,
6666
0x01, 0xa2, 0x01, 0x00, 0x00, 0x00, 0x05, 0x01,
67-
0x00, 0x32, 0x00, 0xbe, 0x03, 0x00, 0x0c, 0x08,
68-
0xea, 0x02, 0x29, 0x38, 0xe0, 0x00, 0x00, 0x00,
69-
0x42, 0xe1, 0x00, 0x00, 0x00, 0x04, 0xe2, 0x00,
70-
0x00, 0x00, 0x24, 0x01, 0x00, 0x0e, 0x38, 0xe0,
71-
0x00, 0x00, 0x00, 0x42, 0xe1, 0x00, 0x00, 0x00,
72-
0x04, 0xe3, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00,
67+
0x00, 0x32, 0x00, 0xc0, 0x03, 0x00, 0x0c, 0x08,
68+
0xea, 0x02, 0x29, 0x38, 0xe1, 0x00, 0x00, 0x00,
69+
0x42, 0xe2, 0x00, 0x00, 0x00, 0x04, 0xe3, 0x00,
70+
0x00, 0x00, 0x24, 0x01, 0x00, 0x0e, 0x38, 0xe1,
71+
0x00, 0x00, 0x00, 0x42, 0xe2, 0x00, 0x00, 0x00,
72+
0x04, 0xe4, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00,
7373
0xbc, 0x0a, 0xef, 0x24, 0x02, 0x00, 0x0e, 0x06,
74-
0x2e, 0xba, 0x03, 0x01, 0x01, 0x0a, 0x01, 0x01,
74+
0x2e, 0xbc, 0x03, 0x01, 0x01, 0x0a, 0x01, 0x01,
7575
0x00, 0x04, 0x0a, 0x02, 0x62, 0x00, 0x4d, 0x30,
7676
0x00,
7777
};

0 commit comments

Comments
 (0)