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

Function TestBridgeCreateClassInstanceFailures

bridge_test.go:1797–1833  ·  view source on GitHub ↗

NEW TEST FOR SCHEME C: Test CreateClassInstance failure scenarios

(t *testing.T)

Source from the content-addressed store, hash-verified

1795
1796// NEW TEST FOR SCHEME C: Test CreateClassInstance failure scenarios
1797func TestBridgeCreateClassInstanceFailures(t *testing.T) {
1798 t.Run("CreateClassInstance_CException", func(t *testing.T) {
1799 rt := NewRuntime()
1800 defer rt.Close()
1801 ctx := rt.NewContext()
1802 defer ctx.Close()
1803
1804 // Create class
1805 constructor, originalClassID := NewClassBuilder("TestClass").
1806 Constructor(func(ctx *Context, instance *Value, args []*Value) (interface{}, error) {
1807 return &Point{X: 1, Y: 2}, nil
1808 }).
1809 Build(ctx)
1810 require.False(t, constructor.IsException())
1811
1812 ctx.Globals().Set("TestClass", constructor)
1813
1814 // Replace with invalid class ID to trigger JS_NewObjectProtoClass failure
1815 constructorKey := jsValueToKey(constructor.ref)
1816 ctx.runtime.constructorRegistry.Store(constructorKey, uint32(999999))
1817
1818 // This should trigger CreateClassInstance to return JS_EXCEPTION
1819 result := ctx.Eval(`new TestClass()`)
1820 defer result.Free()
1821
1822 // Restore for cleanup
1823 ctx.runtime.constructorRegistry.Store(constructorKey, originalClassID)
1824
1825 // Should get an error
1826 if result.IsException() {
1827 err := ctx.Exception()
1828 t.Logf("Expected exception from CreateClassInstance: %v", err)
1829 }
1830
1831 t.Log("Successfully triggered CreateClassInstance JS_EXCEPTION branch")
1832 })
1833}

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
NewRuntimeFunction · 0.85
NewClassBuilderFunction · 0.85
jsValueToKeyFunction · 0.85
ConstructorMethod · 0.80
IsExceptionMethod · 0.80
SetMethod · 0.80

Tested by

no test coverage detected