aboutsummaryrefslogtreecommitdiffstats
path: root/jsre
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-04-21 05:17:00 +0800
committerFelix Lange <fjl@twurst.com>2016-04-21 05:33:43 +0800
commit87ae0df476cf6b413795ee54207e8ec86e178dbc (patch)
tree0a3a42c72845507ce40ff8e6767188d9809fa361 /jsre
parenta6ca8fd26884807c80b649bd2a0e780aa93ced22 (diff)
downloadgo-tangerine-87ae0df476cf6b413795ee54207e8ec86e178dbc.tar.gz
go-tangerine-87ae0df476cf6b413795ee54207e8ec86e178dbc.tar.zst
go-tangerine-87ae0df476cf6b413795ee54207e8ec86e178dbc.zip
cmd/geth, jsre: improve the js command
geth js stopped the JS runtime after running the first input file and blocked for pending callbacks. This commit makes it process all files and enables quitting with Ctrl-C regardless of callbacks. Error reporting is also improved. If a script fails to load, the error is printed and includes the backtrace. package jsre now ensures that otto is aware of the filename, the backtrace will contain them. Before: $ geth js bad.js; echo "exit $?" ... log messages ... exit 0 After: $ geth js bad.js; echo "exit $?" ... log messages ... Fatal: JavaScript Error: Invalid number of input parameters at web3.js:3109:20 at web3.js:4917:15 at web3.js:4960:5 at web3.js:4984:23 at checkWork (bad.js:11:9) at bad.js:19:1 exit 1
Diffstat (limited to 'jsre')
-rw-r--r--jsre/jsre.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/jsre/jsre.go b/jsre/jsre.go
index 7df022cb1..59730bc0d 100644
--- a/jsre/jsre.go
+++ b/jsre/jsre.go
@@ -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
}