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

Function TestBridgeClassConstructorRuntimeUnavailable

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

Source from the content-addressed store, hash-verified

464}
465
466func TestBridgeClassConstructorRuntimeUnavailable(t *testing.T) {
467 rt := NewRuntime()
468 defer rt.Close()
469 ctx := rt.NewContext()
470 defer ctx.Close()
471
472 backupRuntime := ctx.runtime
473
474 constructor, _ := NewClassBuilder("RuntimeUnavailableClass").
475 Constructor(func(ctx *Context, instance *Value, args []*Value) (interface{}, error) {
476 ctx.runtime = nil
477 return map[string]int{"x": 1}, nil
478 }).
479 Build(ctx)
480 require.False(t, constructor.IsException())
481
482 ctx.Globals().Set("RuntimeUnavailableClass", constructor)
483
484 result := ctx.Eval(`new RuntimeUnavailableClass()`)
485 ctx.runtime = backupRuntime
486
487 defer result.Free()
488 require.True(t, result.IsException())
489 err := ctx.Exception()
490 require.Error(t, err)
491 require.Contains(t, err.Error(), "Context runtime not available")
492}
493
494func TestBridgeClassConstructorIdentityRegistrationFailure(t *testing.T) {
495 rt := NewRuntime()

Callers

nothing calls this directly

Calls 14

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
GlobalsMethod · 0.95
EvalMethod · 0.95
ExceptionMethod · 0.95
NewRuntimeFunction · 0.85
NewClassBuilderFunction · 0.85
ConstructorMethod · 0.80
IsExceptionMethod · 0.80
SetMethod · 0.80
BuildMethod · 0.45

Tested by

no test coverage detected