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

Function TestBridgeClassConstructorErrors

bridge_test.go:826–1051  ·  view source on GitHub ↗

Test for class constructor proxy errors - MODIFIED FOR SCHEME C

(t *testing.T)

Source from the content-addressed store, hash-verified

824
825// Test for class constructor proxy errors - MODIFIED FOR SCHEME C
826func TestBridgeClassConstructorErrors(t *testing.T) {
827 // Test class constructor proxy error handling
828 t.Run("ConstructorContextNotFound", func(t *testing.T) {
829 rt := NewRuntime()
830 defer rt.Close()
831 ctx := rt.NewContext()
832 defer ctx.Close()
833
834 // MODIFIED FOR SCHEME C: Create class with new constructor signature
835 constructor, _ := NewClassBuilder("TestClass").
836 Constructor(func(ctx *Context, instance *Value, args []*Value) (interface{}, error) {
837 // SCHEME C: Return Go object for automatic association
838 return &Point{X: 1, Y: 2}, nil
839 }).
840 Build(ctx)
841 require.False(t, constructor.IsException())
842
843 ctx.Globals().Set("TestClass", constructor)
844
845 // Verify constructor works initially
846 result := ctx.Eval(`new TestClass()`)
847 require.False(t, result.IsException())
848 result.Free()
849
850 // Unregister context from mapping
851 unregisterContext(ctx.ref)
852
853 // Call constructor - triggers goClassConstructorProxy with unmapped context
854 result2 := ctx.Eval(`
855 try {
856 new TestClass();
857 } catch(e) {
858 e.toString();
859 }
860 `)
861
862 if result2.IsException() {
863 err := ctx.Exception()
864 require.Contains(t, err.Error(), "Context not found")
865 } else {
866 defer result2.Free()
867 require.Contains(t, result2.ToString(), "Context not found") // Changed: String() → ToString()
868 }
869
870 // Re-register context for cleanup
871 registerContext(ctx.ref, ctx)
872
873 t.Log("Successfully triggered goClassConstructorProxy Context not found branch")
874 })
875
876 t.Run("ConstructorNotFound", func(t *testing.T) {
877 rt := NewRuntime()
878 defer rt.Close()
879 ctx := rt.NewContext()
880 defer ctx.Close()
881
882 // MODIFIED FOR SCHEME C: Create class with new constructor signature
883 constructor, _ := NewClassBuilder("TestClass").

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
GlobalsMethod · 0.95
EvalMethod · 0.95
ExceptionMethod · 0.95
NewStringMethod · 0.95
NewBoolMethod · 0.95
NewRuntimeFunction · 0.85
NewClassBuilderFunction · 0.85
unregisterContextFunction · 0.85
registerContextFunction · 0.85

Tested by

no test coverage detected