Academia
Academia

Reputation: 4124

Interpreting Javascript from Python

I want to be able to interpret or compile Javascript files, catching errors, etc. from Python programs. Javascript Files use the following syntax for ex.:

var a;
function Mul (){
  prompt(b);
  document.write(a*b);
}

I tried with SpiderMonkey but it seems to be unable to interpret "prompt", "document.write", etc. Help please.

Upvotes: 1

Views: 774

Answers (1)

dda
dda

Reputation: 6203

Stuff like document.write can't work since SpiderMonkey is not a browser. So there's no document, and no DOM. Likewise, you don't have a window, so no alerts or prompts. All this wouldn't make much sense in a command-line script...

You could build your own DOM parser in Python (assuming you actually have a web page to parse in the first place), and create a document object yourself, but that would probably be a lot of work for very little return.

Upvotes: 1

Related Questions