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
3d6d828c
Commit
3d6d828c
authored
Apr 26, 2016
by
Felix Lange
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2478 from fjl/geth-js-tweak
cmd/geth, jsre: improve the js command
parents
70b8b54c
87ae0df4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
13 deletions
+34
-13
js.go
cmd/geth/js.go
+7
-9
main.go
cmd/geth/main.go
+19
-3
jsre.go
jsre/jsre.go
+8
-1
No files found.
cmd/geth/js.go
View file @
3d6d828c
...
...
@@ -123,7 +123,7 @@ func (self *jsre) batch(statement string) {
err
:=
self
.
re
.
EvalAndPrettyPrint
(
statement
)
if
err
!=
nil
{
fmt
.
Printf
(
"
error: %v"
,
err
)
fmt
.
Printf
(
"
%v"
,
jsErrorString
(
err
)
)
}
if
self
.
atexit
!=
nil
{
...
...
@@ -301,21 +301,19 @@ func (self *jsre) preloadJSFiles(ctx *cli.Context) error {
for
_
,
file
:=
range
jsFiles
{
filename
:=
common
.
AbsolutePath
(
assetPath
,
strings
.
TrimSpace
(
file
))
if
err
:=
self
.
re
.
Exec
(
filename
);
err
!=
nil
{
return
fmt
.
Errorf
(
"%s: %v"
,
file
,
err
)
return
fmt
.
Errorf
(
"%s: %v"
,
file
,
jsErrorString
(
err
)
)
}
}
}
return
nil
}
// exec executes the JS file with the given filename and stops the JSRE
func
(
self
*
jsre
)
exec
(
filename
string
)
error
{
if
err
:=
self
.
re
.
Exec
(
filename
);
err
!=
nil
{
self
.
re
.
Stop
(
false
)
return
fmt
.
Errorf
(
"Javascript Error: %v"
,
err
)
// jsErrorString adds a backtrace to errors generated by otto.
func
jsErrorString
(
err
error
)
string
{
if
ottoErr
,
ok
:=
err
.
(
*
otto
.
Error
);
ok
{
return
ottoErr
.
String
()
}
self
.
re
.
Stop
(
true
)
return
nil
return
err
.
Error
()
}
func
(
self
*
jsre
)
interactive
()
{
...
...
cmd/geth/main.go
View file @
3d6d828c
...
...
@@ -21,6 +21,7 @@ import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"path/filepath"
"runtime"
"strconv"
...
...
@@ -353,7 +354,7 @@ func console(ctx *cli.Context) {
// preload user defined JS files into the console
err
=
repl
.
preloadJSFiles
(
ctx
)
if
err
!=
nil
{
utils
.
Fatalf
(
"
unable to preload JS file
%v"
,
err
)
utils
.
Fatalf
(
"%v"
,
err
)
}
// in case the exec flag holds a JS statement execute it and return
...
...
@@ -372,6 +373,7 @@ func execScripts(ctx *cli.Context) {
// Create and start the node based on the CLI flags
node
:=
utils
.
MakeSystemNode
(
ClientIdentifier
,
nodeNameVersion
,
makeDefaultExtra
(),
ctx
)
startNode
(
ctx
,
node
)
defer
node
.
Stop
()
// Attach to the newly started node and execute the given scripts
client
,
err
:=
node
.
Attach
()
...
...
@@ -383,10 +385,24 @@ func execScripts(ctx *cli.Context) {
ctx
.
GlobalString
(
utils
.
RPCCORSDomainFlag
.
Name
),
client
,
false
)
// Run all given files.
for
_
,
file
:=
range
ctx
.
Args
()
{
repl
.
exec
(
file
)
if
err
=
repl
.
re
.
Exec
(
file
);
err
!=
nil
{
break
}
node
.
Stop
()
}
if
err
!=
nil
{
utils
.
Fatalf
(
"JavaScript Error: %v"
,
jsErrorString
(
err
))
}
// JS files loaded successfully.
// Wait for pending callbacks, but stop for Ctrl-C.
abort
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
abort
,
os
.
Interrupt
)
go
func
()
{
<-
abort
repl
.
re
.
Stop
(
false
)
}()
repl
.
re
.
Stop
(
true
)
}
// startNode boots up the system node and all registered protocols, after which
...
...
jsre/jsre.go
View file @
3d6d828c
...
...
@@ -235,7 +235,14 @@ func (self *JSRE) Exec(file string) error {
if
err
!=
nil
{
return
err
}
self
.
Do
(
func
(
vm
*
otto
.
Otto
)
{
_
,
err
=
vm
.
Run
(
code
)
})
var
script
*
otto
.
Script
self
.
Do
(
func
(
vm
*
otto
.
Otto
)
{
script
,
err
=
vm
.
Compile
(
file
,
code
)
if
err
!=
nil
{
return
}
_
,
err
=
vm
.
Run
(
script
)
})
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