Skip to content

Instantly share code, notes, and snippets.

@mrfabbri
Created September 19, 2010 19:07
Show Gist options
  • Save mrfabbri/587029 to your computer and use it in GitHub Desktop.
Save mrfabbri/587029 to your computer and use it in GitHub Desktop.
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