function prepareTests(codes) {
var _success = 0;
var _result = document.getElementById('result');
var _total = codes.length;
return function runTests() {
codes = codes || codes;
if (!codes.length) {
_result.innerHTML += _success + ' on ' + _total + ' tests succeed';
return;
}
window.hack = false;
var code = codes.shift();
try {
sandbox(code);
}
catch(e) {
console.log(code, e);
}
// Wait to get result
setTimeout(function(){
_success += (window.hack ? 0 : 1);
_result.innerHTML += '[SUCCESS]' : 'red">[FAILED]') + ' ' + code + '
';
runTests(codes);
}, 20);
};
};
var runTests = prepareTests([
'hack = true;',
'window.hack = true;',
'this.hack = true;',
'self.hack = true;',
'(function(){ hack = true })();',
'(function(){ this.hack = true })();',
'(function(){ self.hack = true })();',
'(function(){ window.hack = true })();',
'new Function("hack = true").call();',
'new Function("this.hack = true").call();',
'new Function("self.hack = true").call();',
'new Function("window.hack = true").call();',
'new Function("hack = true").call(window);',
'new Function("this.hack = true").call(window);',
'new Function("self.hack = true").call(window);',
'new Function("window.hack = true").call(window);',
'setTimeout("hack = true", 10);',
'setTimeout("this.hack = true", 10);',
'setTimeout("self.hack = true", 10);',
'setTimeout("window.hack = true", 10);',
'setTimeout(function(){ hack = true }, 10);',
'setTimeout(function(){ this.hack = true }, 10);',
'setTimeout(function(){ self.hack = true }, 10);',
'setTimeout(function(){ window.hack = true }, 10);',
'var c = setInterval("clearInterval(c); hack = true", 10);',
'var c = setInterval("clearInterval(c); this.hack = true", 10);',
'var c = setInterval("clearInterval(c); self.hack = true", 10);',
'var c = setInterval("clearInterval(c); window.hack = true", 10);',
'var c = setInterval(function(){ clearInterval(c); hack = true }, 10);',
'var c = setInterval(function(){ clearInterval(c); this.hack = true }, 10);',
'var c = setInterval(function(){ clearInterval(c); self.hack = true }, 10);',
'var c = setInterval(function(){ clearInterval(c); window.hack = true }, 10);',
'requestAnimationFrame(function(){ hack = true });',
'requestAnimationFrame(function(){ this.hack = true });',
'requestAnimationFrame(function(){ self.hack = true });',
'requestAnimationFrame(function(){ window.hack = true });',
'var f = function(){}; f.constructor("hack = true")();',
'File.constructor("hack = true")();',
'var d = (new Image()).ownerDocument;\
var s = d.createElement("script");\
s.innerHTML = "hack = true";\
d.body.appendChild(s);',
'var d = (new Audio()).ownerDocument;\
var s = d.createElement("script");\
s.innerHTML = "hack = true";\
d.body.appendChild(s);',
'(new Image()).ownerDocument.defaultView.hack = true;',
'(new Audio()).ownerDocument.defaultView.hack = true;',
'result.ownerDocument.defaultView.hack = true;'
]);