JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdn.rawgit.com/maierfelix/Iroh/b84dde46/dist/iroh-browser.js"></script>
<div id="code">
function main() {
return 42;
};
console.log(
main, // the patched, running code
main.toString() // the original code
);
</div>
CSS
#code {
display: none;
}
JavaScript
let stage = new Iroh.Stage(code.textContent);
let listener = stage.addListener(Iroh.CALL)
listener.on("before", (e) => {
if (
e.object instanceof Function &&
e.call === Function.toString
) {
let node = stage.getFunctionNodeByName(e.object.name);
let code = stage.input.substr(node.start, node.end - node.start);
e.call = () => code;
}
});
eval(stage.script);