MCPcopy
hub / github.com/gopherjs/gopherjs / Field

Method Field

compiler/natives/src/reflect/reflect.go:1056–1104  ·  view source on GitHub ↗

gopherjs:replace

(i int)

Source from the content-addressed store, hash-verified

1054
1055//gopherjs:replace
1056func (v Value) Field(i int) Value {
1057 if v.kind() != Struct {
1058 panic(&ValueError{"reflect.Value.Field", v.kind()})
1059 }
1060 tt := (*structType)(unsafe.Pointer(v.typ()))
1061 if uint(i) >= uint(len(tt.Fields)) {
1062 panic("reflect: Field index out of range")
1063 }
1064
1065 prop := v.typ().JsType().Get("fields").Index(i).Get("prop").String()
1066 field := &tt.Fields[i]
1067 typ := field.Typ
1068
1069 fl := v.flag&(flagStickyRO|flagIndir|flagAddr) | flag(typ.Kind())
1070 if !field.Name.IsExported() {
1071 if field.Embedded() {
1072 fl |= flagEmbedRO
1073 } else {
1074 fl |= flagStickyRO
1075 }
1076 }
1077
1078 if tag := tt.Fields[i].Name.Tag(); tag != "" && i != 0 {
1079 if jsTag := StructTag(tag).Get(`js`); jsTag != "" {
1080 for {
1081 v = v.Field(0)
1082 if v.typ() == abi.JsObjectPtr {
1083 o := v.object().Get("object")
1084 return Value{typ, unsafe.Pointer(typ.JsPtrTo().New(
1085 js.InternalObject(func() *js.Object { return js.Global.Call("$internalize", o.Get(jsTag), typ.JsType()) }),
1086 js.InternalObject(func(x *js.Object) { o.Set(jsTag, js.Global.Call("$externalize", x, typ.JsType())) }),
1087 ).Unsafe()), fl}
1088 }
1089 if v.typ().Kind() == abi.Pointer {
1090 v = v.Elem()
1091 }
1092 }
1093 }
1094 }
1095
1096 s := js.InternalObject(v.ptr)
1097 if fl&flagIndir != 0 && typ.Kind() != abi.Array && typ.Kind() != abi.Struct {
1098 return Value{typ, unsafe.Pointer(typ.JsPtrTo().New(
1099 js.InternalObject(func() *js.Object { return abi.WrapJsObject(typ, s.Get(prop)) }),
1100 js.InternalObject(func(x *js.Object) { s.Set(prop, abi.UnwrapJsObject(typ, x)) }),
1101 ).Unsafe()), fl}
1102 }
1103 return makeValue(typ, abi.WrapJsObject(typ, s.Get(prop)), fl)
1104}
1105
1106//gopherjs:replace
1107func (v Value) UnsafePointer() unsafe.Pointer {

Callers 10

initArgsMethod · 0.45
translateSelectionMethod · 0.45
fieldTypeMethod · 0.45
fieldNameFunction · 0.45
translateExprMethod · 0.45
isGenericFunction · 0.45
StructMethod · 0.45
fieldsOfFunction · 0.45
OffsetOfFunction · 0.45
deepValueEqualJsFunction · 0.45

Calls 15

objectMethod · 0.95
SetMethod · 0.95
ElemMethod · 0.95
GetMethod · 0.95
InternalObjectFunction · 0.92
PointerMethod · 0.80
typMethod · 0.80
JsTypeMethod · 0.80
IsExportedMethod · 0.80
TagMethod · 0.80
UnsafeMethod · 0.80
JsPtrToMethod · 0.80

Tested by

no test coverage detected