console: fix some goja-related crashes/errors in the bridge #21050 (#1522)

This commit is contained in:
Daniel Liu 2025-09-21 18:58:28 +08:00 committed by GitHub
parent 590cbafae9
commit 94a85f4162
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -49,6 +49,9 @@ func newBridge(client *rpc.Client, prompter UserPrompter, printer io.Writer) *br
// Sleep will block the console for the specified number of seconds.
func (b *bridge) Sleep(call jsre.Call) (goja.Value, error) {
if nArgs := len(call.Arguments); nArgs < 1 {
return nil, errors.New("usage: sleep(<number of seconds>)")
}
if !isNumber(call.Argument(0)) {
return nil, errors.New("usage: sleep(<number of seconds>)")
}
@ -76,7 +79,7 @@ func (b *bridge) SleepBlocks(call jsre.Call) (goja.Value, error) {
blocks = call.Argument(0).ToInteger()
}
if nArgs >= 2 {
if isNumber(call.Argument(1)) {
if !isNumber(call.Argument(1)) {
return nil, errors.New("expected number as second argument")
}
sleep = call.Argument(1).ToInteger()