shift-interpreter
Version:
Shift-interpreter is an experimental JavaScript meta-interpreter useful for reverse engineering and analysis. One notable difference from other projects is that shift-interpreter retains state over an entire script but can be fed expressions and statement
40 lines (38 loc) • 814 B
text/typescript
import { assertResult, compare } from '../util';
const operators = [
'==',
'!=',
'===',
'!==',
'<',
'<=',
'>',
'>=',
'<<',
'>>',
'>>>',
'+',
'-',
'*',
'/',
'%',
'**',
',',
'&&',
',',
'^',
'&',
];
// const specialOps = ['in' , 'instanceof'];
describe('BinaryExpressions', () => {
it('should evaluate operators the same as the host environment', () => {
const sample = [2, 120, 1981, '2', 'hi', NaN, true, false, 1 / 0];
const results = operators.flatMap(op =>
sample.flatMap(l => sample.map(r => compare(`${JSON.stringify(l)} ${op} ${JSON.stringify(r)}`))),
);
results.forEach(result => assertResult(result));
});
it('should retain shortcircuit behavior', () => {
assertResult(compare(`typeof x == 'string' && nonexistant()`));
});
});