(t *testing.T)
| 64 | } |
| 65 | |
| 66 | func TestBridgeGetRuntimeFromJSReturnNil(t *testing.T) { |
| 67 | // Test getRuntimeFromJS return nil in goInterruptHandler |
| 68 | t.Run("GetRuntimeFromJSReturnNil", func(t *testing.T) { |
| 69 | rt := NewRuntime() |
| 70 | ctx := rt.NewContext() |
| 71 | require.NotNil(t, ctx) |
| 72 | |
| 73 | // Set interrupt handler |
| 74 | interruptCalled := false |
| 75 | rt.SetInterruptHandler(func() int { |
| 76 | interruptCalled = true |
| 77 | return 1 // Request interrupt |
| 78 | }) |
| 79 | |
| 80 | // Unregister runtime from mapping before executing long-running code |
| 81 | unregisterRuntime(rt.ref) |
| 82 | |
| 83 | // Execute long-running code that may trigger interrupt handler |
| 84 | result := ctx.Eval(` |
| 85 | var sum = 0; |
| 86 | for(var i = 0; i < 100000; i++) { |
| 87 | sum += i; |
| 88 | if (i % 1000 === 0) { |
| 89 | var temp = Math.sqrt(i); |
| 90 | } |
| 91 | } |
| 92 | sum; |
| 93 | `) |
| 94 | |
| 95 | // Since runtime is not in mapping, goInterruptHandler should return 0 |
| 96 | t.Logf("Interrupt handler called: %v", interruptCalled) |
| 97 | if result.IsException() { |
| 98 | err := ctx.Exception() |
| 99 | t.Logf("Execution resulted in exception: %v", err) |
| 100 | } else { |
| 101 | defer result.Free() |
| 102 | t.Logf("Computation completed with result: %d", result.ToInt32()) // Changed: Int32() → ToInt32() |
| 103 | } |
| 104 | |
| 105 | // Re-register runtime for proper cleanup |
| 106 | registerRuntime(rt.ref, rt) |
| 107 | |
| 108 | // Close context first, then runtime |
| 109 | ctx.Close() |
| 110 | rt.Close() |
| 111 | |
| 112 | t.Log("Successfully triggered getRuntimeFromJS return nil branch") |
| 113 | }) |
| 114 | } |
| 115 | |
| 116 | func TestBridgeMappingCorruptionFailClosed(t *testing.T) { |
| 117 | rt := NewRuntime() |
nothing calls this directly
no test coverage detected