@@ -233,11 +233,12 @@ func (b *bridge) UnlockAccount(call jsre.Call) (goja.Value, error) {
233
233
if len (call .Arguments ) < 1 {
234
234
return nil , fmt .Errorf ("usage: unlockAccount(account, [ password, duration ])" )
235
235
}
236
+
237
+ account := call .Argument (0 )
236
238
// 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 {
238
240
return nil , fmt .Errorf ("first argument must be the account to unlock" )
239
241
}
240
- account := call .Argument (0 )
241
242
242
243
// If password is not given or is the null value, prompt the user for it.
243
244
var passwd goja.Value
@@ -285,10 +286,10 @@ func (b *bridge) Sign(call jsre.Call) (goja.Value, error) {
285
286
passwd = call .Argument (2 )
286
287
)
287
288
288
- if message .ExportType ().Kind () != reflect .String {
289
+ if goja . IsUndefined ( message ) || message .ExportType ().Kind () != reflect .String {
289
290
return nil , fmt .Errorf ("first argument must be the message to sign" )
290
291
}
291
- if account .ExportType ().Kind () != reflect .String {
292
+ if goja . IsUndefined ( account ) || account .ExportType ().Kind () != reflect .String {
292
293
return nil , fmt .Errorf ("second argument must be the account to sign with" )
293
294
}
294
295
@@ -317,10 +318,11 @@ func (b *bridge) Sleep(call jsre.Call) (goja.Value, error) {
317
318
if nArgs := len (call .Arguments ); nArgs < 1 {
318
319
return nil , fmt .Errorf ("usage: sleep(<number of seconds>)" )
319
320
}
320
- if ! isNumber (call .Argument (0 )) {
321
+ sleepObj := call .Argument (0 )
322
+ if goja .IsUndefined (sleepObj ) || goja .IsNull (sleepObj ) || ! isNumber (sleepObj ) {
321
323
return nil , fmt .Errorf ("usage: sleep(<number of seconds>)" )
322
324
}
323
- sleep := call . Argument ( 0 ) .ToFloat ()
325
+ sleep := sleepObj .ToFloat ()
324
326
time .Sleep (time .Duration (sleep * float64 (time .Second )))
325
327
return call .VM .ToValue (true ), nil
326
328
}
@@ -338,13 +340,13 @@ func (b *bridge) SleepBlocks(call jsre.Call) (goja.Value, error) {
338
340
return nil , fmt .Errorf ("usage: sleepBlocks(<n blocks>[, max sleep in seconds])" )
339
341
}
340
342
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 )) {
342
344
return nil , fmt .Errorf ("expected number as first argument" )
343
345
}
344
346
blocks = call .Argument (0 ).ToInteger ()
345
347
}
346
348
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 )) {
348
350
return nil , fmt .Errorf ("expected number as second argument" )
349
351
}
350
352
sleep = call .Argument (1 ).ToInteger ()
0 commit comments