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

21 lines
494 B
Go
Raw Normal View History

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