Created
August 8, 2011 17:01
-
-
Save ardcore/1132193 to your computer and use it in GitHub Desktop.
detect globals looped
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
// this code sux. | |
(function() { | |
function getKeys(object) { | |
var keys = []; | |
for (var key in object) { | |
if (!key.match(/^_Firebug/)) { | |
keys.push(key); | |
} | |
} | |
return keys; | |
} | |
var poiobj = getKeys(window).sort(); | |
console.log("initial global variables: ", poiobj); | |
var tim = setInterval( function() { | |
var winobj = getKeys(window).sort(); | |
if (winobj.length > poiobj.length) { | |
for (var i = 0; i < winobj.length;) { | |
if (winobj[i] != poiobj[i]) { | |
console.log("Warning, global poisoned with variable: " + winobj[i]); | |
winobj.splice(i, 1); | |
continue; | |
}; | |
i++; | |
} | |
poiobj = getKeys(window).sort(); | |
} else if (winobj.length < poiobj.length) { | |
console.log("strange stuff"); | |
for (var i = 0; i < poiobj.length;) { | |
if (winobj[i] != poiobj[i]) { | |
console.log("Non-indexed global (possible leak from extension?): " +poiobj[i]); | |
poiobj.splice(i, 1); | |
}; | |
i++; | |
} | |
clearInterval(tim); | |
} | |
}, 200) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment