MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestBridgeContextNotFound

Function TestBridgeContextNotFound

bridge_test.go:666–714  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

664}
665
666func TestBridgeContextNotFound(t *testing.T) {
667 // Test getContextAndFunction - Context not found error
668 t.Run("ContextNotFound", func(t *testing.T) {
669 rt := NewRuntime()
670 defer rt.Close()
671 ctx := rt.NewContext()
672 defer ctx.Close()
673
674 // Create function and store it in JavaScript - MODIFIED: now uses pointer signature
675 fn := ctx.NewFunction(func(ctx *Context, this *Value, args []*Value) *Value { // Changed: Function() → NewFunction()
676 return ctx.NewString("test") // Changed: String() → NewString()
677 })
678 ctx.Globals().Set("testFunc", fn)
679
680 // Verify function works initially
681 result := ctx.Eval(`testFunc()`)
682 require.False(t, result.IsException())
683 require.Equal(t, "test", result.ToString()) // Changed: String() → ToString()
684 result.Free()
685
686 // Unregister context from mapping to simulate context being removed
687 unregisterContext(ctx.ref)
688
689 // Call function from JavaScript - triggers goFunctionProxy -> getContextAndFunction with unmapped context
690 result2 := ctx.Eval(`
691 try {
692 testFunc();
693 } catch(e) {
694 e.toString();
695 }
696 `)
697
698 if result2.IsException() {
699 err := ctx.Exception()
700 t.Logf("Expected exception when context not found: %v", err)
701 require.Contains(t, err.Error(), "Context not found")
702 } else {
703 defer result2.Free()
704 resultStr := result2.ToString() // Changed: String() → ToString()
705 t.Logf("Exception result: %s", resultStr)
706 require.Contains(t, resultStr, "Context not found")
707 }
708
709 // Re-register context for proper cleanup
710 registerContext(ctx.ref, ctx)
711
712 t.Log("Successfully triggered getContextAndFunction Context not found branch")
713 })
714}
715
716func TestBridgeFunctionNotFoundInHandleStore(t *testing.T) {
717 // Test getContextAndFunction - Function not found in handleStore

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
NewFunctionMethod · 0.95
NewStringMethod · 0.95
GlobalsMethod · 0.95
EvalMethod · 0.95
ExceptionMethod · 0.95
NewRuntimeFunction · 0.85
unregisterContextFunction · 0.85
registerContextFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected