Js2Py icon indicating copy to clipboard operation
Js2Py copied to clipboard

how get js function code

Open dreamfly32 opened this issue 3 years ago • 1 comments

in js,function.toString() can get function code image in my,i need get function local var , so what should i do? thanks

dreamfly32 avatar Nov 25 '22 09:11 dreamfly32

If just executing the code is not an option, maybe you can extract what you need from the bytecode disassembly?

import js2py
import dis

context = js2py.EvalJs()  
context.execute('''
function sum(a, b) {
    return a + b
}
''')

print(dis.dis(context.sum._obj.code))

worstperson avatar Dec 13 '22 06:12 worstperson