mirror of
https://github.com/robertkrimen/otto
synced 2025-10-26 20:28:49 +08:00
Beef up _property, remove _defineProperty
Remove uneeded _valueProperty
Rename to propertyMode_{write,enumerate,configure}
.Can* => writeable, enumerable, configureable
Privatize _property
Get rid of _defineProperty
This commit is contained in:
152
property.go
152
property.go
@@ -5,158 +5,52 @@ package otto
|
||||
type _propertyMode int
|
||||
|
||||
const (
|
||||
propertyModeWrite _propertyMode = 0100
|
||||
propertyModeEnumerate = 0010
|
||||
propertyModeConfigure = 0001
|
||||
propertyMode_write _propertyMode = 0100
|
||||
propertyMode_enumerate = 0010
|
||||
propertyMode_configure = 0001
|
||||
)
|
||||
|
||||
type _propertyGetSet [2]*_object
|
||||
|
||||
type _property struct {
|
||||
Value interface{}
|
||||
Mode _propertyMode
|
||||
value interface{}
|
||||
mode _propertyMode
|
||||
}
|
||||
|
||||
func (self _property) CanWrite() bool {
|
||||
return self.Mode&propertyModeWrite != 0
|
||||
func (self _property) writeable() bool {
|
||||
return self.mode & 0700 == 0100
|
||||
}
|
||||
|
||||
func (self _property) CanEnumerate() bool {
|
||||
return self.Mode&propertyModeEnumerate != 0
|
||||
func (self _property) enumerable() bool {
|
||||
return self.mode & 0070 == 0010
|
||||
}
|
||||
|
||||
func (self _property) CanConfigure() bool {
|
||||
return self.Mode&propertyModeConfigure != 0
|
||||
func (self _property) configureable() bool {
|
||||
return self.mode & 0007 == 0001
|
||||
}
|
||||
|
||||
func (self _property) toDefineProperty() _defineProperty {
|
||||
property := _defineProperty{
|
||||
Value: self.Value,
|
||||
}
|
||||
|
||||
{
|
||||
mode := self.Mode
|
||||
|
||||
if mode&propertyModeWrite != 0 {
|
||||
property.Write = propertyAttributeTrue
|
||||
} else {
|
||||
property.Write = propertyAttributeFalse
|
||||
}
|
||||
|
||||
if mode&propertyModeEnumerate != 0 {
|
||||
property.Enumerate = propertyAttributeTrue
|
||||
} else {
|
||||
property.Enumerate = propertyAttributeFalse
|
||||
}
|
||||
|
||||
if mode&propertyModeConfigure != 0 {
|
||||
property.Configure = propertyAttributeTrue
|
||||
} else {
|
||||
property.Configure = propertyAttributeFalse
|
||||
}
|
||||
}
|
||||
|
||||
return property
|
||||
}
|
||||
|
||||
func (self _property) Copy() *_property {
|
||||
func (self _property) copy() *_property {
|
||||
property := self
|
||||
return &property
|
||||
}
|
||||
|
||||
// _valueProperty
|
||||
|
||||
type _valueProperty struct {
|
||||
Value Value
|
||||
Mode _propertyMode
|
||||
}
|
||||
|
||||
// _defineProperty
|
||||
|
||||
type _propertyAttributeBoolean int
|
||||
|
||||
const (
|
||||
propertyAttributeNotSet _propertyAttributeBoolean = iota
|
||||
propertyAttributeTrue
|
||||
propertyAttributeFalse
|
||||
)
|
||||
|
||||
type _defineProperty struct {
|
||||
Value interface{}
|
||||
Write _propertyAttributeBoolean
|
||||
Enumerate _propertyAttributeBoolean
|
||||
Configure _propertyAttributeBoolean
|
||||
}
|
||||
|
||||
func (self _defineProperty) Mode() (mode _propertyMode) {
|
||||
if self.Write != propertyAttributeFalse {
|
||||
mode |= propertyModeWrite
|
||||
}
|
||||
if self.Enumerate != propertyAttributeFalse {
|
||||
mode |= propertyModeEnumerate
|
||||
}
|
||||
if self.Configure != propertyAttributeFalse {
|
||||
mode |= propertyModeConfigure
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (self _defineProperty) CanWrite() bool {
|
||||
return self.Write == propertyAttributeTrue
|
||||
}
|
||||
|
||||
func (self _defineProperty) CanEnumerate() bool {
|
||||
return self.Enumerate == propertyAttributeTrue
|
||||
}
|
||||
|
||||
func (self _defineProperty) CanConfigure() bool {
|
||||
return self.Configure == propertyAttributeTrue
|
||||
}
|
||||
|
||||
func (self _defineProperty) IsAccessorDescriptor() bool {
|
||||
setGet, test := self.Value.(_propertyGetSet)
|
||||
func (self _property) isAccessorDescriptor() bool {
|
||||
setGet, test := self.value.(_propertyGetSet)
|
||||
return test && setGet[0] != nil || setGet[1] != nil
|
||||
}
|
||||
|
||||
func (self _defineProperty) IsDataDescriptor() bool {
|
||||
value, test := self.Value.(Value)
|
||||
return self.Write != propertyAttributeNotSet || (test && !value.isEmpty())
|
||||
func (self _property) isDataDescriptor() bool {
|
||||
value, test := self.value.(Value)
|
||||
return self.mode & 0700 != 0200 || (test && !value.isEmpty())
|
||||
}
|
||||
|
||||
func (self _defineProperty) IsGenericDescriptor() bool {
|
||||
return !(self.IsDataDescriptor() || self.IsAccessorDescriptor())
|
||||
func (self _property) isGenericDescriptor() bool {
|
||||
return !(self.isDataDescriptor() || self.isAccessorDescriptor())
|
||||
}
|
||||
|
||||
func (self _defineProperty) isEmpty() bool {
|
||||
return self.IsGenericDescriptor() &&
|
||||
self.Write == propertyAttributeNotSet &&
|
||||
self.Enumerate == propertyAttributeNotSet &&
|
||||
self.Configure == propertyAttributeNotSet
|
||||
func (self _property) isEmpty() bool {
|
||||
return self.mode == 0222 && self.isGenericDescriptor()
|
||||
}
|
||||
|
||||
func (self _defineProperty) CopyInto(other *_property) {
|
||||
switch self.Write {
|
||||
case propertyAttributeTrue:
|
||||
other.Mode |= propertyModeWrite
|
||||
case propertyAttributeFalse:
|
||||
other.Mode &= ^propertyModeWrite
|
||||
}
|
||||
|
||||
switch self.Enumerate {
|
||||
case propertyAttributeTrue:
|
||||
other.Mode |= propertyModeEnumerate
|
||||
case propertyAttributeFalse:
|
||||
other.Mode &= ^propertyModeEnumerate
|
||||
}
|
||||
|
||||
switch self.Configure {
|
||||
case propertyAttributeTrue:
|
||||
other.Mode |= propertyModeConfigure
|
||||
case propertyAttributeFalse:
|
||||
other.Mode &= ^propertyModeConfigure
|
||||
}
|
||||
|
||||
if !self.IsGenericDescriptor() {
|
||||
other.Value = self.Value
|
||||
}
|
||||
}
|
||||
// _enumerableValue, _enumerableTrue, _enumerableFalse?
|
||||
// .enumerableValue()
|
||||
|
||||
Reference in New Issue
Block a user