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

Function TestStacktraceLocationThrowFromGo

runtime_test.go:2510–2545  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2508}
2509
2510func TestStacktraceLocationThrowFromGo(t *testing.T) {
2511 vm := New()
2512 f := func() {
2513 panic(vm.ToValue("Test"))
2514 }
2515 vm.Set("f", f)
2516 _, err := vm.RunString(`
2517 function main() {
2518 (function noop() {})();
2519 return callee();
2520 }
2521 function callee() {
2522 return f();
2523 }
2524 main();
2525 `)
2526 if err == nil {
2527 t.Fatal("Expected error")
2528 }
2529 stack := err.(*Exception).stack
2530 if len(stack) != 4 {
2531 t.Fatalf("Unexpected stack len: %v", stack)
2532 }
2533 if frame := stack[0]; !strings.HasSuffix(frame.funcName.String(), "TestStacktraceLocationThrowFromGo.func1") {
2534 t.Fatalf("Unexpected stack frame 0: %#v", frame)
2535 }
2536 if frame := stack[1]; frame.funcName != "callee" || frame.pc != 2 {
2537 t.Fatalf("Unexpected stack frame 1: %#v", frame)
2538 }
2539 if frame := stack[2]; frame.funcName != "main" || frame.pc != 6 {
2540 t.Fatalf("Unexpected stack frame 2: %#v", frame)
2541 }
2542 if frame := stack[3]; frame.funcName != "" || frame.pc != 4 {
2543 t.Fatalf("Unexpected stack frame 3: %#v", frame)
2544 }
2545}
2546
2547func TestStacktraceLocationThrowNativeInTheMiddle(t *testing.T) {
2548 vm := New()

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
ToValueMethod · 0.80
RunStringMethod · 0.80
SetMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…