@flighthq/abc 0.5.1-next.973.788d3d7 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/abcFile.d.ts +1 -1
- package/dist/abcFile.d.ts.map +1 -1
- package/dist/abcFile.js +1 -1
- package/dist/abcFile.js.map +1 -1
- package/dist/abcInstruction.d.ts +1 -1
- package/dist/abcInstruction.d.ts.map +1 -1
- package/dist/abcInstruction.js +1 -1
- package/dist/abcInstruction.js.map +1 -1
- package/dist/contract.d.ts +3 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +3 -2
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +296 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +194 -0
- package/dist/types.js.map +1 -0
- package/package.json +4 -5
- package/src/abcFile.test.ts +205 -201
- package/src/abcInstruction.test.ts +39 -62
|
@@ -1,77 +1,54 @@
|
|
|
1
|
-
|
|
1
|
+
// Generated from crates/flight-abc/tests/abc_instruction_test.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const instructions = readAbcInstructions(new Uint8Array([0xd0, 0x30, 0x47]));
|
|
6
|
+
import { AbcOpcode, readAbcInstructions } from './contract.ts';
|
|
7
|
+
import type { AbcInstruction } from './contract.ts';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{ offset: 2, opcode: AbcOpcode.ReturnVoid, operands: [] },
|
|
13
|
-
]);
|
|
9
|
+
describe('readAbcInstructions', () => {
|
|
10
|
+
it('decodes an empty body as no instructions', () => {
|
|
11
|
+
expect(readAbcInstructions(new Uint8Array([]))).toEqual([] as never[]);
|
|
14
12
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
expect(instructions).toEqual([
|
|
21
|
-
{ offset: 0, opcode: AbcOpcode.FindPropStrict, operands: [5] },
|
|
22
|
-
{ offset: 2, opcode: AbcOpcode.PushByte, operands: [2] },
|
|
23
|
-
{ offset: 4, opcode: AbcOpcode.CallPropVoid, operands: [5, 1] },
|
|
13
|
+
it('decodes constructor prologue', () => {
|
|
14
|
+
expect(readAbcInstructions(new Uint8Array([0xd0, 0x30, 0x47]))).toEqual([
|
|
15
|
+
{ offset: 0, opcode: AbcOpcode.GetLocal0 & 0xff, operands: [] },
|
|
16
|
+
{ offset: 1, opcode: AbcOpcode.PushScope & 0xff, operands: [] },
|
|
17
|
+
{ offset: 2, opcode: AbcOpcode.ReturnVoid & 0xff, operands: [] },
|
|
24
18
|
]);
|
|
25
19
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
expect(
|
|
30
|
-
|
|
20
|
+
it('places deprecated typed coerce forms', () => {
|
|
21
|
+
const instructions = readAbcInstructions(new Uint8Array([0x81, 0x83, 0x84, 0x88, 0x89, 0x47]))!;
|
|
22
|
+
expect(instructions.map((value) => value.opcode)).toEqual([0x81, 0x83, 0x84, 0x88, 0x89, 0x47]);
|
|
23
|
+
expect(instructions.every((value) => value.operands.length === 0)).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
it('reads a lookup switch with one more target than case count', () => {
|
|
26
|
+
expect(
|
|
27
|
+
readAbcInstructions(new Uint8Array([0x1b, 0x07, 0x00, 0x00, 0x01, 0x0a, 0x00, 0x00, 0x0d, 0x00, 0x00])),
|
|
28
|
+
).toEqual([{ offset: 0, opcode: AbcOpcode.LookupSwitch & 0xff, operands: [7, 1, 10, 13] }]);
|
|
29
|
+
});
|
|
30
|
+
it('reads call site operand shapes including two operand calls', () => {
|
|
31
|
+
expect(readAbcInstructions(new Uint8Array([0x5d, 0x05, 0x24, 0x02, 0x4f, 0x05, 0x01]))).toEqual([
|
|
32
|
+
{ offset: 0, opcode: AbcOpcode.FindPropStrict & 0xff, operands: [5] },
|
|
33
|
+
{ offset: 2, opcode: AbcOpcode.PushByte & 0xff, operands: [2] },
|
|
34
|
+
{ offset: 4, opcode: AbcOpcode.CallPropVoid & 0xff, operands: [5, 1] },
|
|
31
35
|
]);
|
|
32
36
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
it('reports a truncated operand', () => {
|
|
38
|
+
expect(readAbcInstructions(new Uint8Array([0x4f, 0x05])) === null).toBe(true);
|
|
39
|
+
expect(readAbcInstructions(new Uint8Array([0x10, 0xfc])) === null).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it('sign extends a backward branch target', () => {
|
|
36
42
|
expect(readAbcInstructions(new Uint8Array([0x10, 0xfc, 0xff, 0xff]))).toEqual([
|
|
37
|
-
{ offset: 0, opcode: AbcOpcode.Jump, operands: [-4] },
|
|
43
|
+
{ offset: 0, opcode: AbcOpcode.Jump & 0xff, operands: [-4] },
|
|
38
44
|
]);
|
|
39
45
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// default +7, case count 1, then two targets.
|
|
43
|
-
const instructions = readAbcInstructions(
|
|
44
|
-
new Uint8Array([0x1b, 0x07, 0x00, 0x00, 0x01, 0x0a, 0x00, 0x00, 0x0d, 0x00, 0x00]),
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
expect(instructions).toEqual([{ offset: 0, opcode: AbcOpcode.LookupSwitch, operands: [7, 1, 10, 13] }]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('stops rather than guessing when an opcode is not one the format defines', () => {
|
|
51
|
-
// There is no way to resynchronize a variable-width stream after an unknown opcode, so returning a
|
|
52
|
-
// partial decode would be returning plausible nonsense.
|
|
53
|
-
expect(readAbcInstructions(new Uint8Array([0xd0, 0xff, 0x47]))).toBeNull();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('reports a truncated operand rather than reading past the body', () => {
|
|
57
|
-
expect(readAbcInstructions(new Uint8Array([0x4f, 0x05]))).toBeNull();
|
|
58
|
-
expect(readAbcInstructions(new Uint8Array([0x10, 0xfc]))).toBeNull();
|
|
46
|
+
it('stops on an undefined opcode', () => {
|
|
47
|
+
expect(readAbcInstructions(new Uint8Array([0xd0, 0xff, 0x47])) === null).toBe(true);
|
|
59
48
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// the walk then reads the following opcode as an operand.
|
|
64
|
-
expect(readAbcInstructions(new Uint8Array([0x81, 0x83, 0x84, 0x88, 0x89, 0x47]))).toEqual([
|
|
65
|
-
{ offset: 0, opcode: AbcOpcode.CoerceBoolean, operands: [] },
|
|
66
|
-
{ offset: 1, opcode: AbcOpcode.CoerceInt, operands: [] },
|
|
67
|
-
{ offset: 2, opcode: AbcOpcode.CoerceDouble, operands: [] },
|
|
68
|
-
{ offset: 3, opcode: AbcOpcode.CoerceUint, operands: [] },
|
|
69
|
-
{ offset: 4, opcode: AbcOpcode.CoerceObject, operands: [] },
|
|
70
|
-
{ offset: 5, opcode: AbcOpcode.ReturnVoid, operands: [] },
|
|
49
|
+
it('widens a multi byte variable length operand', () => {
|
|
50
|
+
expect(readAbcInstructions(new Uint8Array([0x2d, 0x81, 0x01]))).toEqual([
|
|
51
|
+
{ offset: 0, opcode: AbcOpcode.PushInt & 0xff, operands: [129] },
|
|
71
52
|
]);
|
|
72
53
|
});
|
|
73
|
-
|
|
74
|
-
it('decodes an empty body as no instructions', () => {
|
|
75
|
-
expect(readAbcInstructions(new Uint8Array())).toEqual([]);
|
|
76
|
-
});
|
|
77
54
|
});
|