aboutsummaryrefslogtreecommitdiffstats
path: root/jsre
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-02-20 21:28:34 +0800
committerFelix Lange <fjl@twurst.com>2016-04-13 18:06:42 +0800
commit5542b51b5047ebd4792cd6b2cec789189c019e3c (patch)
treec5cba3abb83a9426c8a7789199d73d19aa20a0bc /jsre
parentb34b130fb5f8de8bc875c4ddadff044a41c074b4 (diff)
downloaddexon-5542b51b5047ebd4792cd6b2cec789189c019e3c.tar.gz
dexon-5542b51b5047ebd4792cd6b2cec789189c019e3c.tar.zst
dexon-5542b51b5047ebd4792cd6b2cec789189c019e3c.zip
jsre: expose Do
Diffstat (limited to 'jsre')
-rw-r--r--jsre/completion.go4
-rw-r--r--jsre/jsre.go16
2 files changed, 11 insertions, 9 deletions
diff --git a/jsre/completion.go b/jsre/completion.go
index e84a5b75c..11e209b69 100644
--- a/jsre/completion.go
+++ b/jsre/completion.go
@@ -27,7 +27,9 @@ import (
// evaluated, callers need to make sure that evaluating line does not have side effects.
func (jsre *JSRE) CompleteKeywords(line string) []string {
var results []string
- jsre.do(func(vm *otto.Otto) { results = getCompletions(vm, line) })
+ jsre.Do(func(vm *otto.Otto) {
+ results = getCompletions(vm, line)
+ })
return results
}
diff --git a/jsre/jsre.go b/jsre/jsre.go
index f4464910d..7df022cb1 100644
--- a/jsre/jsre.go
+++ b/jsre/jsre.go
@@ -214,8 +214,8 @@ loop:
self.loopWg.Done()
}
-// do schedules the given function on the event loop.
-func (self *JSRE) do(fn func(*otto.Otto)) {
+// Do executes the given function on the JS event loop.
+func (self *JSRE) Do(fn func(*otto.Otto)) {
done := make(chan bool)
req := &evalReq{fn, done}
self.evalQueue <- req
@@ -235,7 +235,7 @@ func (self *JSRE) Exec(file string) error {
if err != nil {
return err
}
- self.do(func(vm *otto.Otto) { _, err = vm.Run(code) })
+ self.Do(func(vm *otto.Otto) { _, err = vm.Run(code) })
return err
}
@@ -247,19 +247,19 @@ func (self *JSRE) Bind(name string, v interface{}) error {
// Run runs a piece of JS code.
func (self *JSRE) Run(code string) (v otto.Value, err error) {
- self.do(func(vm *otto.Otto) { v, err = vm.Run(code) })
+ self.Do(func(vm *otto.Otto) { v, err = vm.Run(code) })
return v, err
}
// Get returns the value of a variable in the JS environment.
func (self *JSRE) Get(ns string) (v otto.Value, err error) {
- self.do(func(vm *otto.Otto) { v, err = vm.Get(ns) })
+ self.Do(func(vm *otto.Otto) { v, err = vm.Get(ns) })
return v, err
}
// Set assigns value v to a variable in the JS environment.
func (self *JSRE) Set(ns string, v interface{}) (err error) {
- self.do(func(vm *otto.Otto) { err = vm.Set(ns, v) })
+ self.Do(func(vm *otto.Otto) { err = vm.Set(ns, v) })
return err
}
@@ -288,7 +288,7 @@ func (self *JSRE) loadScript(call otto.FunctionCall) otto.Value {
// EvalAndPrettyPrint evaluates code and pretty prints the result to
// standard output.
func (self *JSRE) EvalAndPrettyPrint(code string) (err error) {
- self.do(func(vm *otto.Otto) {
+ self.Do(func(vm *otto.Otto) {
var val otto.Value
val, err = vm.Run(code)
if err != nil {
@@ -302,7 +302,7 @@ func (self *JSRE) EvalAndPrettyPrint(code string) (err error) {
// Compile compiles and then runs a piece of JS code.
func (self *JSRE) Compile(filename string, src interface{}) (err error) {
- self.do(func(vm *otto.Otto) { _, err = compileAndRun(vm, filename, src) })
+ self.Do(func(vm *otto.Otto) { _, err = compileAndRun(vm, filename, src) })
return err
}