-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_interface_static_methods.js
More file actions
83 lines (63 loc) · 3.05 KB
/
Copy pathtest_interface_static_methods.js
File metadata and controls
83 lines (63 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env node
/**
* Test to verify that interface static method calls are parsed correctly.
* This addresses the bug where jvm_parser fails with TypeError when parsing
* class files containing calls to interface static methods.
*/
const fs = require('fs');
const { getAST, getDisassembled } = require('./lib');
function test_interface_static_methods() {
console.log('Testing interface static method parsing...\n');
try {
// Test with MinimalBug.class (contains interface static method call)
console.log('✓ Testing MinimalBug.class (interface static method call)...');
const minimalBugBytes = fs.readFileSync('MinimalBug.class');
const minimalBugAST = getAST(minimalBugBytes);
if (!minimalBugAST.ast) {
throw new Error('AST is missing');
}
if (!minimalBugAST.ast.methods || minimalBugAST.ast.methods.length === 0) {
throw new Error('Methods are missing from MinimalBug AST');
}
console.log(` - Found ${minimalBugAST.ast.methods.length} method(s)`);
// Find the main method and check that it has bytecode
const mainMethod = minimalBugAST.ast.methods.find(m => m.name === 'main');
if (!mainMethod) {
throw new Error('main method not found');
}
console.log(' - Found main method');
// Check that main method has code with instructions
if (!mainMethod.code || !mainMethod.code.instructions) {
throw new Error('main method missing code or instructions');
}
console.log(` - main method has ${mainMethod.code.instructions.length} instruction(s)`);
// Look for the invokestatic instruction that calls the interface method
const invokeStaticInstr = mainMethod.code.instructions.find(instr =>
instr.opcode === 184 && instr.comment && instr.comment.includes('doSomething')
);
if (!invokeStaticInstr) {
throw new Error('Expected invokestatic instruction calling doSomething not found');
}
console.log(' - Found invokestatic instruction with interface method call');
console.log(` - Instruction comment: ${invokeStaticInstr.comment}`);
// Test that we can also generate disassembled output
console.log('✓ Testing disassembly of interface static method call...');
const disassembled = getDisassembled(minimalBugBytes);
if (!disassembled.includes('doSomething')) {
throw new Error('Disassembled output does not contain interface method name');
}
console.log(' - Disassembly successful');
console.log('\n🎉 Interface static method parsing test passed!');
return true;
} catch (error) {
console.error('\n❌ Interface static method parsing test failed:', error.message);
throw error;
}
}
// Run the test
try {
test_interface_static_methods();
process.exit(0);
} catch (error) {
process.exit(1);
}