Skip to content

Instantly share code, notes, and snippets.

@Spongman
Created August 3, 2018 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spongman/446af67ab242019965cc6499d90d9f56 to your computer and use it in GitHub Desktop.
Save Spongman/446af67ab242019965cc6499d90d9f56 to your computer and use it in GitHub Desktop.
window.fr = function(o) {
var m = new Map();
var rg = [{ pn: 'window', v: window, l: 0 }];
function add(pc) {
var p = pc.v;
var l = pc.l + 1;
for (var pn of Object.getOwnPropertyNames(p)) {
try {
var pd = Object.getOwnPropertyDescriptor(p, pn);
//if (pd.get) continue;
//console.log(pn, pd);
var v = pd.hasOwnProperty('value') ? pd.value : p[pn];
if (v == null) continue;
var c = m.get(v);
if (!c || pc.l < c.l) {
var nc = { p: pc, pn: pn, v: v, l: l };
if (!c)
rg.push(nc);
m.set(v, nc);
if (v === o) {
var rg2 = [];
for (var pp = nc; pp; pp = pp.p)
rg2.push(pp.pn);
console.log(rg2.reverse().join('.'));
}
}
}
catch { }
}
}
while (rg.length) {
add(rg.pop());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment