rum-goggles/v1/vendor/github.com/robertkrimen/otto/value_primitive.go

21 lines
494 B
Go
Raw Permalink Normal View History

package otto
func toNumberPrimitive(value Value) Value {
2024-04-04 14:46:14 +00:00
return toPrimitive(value, defaultValueHintNumber)
}
2024-04-04 14:46:14 +00:00
func toPrimitiveValue(value Value) Value {
return toPrimitive(value, defaultValueNoHint)
}
2024-04-04 14:46:14 +00:00
func toPrimitive(value Value, hint defaultValueHint) Value {
switch value.kind {
case valueNull, valueUndefined, valueNumber, valueString, valueBoolean:
return value
case valueObject:
2024-04-04 14:46:14 +00:00
return value.object().DefaultValue(hint)
default:
panic(hereBeDragons(value.kind, value))
}
}