aboutsummaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
authorkiel barry <kiel.j.barry@gmail.com>2018-05-02 16:26:21 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-05-02 16:26:21 +0800
commit670bae4cd3e6b34d6db008b22b6f5c2afcb07e0a (patch)
tree5b8fea31e8e6b82cb4057a13549fd34741f37f74 /internal
parent4a8d5d2b1e6e78550ebc3495d9d87787dedadb20 (diff)
downloaddexon-670bae4cd3e6b34d6db008b22b6f5c2afcb07e0a.tar
dexon-670bae4cd3e6b34d6db008b22b6f5c2afcb07e0a.tar.gz
dexon-670bae4cd3e6b34d6db008b22b6f5c2afcb07e0a.tar.bz2
dexon-670bae4cd3e6b34d6db008b22b6f5c2afcb07e0a.tar.lz
dexon-670bae4cd3e6b34d6db008b22b6f5c2afcb07e0a.tar.xz
dexon-670bae4cd3e6b34d6db008b22b6f5c2afcb07e0a.tar.zst
dexon-670bae4cd3e6b34d6db008b22b6f5c2afcb07e0a.zip
internal: golint updates for this or self warning (#16634)
Diffstat (limited to 'internal')
-rw-r--r--internal/jsre/jsre.go54
1 files changed, 27 insertions, 27 deletions
diff --git a/internal/jsre/jsre.go b/internal/jsre/jsre.go
index f05865eca..4c7664f1c 100644
--- a/internal/jsre/jsre.go
+++ b/internal/jsre/jsre.go
@@ -102,8 +102,8 @@ func randomSource() *rand.Rand {
// call the functions of the otto vm directly to circumvent the queue. These
// functions should be used if and only if running a routine that was already
// called from JS through an RPC call.
-func (self *JSRE) runEventLoop() {
- defer close(self.closed)
+func (re *JSRE) runEventLoop() {
+ defer close(re.closed)
vm := otto.New()
r := randomSource()
@@ -202,14 +202,14 @@ loop:
break loop
}
}
- case req := <-self.evalQueue:
+ case req := <-re.evalQueue:
// run the code, send the result back
req.fn(vm)
close(req.done)
if waitForCallbacks && (len(registry) == 0) {
break loop
}
- case waitForCallbacks = <-self.stopEventLoop:
+ case waitForCallbacks = <-re.stopEventLoop:
if !waitForCallbacks || (len(registry) == 0) {
break loop
}
@@ -223,31 +223,31 @@ loop:
}
// Do executes the given function on the JS event loop.
-func (self *JSRE) Do(fn func(*otto.Otto)) {
+func (re *JSRE) Do(fn func(*otto.Otto)) {
done := make(chan bool)
req := &evalReq{fn, done}
- self.evalQueue <- req
+ re.evalQueue <- req
<-done
}
// stops the event loop before exit, optionally waits for all timers to expire
-func (self *JSRE) Stop(waitForCallbacks bool) {
+func (re *JSRE) Stop(waitForCallbacks bool) {
select {
- case <-self.closed:
- case self.stopEventLoop <- waitForCallbacks:
- <-self.closed
+ case <-re.closed:
+ case re.stopEventLoop <- waitForCallbacks:
+ <-re.closed
}
}
// Exec(file) loads and runs the contents of a file
// if a relative path is given, the jsre's assetPath is used
-func (self *JSRE) Exec(file string) error {
- code, err := ioutil.ReadFile(common.AbsolutePath(self.assetPath, file))
+func (re *JSRE) Exec(file string) error {
+ code, err := ioutil.ReadFile(common.AbsolutePath(re.assetPath, file))
if err != nil {
return err
}
var script *otto.Script
- self.Do(func(vm *otto.Otto) {
+ re.Do(func(vm *otto.Otto) {
script, err = vm.Compile(file, code)
if err != nil {
return
@@ -259,36 +259,36 @@ func (self *JSRE) Exec(file string) error {
// Bind assigns value v to a variable in the JS environment
// This method is deprecated, use Set.
-func (self *JSRE) Bind(name string, v interface{}) error {
- return self.Set(name, v)
+func (re *JSRE) Bind(name string, v interface{}) error {
+ return re.Set(name, v)
}
// 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) })
+func (re *JSRE) Run(code string) (v otto.Value, err error) {
+ re.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) })
+func (re *JSRE) Get(ns string) (v otto.Value, err error) {
+ re.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) })
+func (re *JSRE) Set(ns string, v interface{}) (err error) {
+ re.Do(func(vm *otto.Otto) { err = vm.Set(ns, v) })
return err
}
// loadScript executes a JS script from inside the currently executing JS code.
-func (self *JSRE) loadScript(call otto.FunctionCall) otto.Value {
+func (re *JSRE) loadScript(call otto.FunctionCall) otto.Value {
file, err := call.Argument(0).ToString()
if err != nil {
// TODO: throw exception
return otto.FalseValue()
}
- file = common.AbsolutePath(self.assetPath, file)
+ file = common.AbsolutePath(re.assetPath, file)
source, err := ioutil.ReadFile(file)
if err != nil {
// TODO: throw exception
@@ -305,10 +305,10 @@ func (self *JSRE) loadScript(call otto.FunctionCall) otto.Value {
// Evaluate executes code and pretty prints the result to the specified output
// stream.
-func (self *JSRE) Evaluate(code string, w io.Writer) error {
+func (re *JSRE) Evaluate(code string, w io.Writer) error {
var fail error
- self.Do(func(vm *otto.Otto) {
+ re.Do(func(vm *otto.Otto) {
val, err := vm.Run(code)
if err != nil {
prettyError(vm, err, w)
@@ -321,8 +321,8 @@ func (self *JSRE) Evaluate(code string, w io.Writer) 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) })
+func (re *JSRE) Compile(filename string, src interface{}) (err error) {
+ re.Do(func(vm *otto.Otto) { _, err = compileAndRun(vm, filename, src) })
return err
}