mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
Add delete to type_array
This commit is contained in:
parent
38f6d71ff2
commit
e5ff4cef59
12
otto_test.go
12
otto_test.go
|
@ -1262,9 +1262,9 @@ func TestArray(t *testing.T) {
|
|||
test := runTest()
|
||||
|
||||
test(`
|
||||
abc = ""+[0, 1, 2, 3]
|
||||
def = [].toString()
|
||||
ghi = [null, 4, "null"].toString()
|
||||
abc = ""+[0, 1, 2, 3];
|
||||
def = [].toString();
|
||||
ghi = [null, 4, "null"].toString();
|
||||
`)
|
||||
test("abc", "0,1,2,3")
|
||||
test("def", "")
|
||||
|
@ -1272,6 +1272,12 @@ func TestArray(t *testing.T) {
|
|||
test(`new Array(0).length`, "0")
|
||||
test(`new Array(11).length`, "11")
|
||||
test(`new Array(11, 1).length`, "2")
|
||||
|
||||
test(`
|
||||
abc = [0, 1, 2, 3];
|
||||
delete abc[1];
|
||||
abc;
|
||||
`, "0,,2,3")
|
||||
}
|
||||
|
||||
func TestArray_toString(t *testing.T) {
|
||||
|
|
|
@ -117,7 +117,7 @@ func (self *_arrayStash) property(name string) *_property {
|
|||
if name == "length" {
|
||||
return &_property{
|
||||
value: toValue(len(self.valueArray)),
|
||||
mode: 0100, // +Write -Enumerate -Configure
|
||||
mode: 0100, // +w-ec
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ func (self *_arrayStash) property(name string) *_property {
|
|||
}
|
||||
return &_property{
|
||||
value: value,
|
||||
mode: 0111, // +Write +Enumerate +Configure
|
||||
mode: 0111, // +wec
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,3 +148,19 @@ func (self *_arrayStash) enumerate(each func(string)) {
|
|||
}
|
||||
self._stash.enumerate(each)
|
||||
}
|
||||
|
||||
func (self *_arrayStash) delete(name string) {
|
||||
// length
|
||||
if name == "length" {
|
||||
return
|
||||
}
|
||||
|
||||
// .0, .1, .2, ...
|
||||
index := stringToArrayIndex(name)
|
||||
if index >= 0 {
|
||||
if index < int64(len(self.valueArray)) {
|
||||
self.valueArray[index] = emptyValue()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user