Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A web worker used to offload evaluation (by means of an "evil eval") of some JavaScript code written inside the browser. A very quick and dirty hack.
<html>
<head>
<title>
</title>
<style>
#input-area{
width: 400px;
height: 400px;
margin: 10px;
}
#output-area{
width: 400px;
height: 100px;
margin: 10px;
}
</style>
<script>
var evalWorker;
initEvalWorker();
function initEvalWorker()
{
evalWorker = new Worker("./evilevalworker.js");
evalWorker.addEventListener('message', function(event)
{
document.getElementById("output-area").textContent = event.data;
}, false);
}
function stop()
{
evalWorker.terminate();
initEvalWorker();
}
function rep()
{
evalWorker.postMessage(document.getElementById("input-area").value);
}
</script>
</head>
<body>
<button type="button" onclick="rep();">EVAL</button>
<button type="button" onclick="stop();">STOP</button>
<div>
<textarea id="input-area"></textarea>
</div>
<div id="output-area">
</div>
</body>
</html>
onmessage = function (event)
{
postMessage(eval(event.data));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.