spidermonkey
v0.1.3
Published
Spawn a SpiderMonkey shell as a child process.
Downloads
10
Readme
sm.js
Run a SpiderMonkey shell as a node child process.
Usage
var sm = require('sm');
sm.evaluate('var x = 12; x * 3').on('return', function(result) {
// got the result
});
sm.evaluate('throw 12').on('throw', function(e) {
// got the thrown exception
});
sm.check('delete for this').on('throw', function(e) {
// got the syntax error
});
sm.check('function asi() { return 12 }').on('return', function() {
// syntax successfully checked
});
sm.parse('var x = 12; x * 3').on('return', function(ast) {
// got the parsed AST
});
Functions
All the functions provided by this module produce an EventEmitter that supports the same set of events.
evaluate(src[, shell="js"])
: evaluates source with SpiderMonkeyevaluateFile(path[, shell="js"])
: evaluates a file with SpiderMonkeyparse(src[, shell="js"])
: parses source with SpiderMonkey, producing an AST with the Mozilla Parser APIparseFile(path[, shell="js"])
: parses a file with SpiderMonkeycheck(src[, shell="js"])
: checks source for syntax errors with SpiderMonkeycheckFile(path[, shell="js"])
: checks a file for syntax errors with SpiderMonkey
Events
"return"
: the result of a successful evaluation in SpiderMonkey, communicated via JSON"throw"
: the result of a thrown exception in SpiderMonkey, communicated via JSON"error"
: an I/O or spawning error occurred
License
Copyright © 2012 Dave Herman
Licensed under the MIT License.