MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestBridgeClassFinalizerProxyContracts

Function TestBridgeClassFinalizerProxyContracts

bridge_test.go:522–566  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

520}
521
522func TestBridgeClassFinalizerProxyContracts(t *testing.T) {
523 rt := NewRuntime()
524 defer rt.Close()
525 ctx := rt.NewContext()
526 defer ctx.Close()
527
528 var finalized atomic.Bool
529
530 constructor, _ := NewClassBuilder("FinalizerProbeClass").
531 Constructor(func(ctx *Context, instance *Value, args []*Value) (interface{}, error) {
532 return &bridgeFinalizerProbe{mark: &finalized}, nil
533 }).
534 Build(ctx)
535 require.False(t, constructor.IsException())
536 ctx.Globals().Set("FinalizerProbeClass", constructor)
537
538 instance := ctx.Eval(`new FinalizerProbeClass()`)
539 defer instance.Free()
540 require.False(t, instance.IsException())
541
542 require.NotPanics(t, func() {
543 goClassFinalizerProxy(nil, instance.ref)
544 })
545
546 ctxRef := ctx.ref
547 unregisterContext(ctxRef)
548 contextMapping.Store(ctxRef, "corrupted-finalizer-mapping")
549
550 rt2 := NewRuntime()
551 defer rt2.Close()
552 require.NotPanics(t, func() {
553 goClassFinalizerProxy(rt2.ref, instance.ref)
554 })
555 require.False(t, finalized.Load())
556
557 goClassFinalizerProxy(rt.ref, instance.ref)
558 require.True(t, finalized.Load())
559
560 registerContext(ctxRef, ctx)
561
562 // Second finalizer call should be safely ignored after handle cleanup.
563 require.NotPanics(t, func() {
564 goClassFinalizerProxy(rt.ref, instance.ref)
565 })
566}
567
568func TestBridgeClassFinalizerRejectsLegacyOpaque(t *testing.T) {
569 rt := NewRuntime()

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
GlobalsMethod · 0.95
EvalMethod · 0.95
NewRuntimeFunction · 0.85
NewClassBuilderFunction · 0.85
goClassFinalizerProxyFunction · 0.85
unregisterContextFunction · 0.85
registerContextFunction · 0.85
ConstructorMethod · 0.80
IsExceptionMethod · 0.80

Tested by

no test coverage detected