Test for class getter proxy errors - unchanged except method calls
(t *testing.T)
| 1255 | |
| 1256 | // Test for class getter proxy errors - unchanged except method calls |
| 1257 | func TestBridgeClassGetterErrors(t *testing.T) { |
| 1258 | // Test class getter proxy error handling |
| 1259 | t.Run("GetterContextNotFound", func(t *testing.T) { |
| 1260 | rt := NewRuntime() |
| 1261 | defer rt.Close() |
| 1262 | ctx := rt.NewContext() |
| 1263 | defer ctx.Close() |
| 1264 | |
| 1265 | // MODIFIED FOR SCHEME C: Create class with new constructor signature |
| 1266 | constructor, _ := NewClassBuilder("TestClass"). |
| 1267 | Constructor(func(ctx *Context, instance *Value, args []*Value) (interface{}, error) { |
| 1268 | return &Point{X: 1, Y: 2}, nil |
| 1269 | }). |
| 1270 | Accessor("testProp", func(ctx *Context, this *Value) *Value { |
| 1271 | return ctx.NewString("getter called") // Changed: String() → NewString() |
| 1272 | }, nil). |
| 1273 | Build(ctx) |
| 1274 | require.False(t, constructor.IsException()) |
| 1275 | |
| 1276 | ctx.Globals().Set("TestClass", constructor) |
| 1277 | |
| 1278 | // Verify getter works initially |
| 1279 | result := ctx.Eval(` |
| 1280 | let obj = new TestClass(); |
| 1281 | obj.testProp; |
| 1282 | `) |
| 1283 | require.False(t, result.IsException()) |
| 1284 | require.Equal(t, "getter called", result.ToString()) // Changed: String() → ToString() |
| 1285 | result.Free() |
| 1286 | |
| 1287 | // Unregister context from mapping |
| 1288 | unregisterContext(ctx.ref) |
| 1289 | |
| 1290 | // Access getter - triggers goClassGetterProxy with unmapped context |
| 1291 | result2 := ctx.Eval(` |
| 1292 | try { |
| 1293 | let obj = new TestClass(); |
| 1294 | obj.testProp; |
| 1295 | } catch(e) { |
| 1296 | e.toString(); |
| 1297 | } |
| 1298 | `) |
| 1299 | |
| 1300 | if result2.IsException() { |
| 1301 | err := ctx.Exception() |
| 1302 | require.Contains(t, err.Error(), "Context not found") |
| 1303 | } else { |
| 1304 | defer result2.Free() |
| 1305 | require.Contains(t, result2.ToString(), "Context not found") // Changed: String() → ToString() |
| 1306 | } |
| 1307 | |
| 1308 | // Re-register context for cleanup |
| 1309 | registerContext(ctx.ref, ctx) |
| 1310 | |
| 1311 | t.Log("Successfully triggered goClassGetterProxy Context not found branch") |
| 1312 | }) |
| 1313 | |
| 1314 | t.Run("GetterNotFound", func(t *testing.T) { |
nothing calls this directly
no test coverage detected