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

Function TestValueGetGoObjectIdentityRegistryResolution

value_test.go:1825–1877  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1823}
1824
1825func TestValueGetGoObjectIdentityRegistryResolution(t *testing.T) {
1826 rt := NewRuntime()
1827 defer rt.Close()
1828 ctx := rt.NewContext()
1829 defer ctx.Close()
1830
1831 constructor, _ := NewClassBuilder("IdentityRegistryClass").
1832 Constructor(func(ctx *Context, instance *Value, args []*Value) (interface{}, error) {
1833 return map[string]int{"value": 42}, nil
1834 }).
1835 Build(ctx)
1836 require.False(t, constructor.IsException())
1837 ctx.Globals().Set("IdentityRegistryClass", constructor)
1838
1839 instance := ctx.Eval(`new IdentityRegistryClass()`)
1840 defer instance.Free()
1841 require.False(t, instance.IsException())
1842
1843 obj, err := instance.GetGoObject()
1844 require.NoError(t, err)
1845 require.NotNil(t, obj)
1846
1847 var objectID int32
1848 rt.classObjectRegistry.Range(func(key, value interface{}) bool {
1849 id, ok := key.(int32)
1850 if !ok {
1851 return true
1852 }
1853 identity, ok := value.(classObjectIdentity)
1854 if !ok {
1855 return true
1856 }
1857 if identity.contextID == ctx.contextID {
1858 objectID = id
1859 return false
1860 }
1861 return true
1862 })
1863 require.NotZero(t, objectID)
1864
1865 identity, ok := rt.getClassObjectIdentity(objectID)
1866 require.True(t, ok)
1867 ctx.handleStore.Delete(identity.handleID)
1868 _, err = instance.GetGoObject()
1869 require.Error(t, err)
1870 require.Contains(t, err.Error(), "instance data not found in handle store")
1871
1872 rt.classObjectRegistry.Delete(objectID)
1873 require.False(t, instance.HasInstanceData())
1874 _, err = instance.GetGoObject()
1875 require.Error(t, err)
1876 require.Contains(t, err.Error(), "instance data not found in handle store")
1877}
1878
1879func TestValueHasInstanceDataFailClosedOnMissingOwnerContext(t *testing.T) {
1880 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
ConstructorMethod · 0.80
IsExceptionMethod · 0.80
SetMethod · 0.80
GetGoObjectMethod · 0.80

Tested by

no test coverage detected