Skip to content

Commit 5542b51

Browse files
committed
jsre: expose Do
1 parent b34b130 commit 5542b51

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎jsre/completion.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ import (
2727
// evaluated, callers need to make sure that evaluating line does not have side effects.
2828
func (jsre *JSRE) CompleteKeywords(line string) []string {
2929
var results []string
30-
jsre.do(func(vm *otto.Otto) { results = getCompletions(vm, line) })
30+
jsre.Do(func(vm *otto.Otto) {
31+
results = getCompletions(vm, line)
32+
})
3133
return results
3234
}
3335

‎jsre/jsre.go‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ loop:
214214
self.loopWg.Done()
215215
}
216216

217-
// do schedules the given function on the event loop.
218-
func (self *JSRE) do(fn func(*otto.Otto)) {
217+
// Do executes the given function on the JS event loop.
218+
func (self *JSRE) Do(fn func(*otto.Otto)) {
219219
done := make(chan bool)
220220
req := &evalReq{fn, done}
221221
self.evalQueue <- req
@@ -235,7 +235,7 @@ func (self *JSRE) Exec(file string) error {
235235
if err != nil {
236236
return err
237237
}
238-
self.do(func(vm *otto.Otto) { _, err = vm.Run(code) })
238+
self.Do(func(vm *otto.Otto) { _, err = vm.Run(code) })
239239
return err
240240
}
241241

@@ -247,19 +247,19 @@ func (self *JSRE) Bind(name string, v interface{}) error {
247247

248248
// Run runs a piece of JS code.
249249
func (self *JSRE) Run(code string) (v otto.Value, err error) {
250-
self.do(func(vm *otto.Otto) { v, err = vm.Run(code) })
250+
self.Do(func(vm *otto.Otto) { v, err = vm.Run(code) })
251251
return v, err
252252
}
253253

254254
// Get returns the value of a variable in the JS environment.
255255
func (self *JSRE) Get(ns string) (v otto.Value, err error) {
256-
self.do(func(vm *otto.Otto) { v, err = vm.Get(ns) })
256+
self.Do(func(vm *otto.Otto) { v, err = vm.Get(ns) })
257257
return v, err
258258
}
259259

260260
// Set assigns value v to a variable in the JS environment.
261261
func (self *JSRE) Set(ns string, v interface{}) (err error) {
262-
self.do(func(vm *otto.Otto) { err = vm.Set(ns, v) })
262+
self.Do(func(vm *otto.Otto) { err = vm.Set(ns, v) })
263263
return err
264264
}
265265

@@ -288,7 +288,7 @@ func (self *JSRE) loadScript(call otto.FunctionCall) otto.Value {
288288
// EvalAndPrettyPrint evaluates code and pretty prints the result to
289289
// standard output.
290290
func (self *JSRE) EvalAndPrettyPrint(code string) (err error) {
291-
self.do(func(vm *otto.Otto) {
291+
self.Do(func(vm *otto.Otto) {
292292
var val otto.Value
293293
val, err = vm.Run(code)
294294
if err != nil {
@@ -302,7 +302,7 @@ func (self *JSRE) EvalAndPrettyPrint(code string) (err error) {
302302

303303
// Compile compiles and then runs a piece of JS code.
304304
func (self *JSRE) Compile(filename string, src interface{}) (err error) {
305-
self.do(func(vm *otto.Otto) { _, err = compileAndRun(vm, filename, src) })
305+
self.Do(func(vm *otto.Otto) { _, err = compileAndRun(vm, filename, src) })
306306
return err
307307
}
308308

0 commit comments

Comments
 (0)