将V8 JavaScript引擎绑定至Go语言:v8.go
jopen
11年前
v8.go是一个将V8 JavaScript引擎绑定至Go语言的开源项目。用于在Go语言中运行JavaScript。
功能特性:
- Thread safe
- Thorough and careful testing
- Boolean, Number, String, Object, Array, Regexp, Function
- Compile and run JavaScript
- Save and load pre-compiled script data
- Create JavaScript context with global object template
- Operate JavaScript object properties and array elements in Go
- Define JavaScript object template in Go with property accessors and interceptors
- Define JavaScript function template in Go
- Catch JavaScript exception in Go
- Throw JavaScript exception by Go
- JSON parse and generate
这个 'Hello World' 程序显示了如何使用 v8.go 来编译和运行 JavaScript 脚本,并得到结果。
package main import "github.com/idada/v8.go" func main() { engine := v8.NewEngine() script := engine.Compile([]byte("'Hello ' + 'World!'"), nil, nil) context := engine.NewContext(nil) context.Scope(func(cs v8.ContextScope) { result := script.Run() println(result.ToString()) }) }