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
29 lines • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("../util");
const operators = [
'+',
'-',
'!',
'~',
'typeof',
'void',
];
// const specialOps = ['in' , 'instanceof'];
describe('UnaryExpressions', () => {
it('should evaluate operators the same as the host environment', () => {
const operands = [2, 120, 1981, '2', 'hi', NaN, true, false, {}, 1 / 0];
const results = operators.flatMap(op => operands.map(oper => util_1.compare(`${op} ${JSON.stringify(oper)}`)));
results.forEach(result => util_1.assertResult(result));
});
it('should evaluate typeof on an undeclared variable', () => {
util_1.assertResult(util_1.compare(`typeof foo`));
});
it('should propagate thrown errors', () => {
util_1.assertResult(util_1.compare(`try {!(() => n++)();'bad';} catch (e) {'good';}`));
});
it('should not swallow continues/breaks', () => {
util_1.assertResult(util_1.compare(`do{if(!null)continue; nonexistant();}while(i = 0);i`));
});
});
//# sourceMappingURL=unary-expressions.test.js.map