NEW TEST FOR SCHEME C: Test CreateClassInstance failure scenarios
(t *testing.T)
| 1795 | |
| 1796 | // NEW TEST FOR SCHEME C: Test CreateClassInstance failure scenarios |
| 1797 | func 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 | } |
nothing calls this directly
no test coverage detected