Skip to content

Commit da23df8

Browse files
committed
Revert "compiler/natives/src/reflect: Don't skip string internalization for types."
This reverts commit 2f2d5b3. That commit (and its commit message) was wrong/incomplete. Now I understand there was a reason for skipping string internalization for types. The following commit is a better alternative fix.
1 parent 0d1476f commit da23df8

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

compiler/natives/src/reflect/reflect.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func reflectType(typ *js.Object) *rtype {
4242
rt := &rtype{
4343
size: uintptr(typ.Get("size").Int()),
4444
kind: uint8(typ.Get("kind").Int()),
45-
str: newNameOff(newName(typ.Get("string").String(), "", typ.Get("exported").Bool())),
45+
str: newNameOff(newName(internalStr(typ.Get("string")), "", typ.Get("exported").Bool())),
4646
}
4747
js.InternalObject(rt).Set("jsType", typ)
4848
typ.Set("reflectType", js.InternalObject(rt))
@@ -57,12 +57,12 @@ func reflectType(typ *js.Object) *rtype {
5757
for i := range reflectMethods {
5858
m := methodSet.Index(i)
5959
reflectMethods[i] = method{
60-
name: newNameOff(newName(m.Get("name").String(), "", m.Get("pkg").String() == "")),
60+
name: newNameOff(newName(internalStr(m.Get("name")), "", internalStr(m.Get("pkg")) == "")),
6161
mtyp: newTypeOff(reflectType(m.Get("typ"))),
6262
}
6363
}
6464
ut := &uncommonType{
65-
pkgPath: newNameOff(newName(typ.Get("pkg").String(), "", false)),
65+
pkgPath: newNameOff(newName(internalStr(typ.Get("pkg")), "", false)),
6666
mcount: uint16(methodSet.Length()),
6767
_methods: reflectMethods,
6868
}
@@ -116,13 +116,13 @@ func reflectType(typ *js.Object) *rtype {
116116
for i := range imethods {
117117
m := methods.Index(i)
118118
imethods[i] = imethod{
119-
name: newNameOff(newName(m.Get("name").String(), "", m.Get("pkg").String() == "")),
119+
name: newNameOff(newName(internalStr(m.Get("name")), "", internalStr(m.Get("pkg")) == "")),
120120
typ: newTypeOff(reflectType(m.Get("typ"))),
121121
}
122122
}
123123
setKindType(rt, &interfaceType{
124124
rtype: *rt,
125-
pkgPath: newName(typ.Get("pkg").String(), "", false),
125+
pkgPath: newName(internalStr(typ.Get("pkg")), "", false),
126126
methods: imethods,
127127
})
128128
case Map:
@@ -148,14 +148,14 @@ func reflectType(typ *js.Object) *rtype {
148148
offsetAnon |= 1
149149
}
150150
reflectFields[i] = structField{
151-
name: newName(f.Get("name").String(), f.Get("tag").String(), f.Get("exported").Bool()),
151+
name: newName(internalStr(f.Get("name")), internalStr(f.Get("tag")), f.Get("exported").Bool()),
152152
typ: reflectType(f.Get("typ")),
153153
offsetAnon: offsetAnon,
154154
}
155155
}
156156
setKindType(rt, &structType{
157157
rtype: *rt,
158-
pkgPath: newName(typ.Get("pkgPath").String(), "", false),
158+
pkgPath: newName(internalStr(typ.Get("pkgPath")), "", false),
159159
fields: reflectFields,
160160
})
161161
}
@@ -259,6 +259,12 @@ func newTypeOff(t *rtype) typeOff {
259259
return typeOff(i)
260260
}
261261

262+
func internalStr(strObj *js.Object) string {
263+
var c struct{ str string }
264+
js.InternalObject(c).Set("str", strObj) // get string without internalizing
265+
return c.str
266+
}
267+
262268
func isWrapped(typ Type) bool {
263269
return jsType(typ).Get("wrapped").Bool()
264270
}

0 commit comments

Comments
 (0)