patriksimek / vm2

Advanced vm/sandbox for Node.js
MIT License
3.86k stars 293 forks source link

Extract declared variables name and values from vm #501

Closed dorbenzvi closed 1 year ago

dorbenzvi commented 1 year ago

Hi, First of all, this package is awesome, thanks!

I need a way to extract all the declared variables in the global scope of the evalulated code. The is a way to extract the variable names and values outside from the vm?

for exmaple: const hello = 'world' const array = [1,2,3,4] for(const obj of array){ const temp = 1 }

If I ran this code in the VM I want to be able to get hello and array with their values And since temp declared inside the loop (another scope) I don't want it.

Thanks in advance!

XmiliaH commented 1 year ago

I do not know of a way to do this without code transformation.