Skip to content

Commit 764939e

Browse files
test(insta-bytecode): cover try/finally jump-table fallthrough
Add a bytecode snapshot test exercising a loop with a try/finally whose finally runs while a break/continue is only syntactically present in the try. The snapshot pins the emitted N+1 entry jump table, with entry 0 reserved as the fallthrough target reached by the jump emitted right after the table, guarding against a regression of the #5369 fix.
1 parent 1fdef75 commit 764939e

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Regression test for the try/finally jump table (see PR #5381 / issue #5369).
2+
// A `break`/`continue` that is syntactically present but not executed inside a
3+
// `try` whose `finally` runs must fall through past the jump table instead of
4+
// being taken once the finally completes. The emitted table reserves entry 0
5+
// for this fallthrough case.
6+
let total = 0;
7+
for (let i = 0; i < 5; ++i) {
8+
try {
9+
if (i === 2) continue;
10+
if (i === 4) break;
11+
} finally {
12+
total += i;
13+
}
14+
total += 100;
15+
}
16+
total;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
source: tests/insta-bytecode/src/lib.rs
3+
expression: output
4+
input_file: tests/insta-bytecode/scripts/try-finally.js
5+
---
6+
-------------------------- Compiled Output: '<main>' ---------------------------
7+
Location Handler Opcode Operands
8+
000000 StoreZero dst:r01
9+
000005 PutLexicalValue src:r01, binding_index:0
10+
00000e StoreZero dst:r02
11+
000013 StoreInt8 value:5, dst:r03
12+
000019 Jump address:000028
13+
00001e IncrementLoopIteration
14+
00001f Inc src:r02, dst:r02
15+
000028 JumpIfNotLessThan lhs:r02, rhs:r03, address:000147
16+
000035 StoreTrue dst:r04
17+
00003a StoreZero dst:r05
18+
00003f > 0: 0000aa StoreInt8 value:2, dst:r07
19+
000045 0: 0000aa StrictEq lhs:r02, rhs:r07, dst:r06
20+
000052 0: 0000aa JumpIfFalse value:r06, address:00006f
21+
00005b 0: 0000aa StoreFalse dst:r04
22+
000060 0: 0000aa StoreOne dst:r05
23+
000065 0: 0000aa Jump address:0000b9
24+
00006a 0: 0000aa Jump address:00006f
25+
00006f 0: 0000aa StoreInt8 value:4, dst:r07
26+
000075 0: 0000aa StrictEq lhs:r02, rhs:r07, dst:r06
27+
000082 0: 0000aa JumpIfFalse value:r06, address:0000a0
28+
00008b 0: 0000aa StoreFalse dst:r04
29+
000090 0: 0000aa StoreInt8 value:2, dst:r05
30+
000096 0: 0000aa Jump address:0000b9
31+
00009b 0: 0000aa Jump address:0000a0
32+
0000a0 0: 0000aa StoreFalse dst:r04
33+
0000a5 < 0: 0000aa Jump address:0000b9
34+
0000aa > 1: 0000b9 Exception dst:r06
35+
0000af 1: 0000b9 StoreTrue dst:r04
36+
0000b4 < 1: 0000b9 Jump address:0000b9
37+
0000b9 SetRegisterFromAccumulator dst:r07
38+
0000be GetName dst:r08, binding_index:0
39+
0000c7 Move src:r02, dst:r09
40+
0000d0 Add lhs:r08, rhs:r09, dst:r08
41+
0000dd SetName src:r08, binding_index:0
42+
0000e6 SetAccumulator src:r07
43+
0000eb JumpIfFalse value:r04, address:0000f9
44+
0000f4 Throw src:r06
45+
0000f9 JumpTable index:5, jump_table:(00011d, 000113, 000118)
46+
00010e Jump address:00011d
47+
000113 Jump address:00001e
48+
000118 Jump address:000147
49+
00011d GetName dst:r04, binding_index:0
50+
000126 StoreInt8 value:100, dst:r05
51+
00012c Add lhs:r04, rhs:r05, dst:r04
52+
000139 SetName src:r04, binding_index:0
53+
000142 Jump address:00001e
54+
000147 GetName dst:r03, binding_index:0
55+
000150 SetAccumulator src:r03
56+
000155 CheckReturn
57+
000156 Return
58+
59+
Register Count: 10, Flags: CodeBlockFlags(HAS_PROTOTYPE_PROPERTY)
60+
Constants:
61+
0000: [STRING] "total"
62+
Bindings:
63+
0000: total, scope: GlobalDeclarative
64+
Handlers:
65+
0000: Range: [00003f, 0000aa): Handler: 0000aa, Environment: 00
66+
0001: Range: [0000aa, 0000b9): Handler: 0000b9, Environment: 00
67+
Source Map:
68+
0000: 31..190: (7, 24)
69+
0001: 190..285: (12, 9)
70+
0002: 285..322: (14, 5)

0 commit comments

Comments
 (0)