mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
feat: support null value returns for toValue (#325)
Add nullValue as the return value for the nil case in toValue. Co-authored-by: Ryan Macleod <ryan.macleod@cumul8.com>
This commit is contained in:
parent
67c8da69a8
commit
26cb6ccce6
|
@ -228,7 +228,7 @@ func Test_reflectStruct(t *testing.T) {
|
||||||
|
|
||||||
test(`
|
test(`
|
||||||
ret = abc.FuncReturn2();
|
ret = abc.FuncReturn2();
|
||||||
if (ret && ret.length && ret.length == 2 && ret[0] == "def" && ret[1] === undefined) {
|
if (ret && ret.length && ret.length == 2 && ret[0] == "def" && ret[1] === null) {
|
||||||
true;
|
true;
|
||||||
} else {
|
} else {
|
||||||
false;
|
false;
|
||||||
|
|
3
value.go
3
value.go
|
@ -325,8 +325,7 @@ func toValue(value interface{}) Value {
|
||||||
case _result:
|
case _result:
|
||||||
return Value{valueResult, value}
|
return Value{valueResult, value}
|
||||||
case nil:
|
case nil:
|
||||||
// TODO Ugh.
|
return nullValue
|
||||||
return Value{}
|
|
||||||
case reflect.Value:
|
case reflect.Value:
|
||||||
for value.Kind() == reflect.Ptr {
|
for value.Kind() == reflect.Ptr {
|
||||||
// We were given a pointer, so we'll drill down until we get a non-pointer
|
// We were given a pointer, so we'll drill down until we get a non-pointer
|
||||||
|
|
|
@ -39,7 +39,8 @@ func TestToValue(t *testing.T) {
|
||||||
vm := tester.vm
|
vm := tester.vm
|
||||||
|
|
||||||
value, _ := vm.ToValue(nil)
|
value, _ := vm.ToValue(nil)
|
||||||
is(value, "undefined")
|
is(value, "null")
|
||||||
|
is(value, nullValue)
|
||||||
|
|
||||||
value, _ = vm.ToValue((*byte)(nil))
|
value, _ = vm.ToValue((*byte)(nil))
|
||||||
is(value, "undefined")
|
is(value, "undefined")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user