修正函数返回值

This commit is contained in:
Star 2025-12-12 21:32:26 +08:00
parent 627c05fd06
commit ee7007f050
3 changed files with 16 additions and 13 deletions

8
go.mod
View File

@ -46,9 +46,9 @@ require (
github.com/ysmood/gson v0.7.3 // indirect
github.com/ysmood/leakless v0.9.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/crypto v0.44.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/crypto v0.46.0 // indirect
golang.org/x/net v0.48.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.32.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@ -93,7 +93,10 @@ func (r *Response) Write(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value
args := gojs.MakeArgs(&argsIn, vm).Check(1)
n, err := r.resp.Write(args.Bytes(0))
if err != nil {
panic(vm.NewGoError(err))
// panic(vm.NewGoError(err))
vm.SetData("_lastError", err)
gojs.GetLogger(vm).Error(err.Error())
return vm.ToValue(false)
}
return vm.ToValue(n)
}

View File

@ -260,7 +260,7 @@ func init() {
// panic(vm.NewGoError(errors.New("server already started")))
vm.SetData("_lastError", errors.New("server already started"))
gojs.GetLogger(vm).Error("server already started")
return nil
return vm.ToValue(false)
}
// 处理静态文件
if len(serviceConfig.Static) > 0 {
@ -374,11 +374,11 @@ func init() {
// panic(vm.NewGoError(errors.New("server not started")))
vm.SetData("_lastError", errors.New("server not started"))
gojs.GetLogger(vm).Error("server not started")
return nil
return vm.ToValue(false)
}
server.Stop()
s.ResetAllSets()
return nil
return vm.ToValue(true)
},
// "uniqueId": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
// args := gojs.MakeArgs(&argsIn, vm)
@ -495,7 +495,7 @@ func init() {
// panic(vm.NewGoError(errors.New("action must be a callback function")))
vm.SetData("_lastError", errors.New("action must be a callback function"))
gojs.GetLogger(vm).Error("action must be a callback function")
return nil
return vm.ToValue(false)
}
authLevel := o.Int("authLevel")
@ -589,7 +589,7 @@ func init() {
// 无对象池,直接调用(单线程)
s.RestfulWithOptions(authLevel, method, path, makeInnerAction(action, vm, args.This), memo, opt)
}
return nil
return vm.ToValue(true)
},
"load": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
args := gojs.MakeArgs(&argsIn, vm).Check(1)
@ -615,14 +615,14 @@ func init() {
// panic(vm.NewGoError(errors.New("actionFile must be a js file path: " + fullActionFile)))
vm.SetData("_lastError", errors.New("actionFile must be a js file path: "+fullActionFile))
gojs.GetLogger(vm).Error("actionFile must be a js file path: " + fullActionFile)
return nil
return vm.ToValue(false)
}
actionCode := u.ReadFileN(actionFile)
if !strings.Contains(actionCode, "function main(") { // || !strings.Contains(actionCode, ".register(")
// panic(vm.NewGoError(errors.New("actionFile must be a js file with main function")))
vm.SetData("_lastError", errors.New("actionFile must be a js file with main function"))
gojs.GetLogger(vm).Error("actionFile must be a js file with main function")
return nil
return vm.ToValue(false)
}
poolsLock.Lock()
poolExists[actionFile] = true
@ -646,7 +646,7 @@ func init() {
poolsMTime[actionFile] = mtime
poolsConfig[actionFile] = poolOpt
poolsLock.Unlock()
return nil
return vm.ToValue(true)
},
// "task": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
// args := gojs.MakeArgs(&argsIn, vm).Check(1)