JavaScript Toolkit

I would like to use JavaScript code to "register" the values ​​of global variables. For example, I would like to know all the values ​​that were determined by specific foo variables at runtime. Recording is not a problem.

What would be the easiest way to do this? I was thinking of using Rhino (a JavaScript implementation in Java created by Mozilla) to create an AST and modifying that AST.

+2


source to share


7 replies


Using the Rhino version of cvshead, I measured the code.



0


source


This might be what you are looking for:

http://ejohn.org/blog/javascript-getters-and-setters/

Put the log into the installer and that's it. Of course, I don't know where this actually works, if it should be trusted code or any web page or what.

Based on John Resig's code, I would add something like this to my debug code:

var placeLoggerInSetter = function(variableName, obj){ //obj may be window
    obj.__defineSetter__(variableName, function(val){
         console.log(val); //log whatever here
         obj[variableName] = val;
    });
}

var something = 0;
placeLoggerInSetter("something", window);
something = 1;
//out goes "1" in the console
something = 2
//out goes "2" in the console

      



Is it more like this? Again, I haven't tested it and the line obj[variableName]

looked pretty recursive to me ... can you tell me here if it works? :)

Also, Firebug ,

console.dir(obj)

      

will allow you to see all the properties of that object in the console, instead of converting it to a string like in log()

. And also expand properties and so on. Handy.

+1


source


If you're not limited to Rhino / Java, the Johnson Ruby gem integrates the Spidermonkey / Tracemonkey interpreter into Ruby. It provides access to the ACT. I have not tried modifying AST; not sure if this is possible (it might be, judging by the names in the code when looking at it).

Pearl Johnson is in the jbarnette Johnson repo on github. (Switch id, Stackoverflow doesn't want me to insert links at this point ...) I recently added tracemonkey support and is not yet integrated into the main source. This is in my (smparkes) Johnson repo on github.

+1


source


Firebug (plugin for firefox) has a logging feature that you can write to the console with. Much better than using alert ("foo"); for everything

Example log:

console.log("foo="+foo);

      

See this post for more information (including more advanced usage)

0


source


I have no idea what general solution or anything exists, but just wrap these variables around the log class that deals with get / sets etc.

0


source


0


source


You can install a debugger; as the first thing in the document readiness event and step by step step by step.

.. Fredrik

0


source







All Articles