nihil
nihil

Reputation: 95

Obtaning the AST of JavaScript code from Spidermonkey

I need to obtain the AST of a JS code from C++. I know that Spidermonkey's (unlike V8's generated) ASTs follow a standard that I could use.

Can I pass it a code (string or JS file) from a C++ program and get the AST? If so how?

Upvotes: 1

Views: 812

Answers (1)

jwilm
jwilm

Reputation: 447

I just answered a similar question here. The short version is:

  1. Build a runtime, context, and global object as outlined here
  2. JS_InitReflect with your global to instantiate the Reflect object in the global scope (documentation)
  3. Write a bit of JS to parse the code you wish to analyze. Depending on your needs, you may just want to do the analysis in JavaScript or hand a JSON encoded string back to your C++.

Upvotes: 2

Related Questions