Skip to content

Instantly share code, notes, and snippets.

@DavidBruant
Created September 18, 2013 10:07
Show Gist options
  • Save DavidBruant/6607096 to your computer and use it in GitHub Desktop.
Save DavidBruant/6607096 to your computer and use it in GitHub Desktop.
var win = gBrowser.selectedBrowser.contentWindow;
var console = win.console;
var P = Object.getPrototypeOf;
Components.utils.import("resource://gre/modules/jsdebugger.jsm").addDebuggerToGlobal(this);
//console.log(Debugger)
var dbg = new Debugger();
var dbgwin = dbg.addDebuggee(win)
//console.log(dbgwin)
var code = "(function(global){ var secret = Math.random(); window.whatever = function(){ var a = Math.random(); debugger; return String(secret+a)[5] } })(window);";
var envInsideCall;
dbg.onDebuggerStatement = function(){
envInsideCall = dbgwin.getOwnPropertyDescriptor('whatever').value.environment;
console.log('envInsideCall at debugger statement', envInsideCall.names(), envInsideCall.getVariable('secret'), envInsideCall.getVariable('a'));
}
dbgwin.getOwnPropertyDescriptor('eval').value.call(undefined, code);
envOutsideCall = dbgwin.getOwnPropertyDescriptor('whatever').value.environment;
dbgwin.getOwnPropertyDescriptor('whatever').value.call()
console.log("same env?", envInsideCall, envOutsideCall, envInsideCall === envOutsideCall)
console.log(envInsideCall.names(), envInsideCall.getVariable('secret'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment