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
30 lines (28 loc) • 1.29 kB
text/typescript
import { compare, assertResult } from '../util';
const operators = ['+=', '-=', '*=', '/=', '%=', '**=', '<<=', '>>=', '>>>=', '^=', '&='];
// const specialOps = ['in' , 'instanceof'];
describe('CompoundAssignment', () => {
it('should assign to identifiers', () => {
const sample = [2, 120, 1981, '2', 'hi', NaN, true, false, 1 / 0];
const results = operators.flatMap(op =>
sample.flatMap(l => sample.map(r => compare(`let b = ${JSON.stringify(l)}; b ${op} ${JSON.stringify(r)}`))),
);
results.forEach(result => assertResult(result));
});
it('should assign to static members', () => {
const sample = [2, 120, 1981, '2', 'hi', NaN, true, false, 1 / 0];
const results = operators.flatMap(op =>
sample.flatMap(l => sample.map(r => compare(`let b = {a:${JSON.stringify(l)}}; b.a ${op} ${JSON.stringify(r)}`))),
);
results.forEach(result => assertResult(result));
});
it('should assign to computed members', () => {
const sample = [2, 120, 1981, '2', 'hi', NaN, true, false, 1 / 0];
const results = operators.flatMap(op =>
sample.flatMap(l =>
sample.map(r => compare(`let b = {["a"]:${JSON.stringify(l)}}; b["a"] ${op} ${JSON.stringify(r)}`)),
),
);
results.forEach(result => assertResult(result));
});
});