Fix the last problem with setTimeout and setInterval

1.2
IceArmy 2011-06-19 21:18:14 -07:00
parent 1fb67c49e7
commit 3d0c56af40
2 changed files with 66 additions and 0 deletions

View File

@ -75,6 +75,39 @@ window.WebPage = function() {
return page;
}
// override settimeout/setinterval with a try..catch
window._setTimeout = window.setTimeout;
window._setInterval = window.setInterval;
window.setTimeout = function(func, delay) {
var f = function() {
try {
typeof func === 'function' ? func() : eval(func);
} catch (err) {
if (err !== 'phantom.exit') {
throw err;
}
}
}
return window._setTimeout(f, delay);
}
window.setInterval = function(func, delay, lang) {
var f = function() {
try {
typeof func === 'function' ? func() : eval(func);
} catch (err) {
if (err !== 'phantom.exit') {
throw err;
}
}
}
return window._setInterval(f, delay, lang);
}
phantom.exit = function(code) {
if (code == null) {
code = 0;

View File

@ -75,6 +75,39 @@ window.WebPage = function() {
return page;
}
// override settimeout/setinterval with a try..catch
window._setTimeout = window.setTimeout;
window._setInterval = window.setInterval;
window.setTimeout = function(func, delay) {
var f = function() {
try {
typeof func === 'function' ? func() : eval(func);
} catch (err) {
if (err !== 'phantom.exit') {
throw err;
}
}
}
return window._setTimeout(f, delay);
}
window.setInterval = function(func, delay, lang) {
var f = function() {
try {
typeof func === 'function' ? func() : eval(func);
} catch (err) {
if (err !== 'phantom.exit') {
throw err;
}
}
}
return window._setInterval(f, delay, lang);
}
phantom.exit = function(code) {
if (code == null) {
code = 0;