/* Value compatibility between js and go. js => go number => float64 bool => boolean string => string function => v7.Function array => []byte object => []byte */ func toValue(ctx *Context, result C.v7_val_t) (interface{}, error) { rctx := ctx.rctx switch C._val_type(rctx, C.uint64_t(result)) { case _V7_TYPE_UNDEFINED: return UndefinedValue, nil case _V7_TYPE_NULL: return NullValue, nil case _V7_TYPE_NUMBER: return JSNumber(C.v7_to_number(result)), nil case _V7_TYPE_STRING: return JSString(C.GoString(C._v7_to_string(rctx, &result))), nil case _V7_TYPE_BOOLEAN: if int(C.v7_to_boolean(result)) == 0 { return JSFalse, nil } else { return JSTrue, nil } case _V7_TYPE_ARRAY_OBJECT, _V7_TYPE_GENERIC_OBJECT: return _v7_to_json(rctx, result, ctx.bufSize), nil case _V7_TYPE_FUNCTION_OBJECT: return &JSFunction{ctx, result}, nil default: return nil, errUndefinedType } }
func (v7 *V7) ToNumber(v Val) (float64, error) { if !v7.IsNumber(v) { return math.NaN(), errors.New("value is not a number") } return float64(C.v7_to_number(C.v7_val_t(v))), nil }