2024-02-24 21:00:04 +00:00
|
|
|
package otto
|
|
|
|
|
|
|
|
func toNumberPrimitive(value Value) Value {
|
2024-04-04 14:46:14 +00:00
|
|
|
return toPrimitive(value, defaultValueHintNumber)
|
2024-02-24 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
2024-04-04 14:46:14 +00:00
|
|
|
func toPrimitiveValue(value Value) Value {
|
|
|
|
return toPrimitive(value, defaultValueNoHint)
|
2024-02-24 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
2024-04-04 14:46:14 +00:00
|
|
|
func toPrimitive(value Value, hint defaultValueHint) Value {
|
2024-02-24 21:00:04 +00:00
|
|
|
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))
|
2024-02-24 21:00:04 +00:00
|
|
|
}
|
|
|
|
}
|