(t *testing.T)
| 871 | } |
| 872 | |
| 873 | func TestReflectionEdgeCases(t *testing.T) { |
| 874 | newTestContext := func(t *testing.T) *Context { |
| 875 | rt := NewRuntime() |
| 876 | ctx := rt.NewContext() |
| 877 | require.NotNil(t, ctx) |
| 878 | t.Cleanup(func() { |
| 879 | ctx.Close() |
| 880 | rt.Close() |
| 881 | }) |
| 882 | return ctx |
| 883 | } |
| 884 | |
| 885 | // Test empty struct |
| 886 | t.Run("EmptyStruct", func(t *testing.T) { |
| 887 | ctx := newTestContext(t) |
| 888 | constructor, _ := ctx.BindClass(&EmptyStruct{}) |
| 889 | require.False(t, constructor.IsException()) |
| 890 | |
| 891 | ctx.Globals().Set("EmptyStruct", constructor) |
| 892 | |
| 893 | result := ctx.Eval(` |
| 894 | (function() { |
| 895 | let obj = new EmptyStruct(); |
| 896 | return typeof obj; |
| 897 | })(); |
| 898 | `) |
| 899 | defer result.Free() |
| 900 | require.False(t, result.IsException()) |
| 901 | require.Equal(t, "object", result.ToString()) // Changed: String() → ToString() |
| 902 | }) |
| 903 | |
| 904 | // Test struct with only private fields |
| 905 | t.Run("OnlyPrivateFields", func(t *testing.T) { |
| 906 | ctx := newTestContext(t) |
| 907 | constructor, _ := ctx.BindClass(&PrivateStruct{}) |
| 908 | require.False(t, constructor.IsException()) |
| 909 | |
| 910 | ctx.Globals().Set("PrivateStruct", constructor) |
| 911 | |
| 912 | result := ctx.Eval(` |
| 913 | (function() { |
| 914 | let obj = new PrivateStruct(); |
| 915 | return Object.keys(obj).length; // Should have no enumerable accessors |
| 916 | })(); |
| 917 | `) |
| 918 | defer result.Free() |
| 919 | require.False(t, result.IsException()) |
| 920 | require.Equal(t, int32(0), result.ToInt32()) // Changed: Int32() → ToInt32() |
| 921 | }) |
| 922 | |
| 923 | // Test method with zero return values |
| 924 | t.Run("VoidMethod", func(t *testing.T) { |
| 925 | ctx := newTestContext(t) |
| 926 | constructor, _ := ctx.BindClass(&VoidStruct{}) |
| 927 | require.False(t, constructor.IsException()) |
| 928 | |
| 929 | ctx.Globals().Set("VoidStruct", constructor) |
| 930 |
nothing calls this directly
no test coverage detected