github.com/gopherjs/gopherjs@v1.19.0-beta1.0.20240506212314-27071a8796e4/compiler/natives/src/internal/reflectlite/export_test.go (about) 1 //go:build js 2 // +build js 3 4 package reflectlite 5 6 import ( 7 "unsafe" 8 ) 9 10 // Field returns the i'th field of the struct v. 11 // It panics if v's Kind is not Struct or i is out of range. 12 func Field(v Value, i int) Value { 13 if v.kind() != Struct { 14 panic(&ValueError{"reflect.Value.Field", v.kind()}) 15 } 16 return v.Field(i) 17 } 18 19 func TField(typ Type, i int) Type { 20 t := typ.(*rtype) 21 if t.Kind() != Struct { 22 panic("reflect: Field of non-struct type") 23 } 24 tt := (*structType)(unsafe.Pointer(t)) 25 return StructFieldType(tt, i) 26 } 27 28 // Field returns the i'th struct field. 29 func StructFieldType(t *structType, i int) Type { 30 if i < 0 || i >= len(t.fields) { 31 panic("reflect: Field index out of bounds") 32 } 33 p := &t.fields[i] 34 return toType(p.typ) 35 }