TestValueCallConstructorEdgeCases tests edge cases and error conditions in CallConstructor MODIFIED FOR SCHEME C: Removed all NewInstance tests, enhanced CallConstructor coverage
(t *testing.T)
| 1907 | // TestValueCallConstructorEdgeCases tests edge cases and error conditions in CallConstructor |
| 1908 | // MODIFIED FOR SCHEME C: Removed all NewInstance tests, enhanced CallConstructor coverage |
| 1909 | func TestValueCallConstructorEdgeCases(t *testing.T) { |
| 1910 | useStableOwnerHooksForLegacySubtests(t) |
| 1911 | |
| 1912 | rt := NewRuntime() |
| 1913 | defer rt.Close() |
| 1914 | ctx := rt.NewContext() |
| 1915 | defer ctx.Close() |
| 1916 | |
| 1917 | // Test Case 1: CallConstructor called on non-constructor value |
| 1918 | t.Run("CallConstructor_NonConstructor", func(t *testing.T) { |
| 1919 | // Test with regular object (not a constructor) - Updated to use New* methods |
| 1920 | obj := ctx.NewObject() |
| 1921 | defer obj.Free() |
| 1922 | |
| 1923 | // This should trigger a JavaScript TypeError since object is not a constructor |
| 1924 | result := obj.CallConstructor() |
| 1925 | defer result.Free() |
| 1926 | |
| 1927 | // Verify it returns an error/exception or creates a generic object (depends on JS engine behavior) |
| 1928 | // For non-constructor objects, JavaScript usually throws TypeError |
| 1929 | if !result.IsException() { |
| 1930 | // Some JavaScript engines might return an object, that's also valid |
| 1931 | require.True(t, result.IsObject()) |
| 1932 | } |
| 1933 | }) |
| 1934 | |
| 1935 | // Test Case 2: CallConstructor called on string (definitely not a constructor) |
| 1936 | t.Run("CallConstructor_String", func(t *testing.T) { |
| 1937 | str := ctx.NewString("not a constructor") |
| 1938 | defer str.Free() |
| 1939 | |
| 1940 | // This should trigger a JavaScript TypeError |
| 1941 | result := str.CallConstructor() |
| 1942 | defer result.Free() |
| 1943 | |
| 1944 | // Should definitely be an exception since strings are not constructors |
| 1945 | require.True(t, result.IsException()) |
| 1946 | }) |
| 1947 | |
| 1948 | // Test Case 3: CallConstructor with various non-constructor types - Updated to use New* methods |
| 1949 | t.Run("CallConstructor_VariousNonConstructors", func(t *testing.T) { |
| 1950 | testCases := []struct { |
| 1951 | name string |
| 1952 | val func() *Value // Changed to return pointer |
| 1953 | }{ |
| 1954 | {"Number", func() *Value { return ctx.NewInt32(42) }}, |
| 1955 | {"Boolean", func() *Value { return ctx.NewBool(true) }}, |
| 1956 | {"Null", func() *Value { return ctx.NewNull() }}, |
| 1957 | {"Undefined", func() *Value { return ctx.NewUndefined() }}, |
| 1958 | } |
| 1959 | |
| 1960 | for _, tc := range testCases { |
| 1961 | t.Run(tc.name, func(t *testing.T) { |
| 1962 | val := tc.val() |
| 1963 | defer val.Free() |
| 1964 | |
| 1965 | result := val.CallConstructor() |
| 1966 | defer result.Free() |
nothing calls this directly
no test coverage detected