Permalink
Browse files

Revert "compiler/natives/src/reflect: Don't skip string internalizati…

…on 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.
  • Loading branch information...
dmitshur committed Jan 11, 2018
1 parent 0d1476f commit da23df8262780a0fdf35908aa0c291fe976cd67e
Showing with 13 additions and 7 deletions.
  1. +13 −7 compiler/natives/src/reflect/reflect.go
@@ -42,7 +42,7 @@ func reflectType(typ *js.Object) *rtype {
rt := &rtype{
size: uintptr(typ.Get("size").Int()),
kind: uint8(typ.Get("kind").Int()),
str: newNameOff(newName(typ.Get("string").String(), "", typ.Get("exported").Bool())),
str: newNameOff(newName(internalStr(typ.Get("string")), "", typ.Get("exported").Bool())),
}
js.InternalObject(rt).Set("jsType", typ)
typ.Set("reflectType", js.InternalObject(rt))
@@ -57,12 +57,12 @@ func reflectType(typ *js.Object) *rtype {
for i := range reflectMethods {
m := methodSet.Index(i)
reflectMethods[i] = method{
name: newNameOff(newName(m.Get("name").String(), "", m.Get("pkg").String() == "")),
name: newNameOff(newName(internalStr(m.Get("name")), "", internalStr(m.Get("pkg")) == "")),
mtyp: newTypeOff(reflectType(m.Get("typ"))),
}
}
ut := &uncommonType{
pkgPath: newNameOff(newName(typ.Get("pkg").String(), "", false)),
pkgPath: newNameOff(newName(internalStr(typ.Get("pkg")), "", false)),
mcount: uint16(methodSet.Length()),
_methods: reflectMethods,
}
@@ -116,13 +116,13 @@ func reflectType(typ *js.Object) *rtype {
for i := range imethods {
m := methods.Index(i)
imethods[i] = imethod{
name: newNameOff(newName(m.Get("name").String(), "", m.Get("pkg").String() == "")),
name: newNameOff(newName(internalStr(m.Get("name")), "", internalStr(m.Get("pkg")) == "")),
typ: newTypeOff(reflectType(m.Get("typ"))),
}
}
setKindType(rt, &interfaceType{
rtype: *rt,
pkgPath: newName(typ.Get("pkg").String(), "", false),
pkgPath: newName(internalStr(typ.Get("pkg")), "", false),
methods: imethods,
})
case Map:
@@ -148,14 +148,14 @@ func reflectType(typ *js.Object) *rtype {
offsetAnon |= 1
}
reflectFields[i] = structField{
name: newName(f.Get("name").String(), f.Get("tag").String(), f.Get("exported").Bool()),
name: newName(internalStr(f.Get("name")), internalStr(f.Get("tag")), f.Get("exported").Bool()),
typ: reflectType(f.Get("typ")),
offsetAnon: offsetAnon,
}
}
setKindType(rt, &structType{
rtype: *rt,
pkgPath: newName(typ.Get("pkgPath").String(), "", false),
pkgPath: newName(internalStr(typ.Get("pkgPath")), "", false),
fields: reflectFields,
})
}
@@ -259,6 +259,12 @@ func newTypeOff(t *rtype) typeOff {
return typeOff(i)
}
func internalStr(strObj *js.Object) string {
var c struct{ str string }
js.InternalObject(c).Set("str", strObj) // get string without internalizing
return c.str
}
func isWrapped(typ Type) bool {
return jsType(typ).Get("wrapped").Bool()
}

0 comments on commit da23df8

Please sign in to comment.