diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-12-21 19:56:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-21 19:56:11 +0800 |
commit | 5258785c81959109138ebeca613f12c277188abc (patch) | |
tree | b3d21fc2f38927841f44541a3717b69f5a3c5ec1 /vendor/gopkg.in/olebedev/go-duktape.v3/README.md | |
parent | 1a5425779b026587e36f5d21a6e50efe17cc6a9d (diff) | |
download | go-tangerine-5258785c81959109138ebeca613f12c277188abc.tar go-tangerine-5258785c81959109138ebeca613f12c277188abc.tar.gz go-tangerine-5258785c81959109138ebeca613f12c277188abc.tar.bz2 go-tangerine-5258785c81959109138ebeca613f12c277188abc.tar.lz go-tangerine-5258785c81959109138ebeca613f12c277188abc.tar.xz go-tangerine-5258785c81959109138ebeca613f12c277188abc.tar.zst go-tangerine-5258785c81959109138ebeca613f12c277188abc.zip |
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
Diffstat (limited to 'vendor/gopkg.in/olebedev/go-duktape.v3/README.md')
-rw-r--r-- | vendor/gopkg.in/olebedev/go-duktape.v3/README.md | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/README.md b/vendor/gopkg.in/olebedev/go-duktape.v3/README.md new file mode 100644 index 000000000..2ddaad5e1 --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/README.md @@ -0,0 +1,124 @@ +# Duktape bindings for Go(Golang) + +[![wercker status](https://app.wercker.com/status/3a5bb2e639a4b4efaf4c8bf7cab7442d/s "wercker status")](https://app.wercker.com/project/bykey/3a5bb2e639a4b4efaf4c8bf7cab7442d) +[![Travis status](https://travis-ci.org/olebedev/go-duktape.svg?branch=v3)](https://travis-ci.org/olebedev/go-duktape) +[![Appveyor status](https://ci.appveyor.com/api/projects/status/github/olebedev/go-duktape?branch=v3&svg=true)](https://ci.appveyor.com/project/olebedev/go-duktape/branch/v3) +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/olebedev/go-duktape?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) + +[Duktape](http://duktape.org/index.html) is a thin, embeddable javascript engine. +Most of the [api](http://duktape.org/api.html) is implemented. +The exceptions are listed [here](https://github.com/olebedev/go-duktape/blob/master/api.go#L1566). + +### Usage + +The package is fully go-getable, no need to install any external C libraries. +So, just type `go get gopkg.in/olebedev/go-duktape.v3` to install. + + +```go +package main + +import "fmt" +import "gopkg.in/olebedev/go-duktape.v3" + +func main() { + ctx := duktape.New() + ctx.PevalString(`2 + 3`) + result := ctx.GetNumber(-1) + ctx.Pop() + fmt.Println("result is:", result) + // To prevent memory leaks, don't forget to clean up after + // yourself when you're done using a context. + ctx.DestroyHeap() +} +``` + +### Go specific notes + +Bindings between Go and Javascript contexts are not fully functional. +However, binding a Go function to the Javascript context is available: +```go +package main + +import "fmt" +import "gopkg.in/olebedev/go-duktape.v3" + +func main() { + ctx := duktape.New() + ctx.PushGlobalGoFunction("log", func(c *duktape.Context) int { + fmt.Println(c.SafeToString(-1)) + return 0 + }) + ctx.PevalString(`log('Go lang Go!')`) +} +``` +then run it. +```bash +$ go run *.go +Go lang Go! +$ +``` + +### Timers + +There is a method to inject timers to the global scope: +```go +package main + +import "fmt" +import "gopkg.in/olebedev/go-duktape.v3" + +func main() { + ctx := duktape.New() + + // Let's inject `setTimeout`, `setInterval`, `clearTimeout`, + // `clearInterval` into global scope. + ctx.PushTimers() + + ch := make(chan string) + ctx.PushGlobalGoFunction("second", func(_ *Context) int { + ch <- "second step" + return 0 + }) + ctx.PevalString(` + setTimeout(second, 0); + print('first step'); + `) + fmt.Println(<-ch) +} +``` +then run it +```bash +$ go run *.go +first step +second step +$ +``` + +Also you can `FlushTimers()`. + +### Command line tool + +Install `go get gopkg.in/olebedev/go-duktape.v3/...`. +Execute file.js: `$GOPATH/bin/go-duk file.js`. + +### Benchmarks +| prog | time | +| ------------|-------| +|[otto](https://github.com/robertkrimen/otto)|200.13s| +|[anko](https://github.com/mattn/anko)|231.19s| +|[agora](https://github.com/PuerkitoBio/agora/)|149.33s| +|[GopherLua](https://github.com/yuin/gopher-lua/)|8.39s| +|**go-duktape**|**9.80s**| + +More details are [here](https://github.com/olebedev/go-duktape/wiki/Benchmarks). + +### Status + +The package is not fully tested, so be careful. + + +### Contribution + +Pull requests are welcome! Also, if you want to discuss something send a pull request with proposal and changes. +__Convention:__ fork the repository and make changes on your fork in a feature branch. |