@@ -50,7 +50,7 @@ func reflectType(typ *js.Object) *rtype {
50
50
rt := & rtype {
51
51
size : uintptr (typ .Get ("size" ).Int ()),
52
52
kind : uint8 (typ .Get ("kind" ).Int ()),
53
- str : newNameOff (newNameWithoutEmbed (internalStr (typ .Get ("string" )), "" , typ .Get ("exported" ).Bool ())),
53
+ str : newNameOff (newName (internalStr (typ .Get ("string" )), "" , typ .Get ("exported" ).Bool (), false )),
54
54
}
55
55
js .InternalObject (rt ).Set (idJsType , typ )
56
56
typ .Set (idReflectType , js .InternalObject (rt ))
@@ -69,7 +69,7 @@ func reflectType(typ *js.Object) *rtype {
69
69
continue
70
70
}
71
71
reflectMethods = append (reflectMethods , method {
72
- name : newNameOff (newNameWithoutEmbed (internalStr (m .Get ("name" )), "" , exported )),
72
+ name : newNameOff (newName (internalStr (m .Get ("name" )), "" , exported , false )),
73
73
mtyp : newTypeOff (reflectType (m .Get ("typ" ))),
74
74
})
75
75
}
@@ -81,12 +81,12 @@ func reflectType(typ *js.Object) *rtype {
81
81
continue
82
82
}
83
83
reflectMethods = append (reflectMethods , method {
84
- name : newNameOff (newNameWithoutEmbed (internalStr (m .Get ("name" )), "" , exported )),
84
+ name : newNameOff (newName (internalStr (m .Get ("name" )), "" , exported , false )),
85
85
mtyp : newTypeOff (reflectType (m .Get ("typ" ))),
86
86
})
87
87
}
88
88
ut := & uncommonType {
89
- pkgPath : newNameOff (newNameWithoutEmbed (internalStr (typ .Get ("pkg" )), "" , false )),
89
+ pkgPath : newNameOff (newName (internalStr (typ .Get ("pkg" )), "" , false , false )),
90
90
mcount : uint16 (methodSet .Length ()),
91
91
xcount : xcount ,
92
92
_methods : reflectMethods ,
@@ -141,13 +141,13 @@ func reflectType(typ *js.Object) *rtype {
141
141
for i := range imethods {
142
142
m := methods .Index (i )
143
143
imethods [i ] = imethod {
144
- name : newNameOff (newNameWithoutEmbed (internalStr (m .Get ("name" )), "" , internalStr (m .Get ("pkg" )) == "" )),
144
+ name : newNameOff (newName (internalStr (m .Get ("name" )), "" , internalStr (m .Get ("pkg" )) == "" , false )),
145
145
typ : newTypeOff (reflectType (m .Get ("typ" ))),
146
146
}
147
147
}
148
148
setKindType (rt , & interfaceType {
149
149
rtype : * rt ,
150
- pkgPath : newNameWithoutEmbed (internalStr (typ .Get ("pkg" )), "" , false ),
150
+ pkgPath : newName (internalStr (typ .Get ("pkg" )), "" , false , false ),
151
151
methods : imethods ,
152
152
})
153
153
case Map :
@@ -167,11 +167,16 @@ func reflectType(typ *js.Object) *rtype {
167
167
fields := typ .Get ("fields" )
168
168
reflectFields := make ([]structField , fields .Length ())
169
169
for i := range reflectFields {
170
- reflectFields [i ] = buildStructField (i , fields .Index (i ))
170
+ f := fields .Index (i )
171
+ reflectFields [i ] = structField {
172
+ name : newName (internalStr (f .Get ("name" )), internalStr (f .Get ("tag" )), f .Get ("exported" ).Bool (), f .Get ("embedded" ).Bool ()),
173
+ typ : reflectType (f .Get ("typ" )),
174
+ offset : uintptr (i ),
175
+ }
171
176
}
172
177
setKindType (rt , & structType {
173
178
rtype : * rt ,
174
- pkgPath : newNameWithoutEmbed (internalStr (typ .Get ("pkgPath" )), "" , false ),
179
+ pkgPath : newName (internalStr (typ .Get ("pkgPath" )), "" , false , false ),
175
180
fields : reflectFields ,
176
181
})
177
182
}
@@ -242,6 +247,20 @@ func (n name) name() (s string) { return nameMap[n.bytes].name }
242
247
func (n name ) tag () (s string ) { return nameMap [n .bytes ].tag }
243
248
func (n name ) pkgPath () string { return "" }
244
249
func (n name ) isExported () bool { return nameMap [n .bytes ].exported }
250
+ func (n name ) embedded () bool { return nameMap [n .bytes ].embedded }
251
+
252
+ func newName (n , tag string , exported , embedded bool ) name {
253
+ b := new (byte )
254
+ nameMap [b ] = & nameData {
255
+ name : n ,
256
+ tag : tag ,
257
+ exported : exported ,
258
+ embedded : embedded ,
259
+ }
260
+ return name {
261
+ bytes : b ,
262
+ }
263
+ }
245
264
246
265
var nameOffList []name
247
266
0 commit comments