github.com/xyproto/otto (go): Package otto is a JavaScript parser and interpreter written natively in Go.  http://godoc.org/github.com/robertkrimen/otto  Run something in the VM  Get a value out of the VM  Set a number  Set a string  Get the value of an expression  An error happens  Set a Go function  Set a Go function that returns something useful  Use the functions in JavaScript  A separate parser is available in the parser package if you're just interested in building an AST.  http://godoc.org/github.com/robertkrimen/otto/parser  Parse and return an AST  otto  You can run (Go) JavaScript from the commandline with: http://github.com/robertkrimen/otto/tree/master/otto  Run JavaScript by entering some source on stdin or by giving otto a filename:  underscore  Optionally include the JavaScript utility-belt library, underscore, with this import:  For more information: http://github.com/robertkrimen/otto/tree/master/underscore  The following are some limitations with otto:  Go translates JavaScript-style regular expressions into something that is "regexp" compatible via `parser.TransformRegExp`. Unfortunately, RegExp requires backtracking for some patterns, and backtracking is not supported by the standard Go engine: https://code.google.com/p/re2/wiki/Syntax  Therefore, the following syntax is incompatible:  A brief discussion of these limitations: "Regexp (?!re)" https://groups.google.com/forum/?fromgroups=#%21topic/golang-nuts/7qgSDWPIh_E  More information about re2: https://code.google.com/p/re2/  In addition to the above, re2 (Go) has a different definition for \s: [\t\n\f\r ]. The JavaScript definition, on the other hand, also includes \v, Unicode "Separator, Space", etc.  If you want to stop long running executions (like third-party code), you can use the interrupt channel to do this:  Where is setTimeout/setInterval?  These timing functions are not actually part of the ECMA-262 specification. Typically, they belong to the `windows` object (in the browser). It would not be difficult to provide something like these via Go, but you probably want to wrap otto in an event loop in that case.  For an example of how this could be done in Go with otto, see natto:  http://github.com/robertkrimen/natto  Here is some more discussion of the issue:  * http://book.mixu.net/node/ch2.html  * http://en.wikipedia.org/wiki/Reentrancy_%28computing%29  * http://aaroncrane.co.uk/2009/02/perl_safe_signals/
Keywords: ecmascript5|go|javascript