(t *testing.T)
| 172 | } |
| 173 | |
| 174 | func 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 | |
| 208 | func TestContextIsAliveEdgeCases(t *testing.T) { |
| 209 | var nilCtx *Context |
nothing calls this directly
no test coverage detected