MCPcopy Create free account
hub / github.com/dop251/goja / ExampleRuntime_ExportTo_funcThrow

Function ExampleRuntime_ExportTo_funcThrow

runtime_test.go:919–941  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

917}
918
919func ExampleRuntime_ExportTo_funcThrow() {
920 const SCRIPT = `
921 function f(param) {
922 throw new Error("testing");
923 }
924 `
925
926 vm := New()
927 _, err := vm.RunString(SCRIPT)
928 if err != nil {
929 panic(err)
930 }
931
932 var fn func(string) (string, error)
933 err = vm.ExportTo(vm.Get("f"), &fn)
934 if err != nil {
935 panic(err)
936 }
937 _, err = fn("")
938
939 fmt.Println(err)
940 // Output: Error: testing at f (<eval>:3:9(3))
941}
942
943func ExampleRuntime_ExportTo_funcVariadic() {
944 const SCRIPT = `

Callers

nothing calls this directly

Calls 4

NewFunction · 0.85
RunStringMethod · 0.80
ExportToMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…