From 473b22bd55d6796ca329e648540425414458a1ac Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Wed, 24 Sep 2025 07:45:57 +0800 Subject: [PATCH] console: handle undefined + null in console funcs #21160 (#1525) --- console/bridge.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/console/bridge.go b/console/bridge.go index 467a19768d..b977155ccf 100644 --- a/console/bridge.go +++ b/console/bridge.go @@ -19,6 +19,7 @@ package console import ( "encoding/json" "errors" + "fmt" "io" "reflect" "strings" @@ -53,10 +54,11 @@ func (b *bridge) Sleep(call jsre.Call) (goja.Value, error) { if nArgs := len(call.Arguments); nArgs < 1 { return nil, errors.New("usage: sleep()") } - if !isNumber(call.Argument(0)) { - return nil, errors.New("usage: sleep()") + sleepObj := call.Argument(0) + if goja.IsUndefined(sleepObj) || goja.IsNull(sleepObj) || !isNumber(sleepObj) { + return nil, fmt.Errorf("usage: sleep()") } - sleep := call.Argument(0).ToFloat() + sleep := sleepObj.ToFloat() time.Sleep(time.Duration(sleep * float64(time.Second))) 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([, max sleep in seconds])") } 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") } blocks = call.Argument(0).ToInteger() } 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") } sleep = call.Argument(1).ToInteger()