SpiderMonkey变量列表 [英] SpiderMonkey variables list

查看:193
本文介绍了SpiderMonkey变量列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个QT应用程序,我想在其中嵌入SpiderMonkey.有了它,我想解析javascript段(而不是执行它)并检索某种结构化树中的所有变量,函数,对象,数组等,或者只列出它们...这可能吗?

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.

或者如果我不能用SpiderMonkey做到这一点,也许有人可以将我指向另一个解析器?

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

推荐答案

如果必须使用SpiderMonkey嵌入进行此操作,则可以使用JS_InitReflect函数在当前全局上下文中创建Reflect对象(文档).这将需要您编写一个脚本来运行Relect.parse(/* your javascript segment */),但是随后您将AST引入了JS对象层次结构中.那时,将JSON字符串或您需要的任何内容导出回本机代码应该很容易.

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.

使用像 Esprima 这样的项目并生成Node.js进程进行打印可能会容易得多.您要分析的JS的AST,而不必处理SpiderMonkey完全嵌入的麻烦.

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.

这篇关于SpiderMonkey变量列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆