title: "Decompile" Javascript function?
body: <p>[1] Ok, I don't even know how to call this, to be honest. So let me get some semi-pseudo code, to show what I'm trying to do. I'm using jQuery to get an already existing script declared inside the page, inside a <code>createDocument()</code> element, from an AJAX call.</p>
  
  <pre>
  GM_xmlhttprequest({
    ...
    load:function(r){
      var doc = document_from_string(r.responseText);
      script_content = $('body script:regex(html, local_xw_sig)', doc).html();
      var scriptEl = document.createElement('script');
      scriptEl.type = 'text/javascript';
      scriptEl.innerHTML = script_content; // good till here
      (function(sc){
        eval(sc.innerHTML); // not exactly like this, but you get the idea, errors
        alert('wont get here ' + local_xw_sig); // local_xw_sig is a global "var" inside the source
      })(scriptEl);
    }
  });
  </pre>
  
  <p>So far so good, the script indeed contains the source from the entire script block. Now, inside this "script_content", there are auto executing functions, like $(document).ready(function(){...}) that, everything I "eval" the innerHTML, it executes this code, halting my encapsulated script. Like variables that doesn't exist, etc.</p>
  
  <p>Removing certain parts of the script using regex isn't really an option... what I really wanted is to "walk" inside the function. like do a (completely fictional):</p>
  
  <pre>
  script = eval("function(){" + script_content + "};");
  alert(script['local_xw_sig']); // a03ucc34095cw3495
  </pre>
  
  <p>Is there any way to 'disassemble' the function, and be able to reach the "var"s inside of it?
  like this function:</p>
  
  <pre>
  function hello(){
    var message = "hello";
  }
  alert(hello.message); // message = var inside the function
  </pre>
  
  <p>Is it possible at all? Or I will have to hack my way using regex? ;P</p>
  
  <p>[2] also, is there any way I can access javascript inside a document created with "createDocument"?</p>