Created
March 15, 2018 20:57
-
-
Save dawsontoth/7285ae367a32206db93e238b49e172d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function getStackTrace() { | |
let obj = {}; | |
Error.captureStackTrace(obj, getStackTrace); | |
return obj.stack; | |
} | |
window.activeFuncs = {}; | |
window.originalSetTimeout = window.setTimeout; | |
window.originalClearTimeout = window.clearTimeout; | |
window.originalSetInterval = window.setInterval; | |
window.originalClearInterval = window.clearInterval; | |
window.setTimeout = function(func, delay) { | |
let id, | |
wrapper = () => { | |
delete window.activeFuncs['timeout' + id]; | |
func.apply(window); | |
}; | |
id = window.originalSetTimeout(wrapper, delay); | |
if (func) { | |
window.activeFuncs['timeout' + id] = getStackTrace(); | |
} | |
return id; | |
}; | |
window.clearTimeout = function(timerID) { | |
window.originalClearTimeout(timerID); | |
delete window.activeFuncs['timeout' + timerID]; | |
}; | |
window.setInterval = function(func, delay) { | |
let id = window.originalSetInterval(func, delay); | |
if (func) { | |
window.activeFuncs['interval' + id] = getStackTrace(); | |
} | |
return id; | |
}; | |
window.clearInterval = function(intervalID) { | |
delete window.activeFuncs['interval' + intervalID]; | |
return window.originalClearInterval(intervalID); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment