SpiderMonkey variables list

自古美人都是妖i 提交于 2019-12-24 17:24:42

问题


I have a QT application in which I want to embed SpiderMonkey. With it I want to parse javascript segment (not execute it) and retrieve all the variables, functions, objects, arrays, etc. in some kind of a structured tree or just list them... Is that possible?

I've looked through the documentation, but could not find anything.

Or perhaps someone can point me to another parser if I can't do that with SpiderMonkey?


回答1:


If you must do this with a SpiderMonkey embedding, you can use the JS_InitReflect function to create a Reflect object in the current global context (documentation). It would require you to write a script to run Relect.parse(/* your javascript segment */), but then you've got the AST in a JS object hierarchy. At that point, it should be easy to export a JSON string or whatever you need back to your native code.

It would probably be a lot easier to use a project like Esprima and spawn a Node.js process to print out the AST for the JS you want to analyze instead of dealing with the trouble of a full on SpiderMonkey embedding.



来源:https://stackoverflow.com/questions/31674368/spidermonkey-variables-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!