1
0
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:
Simon Stone 2016-11-24 16:28:05 +00:00
parent bf1c3795ba
commit 7a965dd45d
2 changed files with 5 additions and 0 deletions

View File

@ -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

View File

@ -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)
})
}