I’ll make it short:
I want to enum all available functions and objects inside of window object for creating some kind of object reflection code.
it runs just fine in every browser but in Firefox.
here is my pseudo loop code:
var all_names=[];
for (var i in window)
{
//if it's NOT an object
all_name.push(i.toString());
//if it's an object
enum up to 3 more levels in child objects.
}
And I don’t want to use available APIs in Firefox such as getOwnPropertyNames.
So, what should I do? is there any better solution for enumeration in Javascript (cross-browser of course)
Here is some more technical info:
Exact Firefox error:
[20:48:04.539] uncaught exception: [Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location: "http://localhost/test/common.js Line: 53"]
Exact enum loop code:
function reflectAsString() {
try{
var m1 = "";
var m2 = "";
var m3 = "";
for (var i in window) {
if(window[i] && window[i]!= null && window[i] != "globalStorage")
{
m1 += i;
first_instance = window[i];
if(typeof first_instance == "object")
{
for(var j in first_instance)
{
if(first_instance[j] && first_instance[j]!= null)
{
m2 += j;
second_instance = first_instance[j];
if(typeof second_instance == "object")
{
for (var k in second_instance)
{
if(second_instance[k] && second_instance[k]!= null)
{
m3 += k;
}
}
}
}
}
}
}
}
return hex_md5(hex_md5(m1)+hex_md5(m2)+hex_md5(m3));
} catch(e) {
try {
var strToHash = Object.getOwnPropertyNames(window).filter(function(property) {
return typeof window[property] == 'function';
});
return hex_md5(strToHash.toString());
} catch(e2) {
return "undef";
}
}
}
I have done something similar by opening an iframe on the page I am interested in, and comparing the globals in the iframe’s window with those in the parent window.
The try block will return the property name with an error flag, if there are any errors.
HTML for iframe src: