mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
parent
2563cd13ed
commit
473b22bd55
1 changed files with 7 additions and 5 deletions
|
|
@ -19,6 +19,7 @@ package console
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -53,10 +54,11 @@ func (b *bridge) Sleep(call jsre.Call) (goja.Value, error) {
|
||||||
if nArgs := len(call.Arguments); nArgs < 1 {
|
if nArgs := len(call.Arguments); nArgs < 1 {
|
||||||
return nil, errors.New("usage: sleep(<number of seconds>)")
|
return nil, errors.New("usage: sleep(<number of seconds>)")
|
||||||
}
|
}
|
||||||
if !isNumber(call.Argument(0)) {
|
sleepObj := call.Argument(0)
|
||||||
return nil, errors.New("usage: sleep(<number of seconds>)")
|
if goja.IsUndefined(sleepObj) || goja.IsNull(sleepObj) || !isNumber(sleepObj) {
|
||||||
|
return nil, fmt.Errorf("usage: sleep(<number of seconds>)")
|
||||||
}
|
}
|
||||||
sleep := call.Argument(0).ToFloat()
|
sleep := sleepObj.ToFloat()
|
||||||
time.Sleep(time.Duration(sleep * float64(time.Second)))
|
time.Sleep(time.Duration(sleep * float64(time.Second)))
|
||||||
return call.VM.ToValue(true), nil
|
return call.VM.ToValue(true), nil
|
||||||
}
|
}
|
||||||
|
|
@ -74,13 +76,13 @@ func (b *bridge) SleepBlocks(call jsre.Call) (goja.Value, error) {
|
||||||
return nil, errors.New("usage: sleepBlocks(<n blocks>[, max sleep in seconds])")
|
return nil, errors.New("usage: sleepBlocks(<n blocks>[, max sleep in seconds])")
|
||||||
}
|
}
|
||||||
if nArgs >= 1 {
|
if nArgs >= 1 {
|
||||||
if !isNumber(call.Argument(0)) {
|
if goja.IsNull(call.Argument(0)) || goja.IsUndefined(call.Argument(0)) || !isNumber(call.Argument(0)) {
|
||||||
return nil, errors.New("expected number as first argument")
|
return nil, errors.New("expected number as first argument")
|
||||||
}
|
}
|
||||||
blocks = call.Argument(0).ToInteger()
|
blocks = call.Argument(0).ToInteger()
|
||||||
}
|
}
|
||||||
if nArgs >= 2 {
|
if nArgs >= 2 {
|
||||||
if !isNumber(call.Argument(1)) {
|
if goja.IsNull(call.Argument(1)) || goja.IsUndefined(call.Argument(1)) || !isNumber(call.Argument(1)) {
|
||||||
return nil, errors.New("expected number as second argument")
|
return nil, errors.New("expected number as second argument")
|
||||||
}
|
}
|
||||||
sleep = call.Argument(1).ToInteger()
|
sleep = call.Argument(1).ToInteger()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue