quorum/vendor/gopkg.in/olebedev/go-duktape.v3
Sai V c215989c10
Quorum geth upgrade to 1.9.7 (#960)
Co-authored-by: amalraj.manigmail.com <amalraj.manigmail.com>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
Co-authored-by: Flash Sheridan <flash@pobox.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Nguyen Kien Trung <trung.n.k@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: Rob Mulholand <rmulholand@8thlight.com>
Co-authored-by: Felföldi Zsolt <zsfelfoldi@gmail.com>
Co-authored-by: soc1c <soc1c@users.noreply.github.com>
Co-authored-by: Rafael Matias <rafael@skyle.net>
Co-authored-by: gary rong <garyrong0905@gmail.com>
Co-authored-by: Lucas Hendren <lhendre2@gmail.com>
Co-authored-by: Ryan Schneider <ryanleeschneider@gmail.com>
Co-authored-by: ywzqwwt <39263032+ywzqwwt@users.noreply.github.com>
Co-authored-by: zcheng9 <zcheng9@hawk.iit.edu>
Co-authored-by: zzy96 <zhou0250@e.ntu.edu.sg>
Co-authored-by: kikilass <36239971+kikilass@users.noreply.github.com>
Co-authored-by: Darrel Herbst <dherbst@gmail.com>
Co-authored-by: Ross <9055337+Chadsr@users.noreply.github.com>
Co-authored-by: Jeffery Robert Walsh <rlxrlps@gmail.com>
Co-authored-by: Marius Kjærstad <sandakersmann@users.noreply.github.com>
Co-authored-by: Piotr Dyraga <piotr.dyraga@keep.network>
Co-authored-by: Guillaume Ballet <gballet@gmail.com>
Co-authored-by: Michael Forney <mforney@mforney.org>
Co-authored-by: Samuel Marks <807580+SamuelMarks@users.noreply.github.com>
2020-04-29 10:50:56 -04:00
..
Gopkg.lock Merge attempt 2018-05-31 14:16:44 +08:00
Gopkg.toml Merge attempt 2018-05-31 14:16:44 +08:00
LICENSE.md Merge attempt 2018-05-31 14:16:44 +08:00
README.md Merge attempt 2018-05-31 14:16:44 +08:00
api.go Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
appveyor.yml Merge attempt 2018-05-31 14:16:44 +08:00
conts.go Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duk_alloc_pool.c Merge attempt 2018-05-31 14:16:44 +08:00
duk_alloc_pool.h Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duk_config.h Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duk_console.c Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duk_console.h Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duk_logging.c Merge attempt 2018-05-31 14:16:44 +08:00
duk_logging.h Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duk_minimal_printf.c Merge attempt 2018-05-31 14:16:44 +08:00
duk_minimal_printf.h Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duk_module_duktape.c Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duk_module_duktape.h Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duk_module_node.c Merge attempt 2018-05-31 14:16:44 +08:00
duk_module_node.h Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duk_print_alert.c Merge attempt 2018-05-31 14:16:44 +08:00
duk_print_alert.h Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duk_v1_compat.c Merge attempt 2018-05-31 14:16:44 +08:00
duk_v1_compat.h Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duktape.c Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duktape.go Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
duktape.h Quorum geth upgrade to 1.9.7 (#960) 2020-04-29 10:50:56 -04:00
timers.go Merge attempt 2018-05-31 14:16:44 +08:00
utils.go Merge attempt 2018-05-31 14:16:44 +08:00
wercker.yml Merge attempt 2018-05-31 14:16:44 +08:00

README.md

Duktape bindings for Go(Golang)

wercker status Travis status Appveyor status Gitter

Duktape is a thin, embeddable javascript engine. Most of the api is implemented. The exceptions are listed here.

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.

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:

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.

$ go run *.go
Go lang Go!
$

Timers

There is a method to inject timers to the global scope:

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

$ 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 200.13s
anko 231.19s
agora 149.33s
GopherLua 8.39s
go-duktape 9.80s

More details are here.

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.