Skip to content

Commit

Permalink
jsre: expose Do
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed Apr 13, 2016
1 parent b34b130 commit 5542b51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion jsre/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
16 changes: 8 additions & 8 deletions jsre/jsre.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit 5542b51

Please sign in to comment.