Handle out of range on Listbox.Delete(). The Mac OS X exception behavior I previously noted has bene resolved: what happens after exception handling is undefined :|

This commit is contained in:
Pietro Gagliardi 2014-03-11 13:37:19 -04:00
parent cbcf9da6a0
commit c43583fe20
3 changed files with 16 additions and 6 deletions

View File

@ -69,17 +69,24 @@ badrange:
panic(fmt.Errorf("index %d out of range in Listbox.InsertBefore()", before))
}
// Delete removes the given item from the Listbox.
// (TODO action on invalid index)
// Delete removes the given item from the Listbox. It panics if the given index is out of bounds.
func (l *Listbox) Delete(index int) error {
l.lock.Lock()
defer l.lock.Unlock()
if l.created {
if index < 0 || index >= l.sysData.len() {
goto badrange
}
return l.sysData.delete(index)
}
if index < 0 || index >= len(l.initItems) {
goto badrange
}
l.initItems = append(l.initItems[:index], l.initItems[index + 1:]...)
return nil
badrange:
panic(fmt.Errorf("index %d out of range in Listbox.Delete()", index))
}
// Selection returns a list of strings currently selected in the Listbox, or an empty list if none have been selected. This list will have at most one item on a single-selection Listbox.

View File

@ -57,7 +57,7 @@ func invalidTest(c *Combobox, l *Listbox) {
defer x("Combobox.Delete < 0"); c.Delete(-5); panic(nil)
}()
func() {
defer x("Listbox.Delete > len"); c.Delete(c.Len() + 5); panic(nil)
defer x("Combobox.Delete > len"); c.Delete(c.Len() + 5); panic(nil)
}()
func() {
defer x("Listbox.InsertBefore < 0"); l.InsertBefore("xxx", -5); panic(nil)
@ -65,7 +65,12 @@ func invalidTest(c *Combobox, l *Listbox) {
func() {
defer x("Listbox.InsertBefore > len"); l.InsertBefore("xxx", l.Len() + 5); panic(nil)
}()
// TODO add Listbox.Delete() tests when I move that over
func() {
defer x("Listbox.Delete < 0"); l.Delete(-5); panic(nil)
}()
func() {
defer x("Listbox.Delete > len"); l.Delete(c.Len() + 5); panic(nil)
}()
MsgBox("test", "all working as intended")
}

View File

@ -70,8 +70,6 @@ super ultra important things:
(test:17575): Gtk-CRITICAL **: gtk_device_grab_remove: assertion 'GDK_IS_DEVICE (device)' failed
```
figure out why
- Mac OS X 32-bit builds don't call runtime.sighandler() on a Cocoa exception like the 64-bit builds do
- does array index out of bounds on 32-bit Cocoa not generate a SIGTRAP like invalid selector does? need to experiment... or is something clobbering SIGTRAP? I didn't catch it in my tests here...
- the user can still [NSApp terminate:] from the Dock icon, bypassing Go itself
- ideally we need a QuitItem() function for this case if/when we add menus