Created
September 19, 2010 19:07
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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