Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
670bae4c
Commit
670bae4c
authored
May 02, 2018
by
kiel barry
Committed by
Péter Szilágyi
May 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
internal: golint updates for this or self warning (#16634)
parent
4a8d5d2b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
27 deletions
+27
-27
jsre.go
internal/jsre/jsre.go
+27
-27
No files found.
internal/jsre/jsre.go
View file @
670bae4c
...
...
@@ -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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment