mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-19 22:19:23 +02:00
treat returned false bool from a jsvm hook as hook.stopPropagation
This commit is contained in:
parent
4962dc618b
commit
64d7ab22f3
@ -76,22 +76,17 @@ func hooksBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
|||||||
res, err := executor.RunProgram(pr)
|
res, err := executor.RunProgram(pr)
|
||||||
executor.Set("__args", goja.Undefined())
|
executor.Set("__args", goja.Undefined())
|
||||||
|
|
||||||
// check for returned hook.StopPropagation
|
// check for returned error or false
|
||||||
if res != nil {
|
if res != nil {
|
||||||
exported := res.Export()
|
exported := res.Export()
|
||||||
if exported != nil {
|
if exported != nil {
|
||||||
if v, ok := exported.(error); ok {
|
switch v := exported.(type) {
|
||||||
|
case error:
|
||||||
return v
|
return v
|
||||||
}
|
case bool:
|
||||||
}
|
if !v {
|
||||||
}
|
return hook.StopPropagation
|
||||||
|
}
|
||||||
// check for throwed hook.StopPropagation
|
|
||||||
if err != nil {
|
|
||||||
if exception, ok := err.(*goja.Exception); ok {
|
|
||||||
v, ok := exception.Value().Export().(error)
|
|
||||||
if ok && errors.Is(v, hook.StopPropagation) {
|
|
||||||
return hook.StopPropagation
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -344,8 +339,6 @@ func baseBinds(vm *goja.Runtime) {
|
|||||||
|
|
||||||
return instanceValue
|
return instanceValue
|
||||||
})
|
})
|
||||||
|
|
||||||
vm.Set("$stopPropagation", hook.StopPropagation)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func dbxBinds(vm *goja.Runtime) {
|
func dbxBinds(vm *goja.Runtime) {
|
||||||
|
@ -45,7 +45,7 @@ func TestBaseBindsCount(t *testing.T) {
|
|||||||
vm := goja.New()
|
vm := goja.New()
|
||||||
baseBinds(vm)
|
baseBinds(vm)
|
||||||
|
|
||||||
testBindsCount(vm, "this", 15, t)
|
testBindsCount(vm, "this", 14, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBaseBindsRecord(t *testing.T) {
|
func TestBaseBindsRecord(t *testing.T) {
|
||||||
@ -1048,7 +1048,7 @@ func TestHooksBinds(t *testing.T) {
|
|||||||
}, "demo2")
|
}, "demo2")
|
||||||
|
|
||||||
onModelBeforeUpdate((e) => {
|
onModelBeforeUpdate((e) => {
|
||||||
return $stopPropagation
|
return false
|
||||||
}, "demo2")
|
}, "demo2")
|
||||||
|
|
||||||
onModelBeforeUpdate((e) => {
|
onModelBeforeUpdate((e) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user