0

Is there a way to list all variables in the global and in the current scope (at realtime execution)? I tried to simply loop over the variables in a recursive manner.

function recursion(variable_name){for (var property in variable_name){recursion(property)}}

I get the Error:

JavaScript: Too much recursion

Besides the error, this should usually list the global variables.

My goal is, to just store all variables and subvariables the JavaScript Interpreter encounters, and scan them for changes or absolut value in order to easily find the global or private variable name I was looking.

killertoge
  • 333
  • 1
  • 4
  • 13
  • You're mixing context and scope. You can't list variables in a scope (excluding the global scope). If you're talking about listing properties of an object, you can take a look at [this answer](https://stackoverflow.com/a/11922384/1169519). – Teemu Mar 28 '21 at 11:30
  • This is what I do. I take the "this" variable and now loop over the objects properties, the properties properties, ... . I thought with this way I atleast get all global objects listed. And what I mean with current scope is: The JavaScript executes functions, and those functions define temporary variables, and I want to list these too. My other idea was to just take the source-code and give every variable a unique identifier and turn everything global. – killertoge Mar 28 '21 at 11:37
  • You can't access local variables declared in functions from outside of the functions, because those variables exist only during the function is executing. I'm not sure what exactly you need, maybe you should search for _javascript AST_. – Teemu Mar 28 '21 at 11:41
  • Yes, I really think there is no way than dealing with static analysis over the source-code to solve my problem. I aimed for real-time execution and listing every variable I encounter (thats why I used the word context). I'm dealing with obfuscated code, where I assume, there is an event triggered and a function gets called with these (x,y) values, which I couldn't manually find in the global variables. So these are used temporary in a function. My overall goal was to find the variable name that processes (x,y) and to modify the source-code to log these values whenever used in this function. – killertoge Mar 28 '21 at 12:01

0 Answers0