|
@@ -18,7 +18,7 @@ type FieldNameMapper interface {
|
|
// If this method returns "" the field becomes hidden.
|
|
// If this method returns "" the field becomes hidden.
|
|
FieldName(t reflect.Type, f reflect.StructField) string
|
|
FieldName(t reflect.Type, f reflect.StructField) string
|
|
|
|
|
|
- // FieldName returns a JavaScript name for the given method in the given type.
|
|
|
|
|
|
+ // MethodName returns a JavaScript name for the given method in the given type.
|
|
// If this method returns "" the method becomes hidden.
|
|
// If this method returns "" the method becomes hidden.
|
|
MethodName(t reflect.Type, m reflect.Method) string
|
|
MethodName(t reflect.Type, m reflect.Method) string
|
|
}
|
|
}
|
|
@@ -216,25 +216,23 @@ func (r *Runtime) checkHostObjectPropertyDescr(name string, descr propertyDescr,
|
|
}
|
|
}
|
|
|
|
|
|
func (o *objectGoReflect) defineOwnProperty(n Value, descr propertyDescr, throw bool) bool {
|
|
func (o *objectGoReflect) defineOwnProperty(n Value, descr propertyDescr, throw bool) bool {
|
|
- name := n.String()
|
|
|
|
- if ast.IsExported(name) {
|
|
|
|
- if o.value.Kind() == reflect.Struct {
|
|
|
|
- if v := o._getField(name); v.IsValid() {
|
|
|
|
- if !o.val.runtime.checkHostObjectPropertyDescr(name, descr, throw) {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- val := descr.Value
|
|
|
|
- if val == nil {
|
|
|
|
- val = _undefined
|
|
|
|
- }
|
|
|
|
- vv, err := o.val.runtime.toReflectValue(val, v.Type())
|
|
|
|
- if err != nil {
|
|
|
|
- o.val.runtime.typeErrorResult(throw, "Go struct conversion error: %v", err)
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- v.Set(vv)
|
|
|
|
- return true
|
|
|
|
|
|
+ if o.value.Kind() == reflect.Struct {
|
|
|
|
+ name := n.String()
|
|
|
|
+ if v := o._getField(name); v.IsValid() {
|
|
|
|
+ if !o.val.runtime.checkHostObjectPropertyDescr(name, descr, throw) {
|
|
|
|
+ return false
|
|
}
|
|
}
|
|
|
|
+ val := descr.Value
|
|
|
|
+ if val == nil {
|
|
|
|
+ val = _undefined
|
|
|
|
+ }
|
|
|
|
+ vv, err := o.val.runtime.toReflectValue(val, v.Type())
|
|
|
|
+ if err != nil {
|
|
|
|
+ o.val.runtime.typeErrorResult(throw, "Go struct conversion error: %v", err)
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ v.Set(vv)
|
|
|
|
+ return true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -242,9 +240,6 @@ func (o *objectGoReflect) defineOwnProperty(n Value, descr propertyDescr, throw
|
|
}
|
|
}
|
|
|
|
|
|
func (o *objectGoReflect) _has(name string) bool {
|
|
func (o *objectGoReflect) _has(name string) bool {
|
|
- if !ast.IsExported(name) {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
if o.value.Kind() == reflect.Struct {
|
|
if o.value.Kind() == reflect.Struct {
|
|
if v := o._getField(name); v.IsValid() {
|
|
if v := o._getField(name); v.IsValid() {
|
|
return true
|
|
return true
|
|
@@ -508,7 +503,7 @@ func (r *Runtime) typeInfo(t reflect.Type) (info *reflectTypeInfo) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-// Sets a custom field name mapper for Go types. It can be called at any time, however
|
|
|
|
|
|
+// SetFieldNameMapper sets a custom field name mapper for Go types. It can be called at any time, however
|
|
// the mapping for any given value is fixed at the point of creation.
|
|
// the mapping for any given value is fixed at the point of creation.
|
|
// Setting this to nil restores the default behaviour which is all exported fields and methods are mapped to their
|
|
// Setting this to nil restores the default behaviour which is all exported fields and methods are mapped to their
|
|
// original unchanged names.
|
|
// original unchanged names.
|