github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/compiler/natives/src/internal/reflectlite/export_test.go (about)

     1  // +build js
     2  
     3  package reflectlite
     4  
     5  import (
     6  	"unsafe"
     7  )
     8  
     9  // Field returns the i'th field of the struct v.
    10  // It panics if v's Kind is not Struct or i is out of range.
    11  func Field(v Value, i int) Value {
    12  	if v.kind() != Struct {
    13  		panic(&ValueError{"reflect.Value.Field", v.kind()})
    14  	}
    15  	return v.Field(i)
    16  }
    17  
    18  func TField(typ Type, i int) Type {
    19  	t := typ.(*rtype)
    20  	if t.Kind() != Struct {
    21  		panic("reflect: Field of non-struct type")
    22  	}
    23  	tt := (*structType)(unsafe.Pointer(t))
    24  	return StructFieldType(tt, i)
    25  }
    26  
    27  // Field returns the i'th struct field.
    28  func StructFieldType(t *structType, i int) Type {
    29  	if i < 0 || i >= len(t.fields) {
    30  		panic("reflect: Field index out of bounds")
    31  	}
    32  	p := &t.fields[i]
    33  	return toType(p.typ)
    34  }
    35  
    36  // // Zero returns a Value representing the zero value for the specified type.
    37  // // The result is different from the zero value of the Value struct,
    38  // // which represents no value at all.
    39  // // For example, Zero(TypeOf(42)) returns a Value with Kind Int and value 0.
    40  // // The returned value is neither addressable nor settable.
    41  // func Zero(typ Type) Value {
    42  // 	if typ == nil {
    43  // 		panic("reflect: Zero(nil)")
    44  // 	}
    45  // 	t := typ.(*rtype)
    46  // 	fl := flag(t.Kind())
    47  // 	if ifaceIndir(t) {
    48  // 		return Value{t, unsafe_New(t), fl | flagIndir}
    49  // 	}
    50  // 	return Value{t, nil, fl}
    51  // }
    52  
    53  // // ToInterface returns v's current value as an interface{}.
    54  // // It is equivalent to:
    55  // //	var i interface{} = (v's underlying value)
    56  // // It panics if the Value was obtained by accessing
    57  // // unexported struct fields.
    58  // func ToInterface(v Value) (i interface{}) {
    59  // 	return valueInterface(v)
    60  // }
    61  
    62  // type EmbedWithUnexpMeth struct{}
    63  
    64  // func (EmbedWithUnexpMeth) f() {}
    65  
    66  // type pinUnexpMeth interface {
    67  // 	f()
    68  // }
    69  
    70  // var pinUnexpMethI = pinUnexpMeth(EmbedWithUnexpMeth{})
    71  
    72  // func FirstMethodNameBytes(t Type) *byte {
    73  // 	_ = pinUnexpMethI
    74  
    75  // 	ut := t.uncommon()
    76  // 	if ut == nil {
    77  // 		panic("type has no methods")
    78  // 	}
    79  // 	m := ut.methods()[0]
    80  // 	mname := t.(*rtype).nameOff(m.name)
    81  // 	if *mname.data(0, "name flag field")&(1<<2) == 0 {
    82  // 		panic("method name does not have pkgPath *string")
    83  // 	}
    84  // 	return mname.bytes
    85  // }
    86  
    87  // type Buffer struct {
    88  // 	buf []byte
    89  // }