UNPKG

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 (37 loc) 1 kB
import { describe } from 'mocha'; import { assertResult, compare } from '../util'; describe('new', () => { it('should instantiate functions and retain prototype chain', () => { assertResult( compare(` function d() {} d.prototype.run = function () {return "expected"}; d.prototype.run(); const a = new d(); a.run(); `), ); }); it('should return the return value for an instantiated function if the fn returns', () => { assertResult( compare(` function d() { return { run() {return 'this one'}}; } d.prototype.run = function () {return "not this one"}; d.prototype.run(); const a = new d(); a.run(); `), ); }); it('should still return the "this" if a primitive is returned', () => { assertResult( compare(` function d() { return 2; } d.prototype.run = function () {return "expected"}; d.prototype.run(); const a = new d(); a.run(); `), ); }); });