@@ -233,11 +233,12 @@ func (b *bridge) UnlockAccount(call jsre.Call) (goja.Value, error) {
233233 if len(call.Arguments) < 1 {
234234 return nil, fmt.Errorf("usage: unlockAccount(account, [ password, duration ])")
235235 }
236+
237+ account := call.Argument(0)
236238 // Make sure we have an account specified to unlock.
237- if call.Argument(0) .ExportType().Kind() != reflect.String {
239+ if goja.IsUndefined(account) || goja.IsNull(account) || account .ExportType().Kind() != reflect.String {
238240 return nil, fmt.Errorf("first argument must be the account to unlock")
239241 }
240- account := call.Argument(0)
241242
242243 // If password is not given or is the null value, prompt the user for it.
243244 var passwd goja.Value
@@ -285,10 +286,10 @@ func (b *bridge) Sign(call jsre.Call) (goja.Value, error) {
285286 passwd = call.Argument(2)
286287 )
287288
288- if message.ExportType().Kind() != reflect.String {
289+ if goja.IsUndefined(message) || message.ExportType().Kind() != reflect.String {
289290 return nil, fmt.Errorf("first argument must be the message to sign")
290291 }
291- if account.ExportType().Kind() != reflect.String {
292+ if goja.IsUndefined(account) || account.ExportType().Kind() != reflect.String {
292293 return nil, fmt.Errorf("second argument must be the account to sign with")
293294 }
294295
@@ -317,10 +318,11 @@ func (b *bridge) Sleep(call jsre.Call) (goja.Value, error) {
317318 if nArgs := len(call.Arguments); nArgs < 1 {
318319 return nil, fmt.Errorf("usage: sleep(<number of seconds>)")
319320 }
320- if !isNumber(call.Argument(0)) {
321+ sleepObj := call.Argument(0)
322+ if goja.IsUndefined(sleepObj) || goja.IsNull(sleepObj) || !isNumber(sleepObj) {
321323 return nil, fmt.Errorf("usage: sleep(<number of seconds>)")
322324 }
323- sleep := call.Argument(0) .ToFloat()
325+ sleep := sleepObj .ToFloat()
324326 time.Sleep(time.Duration(sleep * float64(time.Second)))
325327 return call.VM.ToValue(true), nil
326328}
@@ -338,13 +340,13 @@ func (b *bridge) SleepBlocks(call jsre.Call) (goja.Value, error) {
338340 return nil, fmt.Errorf("usage: sleepBlocks(<n blocks>[, max sleep in seconds])")
339341 }
340342 if nArgs >= 1 {
341- if !isNumber(call.Argument(0)) {
343+ if goja.IsNull(call.Argument(0)) || goja.IsUndefined(call.Argument(0)) || !isNumber(call.Argument(0)) {
342344 return nil, fmt.Errorf("expected number as first argument")
343345 }
344346 blocks = call.Argument(0).ToInteger()
345347 }
346348 if nArgs >= 2 {
347- if !isNumber(call.Argument(1)) {
349+ if goja.IsNull(call.Argument(1)) || goja.IsUndefined(call.Argument(1)) || !isNumber(call.Argument(1)) {
348350 return nil, fmt.Errorf("expected number as second argument")
349351 }
350352 sleep = call.Argument(1).ToInteger()
0 commit comments