(t *testing.T)
| 261 | } |
| 262 | |
| 263 | func TestBridgeNilCallbackResultsNormalizeToUndefined(t *testing.T) { |
| 264 | rt := NewRuntime() |
| 265 | defer rt.Close() |
| 266 | ctx := rt.NewContext() |
| 267 | defer ctx.Close() |
| 268 | |
| 269 | ctx.Globals().Set("nilFn", ctx.NewFunction(func(ctx *Context, this *Value, args []*Value) *Value { |
| 270 | return nil |
| 271 | })) |
| 272 | |
| 273 | fnType := ctx.Eval(`typeof nilFn()`) |
| 274 | defer fnType.Free() |
| 275 | require.False(t, fnType.IsException()) |
| 276 | require.Equal(t, "undefined", fnType.ToString()) |
| 277 | |
| 278 | constructor, _ := NewClassBuilder("NilBridgeClass"). |
| 279 | Constructor(func(ctx *Context, instance *Value, args []*Value) (interface{}, error) { |
| 280 | return map[string]int{"ok": 1}, nil |
| 281 | }). |
| 282 | Method("m", func(ctx *Context, this *Value, args []*Value) *Value { |
| 283 | return nil |
| 284 | }). |
| 285 | Accessor("a", func(ctx *Context, this *Value) *Value { |
| 286 | return nil |
| 287 | }, func(ctx *Context, this *Value, val *Value) *Value { |
| 288 | return nil |
| 289 | }). |
| 290 | Build(ctx) |
| 291 | require.False(t, constructor.IsException()) |
| 292 | |
| 293 | ctx.Globals().Set("NilBridgeClass", constructor) |
| 294 | |
| 295 | result := ctx.Eval(` |
| 296 | (() => { |
| 297 | const o = new NilBridgeClass(); |
| 298 | const m = o.m(); |
| 299 | const g = o.a; |
| 300 | o.a = 123; |
| 301 | return [m === undefined, g === undefined].join(','); |
| 302 | })() |
| 303 | `) |
| 304 | defer result.Free() |
| 305 | require.False(t, result.IsException()) |
| 306 | require.Equal(t, "true,true", result.ToString()) |
| 307 | } |
| 308 | |
| 309 | func TestBridgeModuleInitFailClosedInvalidExportAndBuilderHandle(t *testing.T) { |
| 310 | newModuleContext := func(t *testing.T) *Context { |
nothing calls this directly
no test coverage detected