(t *testing.T)
| 20 | } |
| 21 | |
| 22 | func TestBridgeGetContextFromJSReturnNil(t *testing.T) { |
| 23 | // Test getContextFromJS return nil |
| 24 | t.Run("GetContextFromJSReturnNil", func(t *testing.T) { |
| 25 | rt := NewRuntime() |
| 26 | defer rt.Close() |
| 27 | ctx := rt.NewContext() |
| 28 | |
| 29 | // Create function and store it globally - MODIFIED: now uses pointer signature |
| 30 | fn := ctx.NewFunction(func(ctx *Context, this *Value, args []*Value) *Value { // Changed: Function() → NewFunction() |
| 31 | return ctx.NewString("test") // Changed: String() → NewString() |
| 32 | }) |
| 33 | ctx.Globals().Set("testFn", fn) |
| 34 | |
| 35 | // Unregister context from mapping to simulate context not found |
| 36 | unregisterContext(ctx.ref) |
| 37 | |
| 38 | // Call function from JavaScript - triggers goFunctionProxy -> getContextFromJS with unmapped context |
| 39 | result := ctx.Eval(` |
| 40 | try { |
| 41 | testFn(); |
| 42 | } catch(e) { |
| 43 | e.toString(); |
| 44 | } |
| 45 | `) |
| 46 | |
| 47 | // Should get an error or exception |
| 48 | if result.IsException() { |
| 49 | err := ctx.Exception() |
| 50 | t.Logf("Expected exception when context not in mapping: %v", err) |
| 51 | } else { |
| 52 | defer result.Free() |
| 53 | resultStr := result.ToString() // Changed: String() → ToString() |
| 54 | t.Logf("Exception result: %s", resultStr) |
| 55 | require.True(t, len(resultStr) > 0) |
| 56 | } |
| 57 | |
| 58 | // Re-register context for proper cleanup |
| 59 | registerContext(ctx.ref, ctx) |
| 60 | ctx.Close() |
| 61 | |
| 62 | t.Log("Successfully triggered getContextFromJS return nil branch") |
| 63 | }) |
| 64 | } |
| 65 | |
| 66 | func TestBridgeGetRuntimeFromJSReturnNil(t *testing.T) { |
| 67 | // Test getRuntimeFromJS return nil in goInterruptHandler |
nothing calls this directly
no test coverage detected