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

Function TestContextInternalStateHelpers

context_test.go:174–206  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

172}
173
174func TestContextInternalStateHelpers(t *testing.T) {
175 var nilCtx *Context
176 require.Nil(t, nilCtx.Runtime())
177 require.False(t, nilCtx.isAlive())
178
179 rt := NewRuntime()
180 defer rt.Close()
181 ctx := rt.NewContext()
182
183 require.True(t, ctx.isAlive())
184
185 fn := ctx.NewFunction(func(ctx *Context, this *Value, args []*Value) *Value {
186 return ctx.NewUndefined()
187 })
188
189 var handleID int32
190 ctx.handleStore.handles.Range(func(key, _ interface{}) bool {
191 handleID = key.(int32)
192 return false
193 })
194 require.Greater(t, handleID, int32(0))
195 require.NotNil(t, ctx.loadFunctionFromHandleID(handleID))
196
197 require.Nil(t, ctx.loadFunctionFromHandleID(0))
198 require.Nil(t, ctx.loadFunctionFromHandleID(-1))
199
200 empty := &Context{}
201 require.Nil(t, empty.loadFunctionFromHandleID(handleID))
202
203 fn.Free()
204 ctx.Close()
205 require.False(t, ctx.isAlive())
206}
207
208func TestContextIsAliveEdgeCases(t *testing.T) {
209 var nilCtx *Context

Callers

nothing calls this directly

Calls 10

RuntimeMethod · 0.95
isAliveMethod · 0.95
CloseMethod · 0.95
NewContextMethod · 0.95
NewFunctionMethod · 0.95
NewUndefinedMethod · 0.95
CloseMethod · 0.95
NewRuntimeFunction · 0.85
FreeMethod · 0.45

Tested by

no test coverage detected