1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00

fixes #165 - crash exporting an array with undefined as the first element

This commit is contained in:
deoxxa 2016-04-04 00:24:47 +10:00
parent 53221230c2
commit da054efc5f
2 changed files with 9 additions and 1 deletions

View File

@ -690,7 +690,9 @@ func (self Value) export() interface{} {
} }
value := object.get(name).export() value := object.get(name).export()
t = reflect.TypeOf(value) t = reflect.TypeOf(value)
if state == 0 { if t == nil {
state = 2
} else if state == 0 {
kind = t.Kind() kind = t.Kind()
state = 1 state = 1
} else if state == 1 && kind != t.Kind() { } else if state == 1 && kind != t.Kind() {

View File

@ -237,6 +237,12 @@ func TestExport(t *testing.T) {
is(value[5], nil) is(value[5], nil)
is(value[5], interface{}(nil)) is(value[5], interface{}(nil))
} }
{
value := test(`[ undefined, null ];`).export().([]interface{})
is(value[0], nil)
is(value[1], nil)
is(value[1], interface{}(nil))
}
roundtrip := []interface{}{ roundtrip := []interface{}{
true, true,