mirror of
https://github.com/robertkrimen/otto
synced 2025-10-05 19:19:10 +08:00
Handle []uint16 to boolean conversion (resolves #232)
This commit is contained in:
parent
bf1c3795ba
commit
7a965dd45d
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"unicode/utf16"
|
||||
)
|
||||
|
||||
func (value Value) bool() bool {
|
||||
|
@ -32,6 +33,8 @@ func (value Value) bool() bool {
|
|||
return true
|
||||
case string:
|
||||
return 0 != len(value)
|
||||
case []uint16:
|
||||
return 0 != len(utf16.Decode(value))
|
||||
}
|
||||
if value.IsObject() {
|
||||
return true
|
||||
|
|
|
@ -98,6 +98,8 @@ func TestToBoolean(t *testing.T) {
|
|||
//is(toValue(newObject()), true)
|
||||
is(UndefinedValue(), false)
|
||||
is(NullValue(), false)
|
||||
is([]uint16{}, false)
|
||||
is([]uint16{0x68, 0x65, 0x6c, 0x6c, 0x6f}, true)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user