@@ -102,8 +102,8 @@ func randomSource() *rand.Rand {
102
102
// call the functions of the otto vm directly to circumvent the queue. These
103
103
// functions should be used if and only if running a routine that was already
104
104
// called from JS through an RPC call.
105
- func (self * JSRE ) runEventLoop () {
106
- defer close (self .closed )
105
+ func (re * JSRE ) runEventLoop () {
106
+ defer close (re .closed )
107
107
108
108
vm := otto .New ()
109
109
r := randomSource ()
@@ -202,14 +202,14 @@ loop:
202
202
break loop
203
203
}
204
204
}
205
- case req := <- self .evalQueue :
205
+ case req := <- re .evalQueue :
206
206
// run the code, send the result back
207
207
req .fn (vm )
208
208
close (req .done )
209
209
if waitForCallbacks && (len (registry ) == 0 ) {
210
210
break loop
211
211
}
212
- case waitForCallbacks = <- self .stopEventLoop :
212
+ case waitForCallbacks = <- re .stopEventLoop :
213
213
if ! waitForCallbacks || (len (registry ) == 0 ) {
214
214
break loop
215
215
}
@@ -223,31 +223,31 @@ loop:
223
223
}
224
224
225
225
// Do executes the given function on the JS event loop.
226
- func (self * JSRE ) Do (fn func (* otto.Otto )) {
226
+ func (re * JSRE ) Do (fn func (* otto.Otto )) {
227
227
done := make (chan bool )
228
228
req := & evalReq {fn , done }
229
- self .evalQueue <- req
229
+ re .evalQueue <- req
230
230
<- done
231
231
}
232
232
233
233
// stops the event loop before exit, optionally waits for all timers to expire
234
- func (self * JSRE ) Stop (waitForCallbacks bool ) {
234
+ func (re * JSRE ) Stop (waitForCallbacks bool ) {
235
235
select {
236
- case <- self .closed :
237
- case self .stopEventLoop <- waitForCallbacks :
238
- <- self .closed
236
+ case <- re .closed :
237
+ case re .stopEventLoop <- waitForCallbacks :
238
+ <- re .closed
239
239
}
240
240
}
241
241
242
242
// Exec(file) loads and runs the contents of a file
243
243
// if a relative path is given, the jsre's assetPath is used
244
- func (self * JSRE ) Exec (file string ) error {
245
- code , err := ioutil .ReadFile (common .AbsolutePath (self .assetPath , file ))
244
+ func (re * JSRE ) Exec (file string ) error {
245
+ code , err := ioutil .ReadFile (common .AbsolutePath (re .assetPath , file ))
246
246
if err != nil {
247
247
return err
248
248
}
249
249
var script * otto.Script
250
- self .Do (func (vm * otto.Otto ) {
250
+ re .Do (func (vm * otto.Otto ) {
251
251
script , err = vm .Compile (file , code )
252
252
if err != nil {
253
253
return
@@ -259,36 +259,36 @@ func (self *JSRE) Exec(file string) error {
259
259
260
260
// Bind assigns value v to a variable in the JS environment
261
261
// This method is deprecated, use Set.
262
- func (self * JSRE ) Bind (name string , v interface {}) error {
263
- return self .Set (name , v )
262
+ func (re * JSRE ) Bind (name string , v interface {}) error {
263
+ return re .Set (name , v )
264
264
}
265
265
266
266
// Run runs a piece of JS code.
267
- func (self * JSRE ) Run (code string ) (v otto.Value , err error ) {
268
- self .Do (func (vm * otto.Otto ) { v , err = vm .Run (code ) })
267
+ func (re * JSRE ) Run (code string ) (v otto.Value , err error ) {
268
+ re .Do (func (vm * otto.Otto ) { v , err = vm .Run (code ) })
269
269
return v , err
270
270
}
271
271
272
272
// Get returns the value of a variable in the JS environment.
273
- func (self * JSRE ) Get (ns string ) (v otto.Value , err error ) {
274
- self .Do (func (vm * otto.Otto ) { v , err = vm .Get (ns ) })
273
+ func (re * JSRE ) Get (ns string ) (v otto.Value , err error ) {
274
+ re .Do (func (vm * otto.Otto ) { v , err = vm .Get (ns ) })
275
275
return v , err
276
276
}
277
277
278
278
// Set assigns value v to a variable in the JS environment.
279
- func (self * JSRE ) Set (ns string , v interface {}) (err error ) {
280
- self .Do (func (vm * otto.Otto ) { err = vm .Set (ns , v ) })
279
+ func (re * JSRE ) Set (ns string , v interface {}) (err error ) {
280
+ re .Do (func (vm * otto.Otto ) { err = vm .Set (ns , v ) })
281
281
return err
282
282
}
283
283
284
284
// loadScript executes a JS script from inside the currently executing JS code.
285
- func (self * JSRE ) loadScript (call otto.FunctionCall ) otto.Value {
285
+ func (re * JSRE ) loadScript (call otto.FunctionCall ) otto.Value {
286
286
file , err := call .Argument (0 ).ToString ()
287
287
if err != nil {
288
288
// TODO: throw exception
289
289
return otto .FalseValue ()
290
290
}
291
- file = common .AbsolutePath (self .assetPath , file )
291
+ file = common .AbsolutePath (re .assetPath , file )
292
292
source , err := ioutil .ReadFile (file )
293
293
if err != nil {
294
294
// TODO: throw exception
@@ -305,10 +305,10 @@ func (self *JSRE) loadScript(call otto.FunctionCall) otto.Value {
305
305
306
306
// Evaluate executes code and pretty prints the result to the specified output
307
307
// stream.
308
- func (self * JSRE ) Evaluate (code string , w io.Writer ) error {
308
+ func (re * JSRE ) Evaluate (code string , w io.Writer ) error {
309
309
var fail error
310
310
311
- self .Do (func (vm * otto.Otto ) {
311
+ re .Do (func (vm * otto.Otto ) {
312
312
val , err := vm .Run (code )
313
313
if err != nil {
314
314
prettyError (vm , err , w )
@@ -321,8 +321,8 @@ func (self *JSRE) Evaluate(code string, w io.Writer) error {
321
321
}
322
322
323
323
// Compile compiles and then runs a piece of JS code.
324
- func (self * JSRE ) Compile (filename string , src interface {}) (err error ) {
325
- self .Do (func (vm * otto.Otto ) { _ , err = compileAndRun (vm , filename , src ) })
324
+ func (re * JSRE ) Compile (filename string , src interface {}) (err error ) {
325
+ re .Do (func (vm * otto.Otto ) { _ , err = compileAndRun (vm , filename , src ) })
326
326
return err
327
327
}
328
328
0 commit comments