mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
Reorganize (type_*) code layout
This commit is contained in:
parent
e5ff4cef59
commit
96601bf274
107
type_array.go
107
type_array.go
|
@ -26,20 +26,7 @@ func newArrayStash(valueArray []Value, stash _stash) *_arrayStash {
|
|||
return self
|
||||
}
|
||||
|
||||
func (self *_arrayStash) canPut(name string) bool {
|
||||
// length
|
||||
if name == "length" {
|
||||
return true
|
||||
}
|
||||
|
||||
// .0, .1, .2, ...
|
||||
index := stringToArrayIndex(name)
|
||||
if index >= 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
return self._stash.canPut(name)
|
||||
}
|
||||
// read
|
||||
|
||||
func (self *_arrayStash) test(name string) bool {
|
||||
// length
|
||||
|
@ -77,6 +64,60 @@ func (self *_arrayStash) get(name string) Value {
|
|||
return self._stash.get(name)
|
||||
}
|
||||
|
||||
func (self *_arrayStash) enumerate(each func(string)) {
|
||||
// .0, .1, .2, ...
|
||||
for index, _ := range self.valueArray {
|
||||
if self.valueArray[index]._valueType == valueEmpty {
|
||||
continue // A sparse array
|
||||
}
|
||||
name := strconv.FormatInt(int64(index), 10)
|
||||
each(name)
|
||||
}
|
||||
self._stash.enumerate(each)
|
||||
}
|
||||
|
||||
func (self *_arrayStash) property(name string) *_property {
|
||||
// length
|
||||
if name == "length" {
|
||||
return &_property{
|
||||
value: toValue(len(self.valueArray)),
|
||||
mode: 0100, // +w-ec
|
||||
}
|
||||
}
|
||||
|
||||
// .0, .1, .2, ...
|
||||
index := stringToArrayIndex(name)
|
||||
if index >= 0 {
|
||||
value := UndefinedValue()
|
||||
if index < int64(len(self.valueArray)) {
|
||||
value = self.valueArray[index]
|
||||
}
|
||||
return &_property{
|
||||
value: value,
|
||||
mode: 0111, // +wec
|
||||
}
|
||||
}
|
||||
|
||||
return self._stash.property(name)
|
||||
}
|
||||
|
||||
// write
|
||||
|
||||
func (self *_arrayStash) canPut(name string) bool {
|
||||
// length
|
||||
if name == "length" {
|
||||
return true
|
||||
}
|
||||
|
||||
// .0, .1, .2, ...
|
||||
index := stringToArrayIndex(name)
|
||||
if index >= 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
return self._stash.canPut(name)
|
||||
}
|
||||
|
||||
func (self *_arrayStash) put(name string, value Value) {
|
||||
// length
|
||||
if name == "length" {
|
||||
|
@ -112,43 +153,6 @@ func (self *_arrayStash) put(name string, value Value) {
|
|||
self._stash.put(name, value)
|
||||
}
|
||||
|
||||
func (self *_arrayStash) property(name string) *_property {
|
||||
// length
|
||||
if name == "length" {
|
||||
return &_property{
|
||||
value: toValue(len(self.valueArray)),
|
||||
mode: 0100, // +w-ec
|
||||
}
|
||||
}
|
||||
|
||||
// .0, .1, .2, ...
|
||||
index := stringToArrayIndex(name)
|
||||
if index >= 0 {
|
||||
value := UndefinedValue()
|
||||
if index < int64(len(self.valueArray)) {
|
||||
value = self.valueArray[index]
|
||||
}
|
||||
return &_property{
|
||||
value: value,
|
||||
mode: 0111, // +wec
|
||||
}
|
||||
}
|
||||
|
||||
return self._stash.property(name)
|
||||
}
|
||||
|
||||
func (self *_arrayStash) enumerate(each func(string)) {
|
||||
// .0, .1, .2, ...
|
||||
for index, _ := range self.valueArray {
|
||||
if self.valueArray[index]._valueType == valueEmpty {
|
||||
continue // A sparse array
|
||||
}
|
||||
name := strconv.FormatInt(int64(index), 10)
|
||||
each(name)
|
||||
}
|
||||
self._stash.enumerate(each)
|
||||
}
|
||||
|
||||
func (self *_arrayStash) delete(name string) {
|
||||
// length
|
||||
if name == "length" {
|
||||
|
@ -162,5 +166,4 @@ func (self *_arrayStash) delete(name string) {
|
|||
self.valueArray[index] = emptyValue()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -228,6 +228,8 @@ func newRegExpStash(_regExpObject *_regExpObject, stash _stash) *_regExpStash {
|
|||
return self
|
||||
}
|
||||
|
||||
// read
|
||||
|
||||
func (self *_regExpStash) test(name string) bool {
|
||||
switch name {
|
||||
case "global", "ignoreCase", "multiline", "lastIndex", "source":
|
||||
|
@ -252,16 +254,9 @@ func (self *_regExpStash) get(name string) Value {
|
|||
return self._stash.get(name)
|
||||
}
|
||||
|
||||
func (self *_regExpStash) put(name string, value Value) {
|
||||
switch name {
|
||||
case "global", "ignoreCase", "multiline", "source":
|
||||
// TODO Is this good enough? Check DefineOwnProperty
|
||||
panic(newTypeError())
|
||||
case "lastIndex":
|
||||
self._regExpObject.LastIndex = value
|
||||
return
|
||||
}
|
||||
self._stash.put(name, value)
|
||||
func (self *_regExpStash) enumerate(each func(string)) {
|
||||
// Skip global, ignoreCase, multiline, source, & lastIndex
|
||||
self._stash.enumerate(each)
|
||||
}
|
||||
|
||||
func (self *_regExpStash) property(name string) *_property {
|
||||
|
@ -280,7 +275,16 @@ func (self *_regExpStash) property(name string) *_property {
|
|||
return self._stash.property(name)
|
||||
}
|
||||
|
||||
func (self *_regExpStash) enumerate(each func(string)) {
|
||||
// Skip global, ignoreCase, multiline, source, & lastIndex
|
||||
self._stash.enumerate(each)
|
||||
// write
|
||||
|
||||
func (self *_regExpStash) put(name string, value Value) {
|
||||
switch name {
|
||||
case "global", "ignoreCase", "multiline", "source":
|
||||
// TODO Is this good enough? Check DefineOwnProperty
|
||||
panic(newTypeError())
|
||||
case "lastIndex":
|
||||
self._regExpObject.LastIndex = value
|
||||
return
|
||||
}
|
||||
self._stash.put(name, value)
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ func newStringStash(value string, stash _stash) *_stringStash {
|
|||
return self
|
||||
}
|
||||
|
||||
// read
|
||||
|
||||
func (self *_stringStash) test(name string) bool {
|
||||
// .length
|
||||
if name == "length" {
|
||||
|
@ -85,3 +87,5 @@ func (self *_stringStash) enumerate(each func(string)) {
|
|||
}
|
||||
self._stash.enumerate(each)
|
||||
}
|
||||
|
||||
// write
|
||||
|
|
Loading…
Reference in New Issue
Block a user