Closed stevenliebregt closed 1 year ago
Yes, it is! This is documented in the type hierarchy. The JsValue
type is a super type of all types. You can upcast()
to a JsValue
from any type to unify two different types.
fn object_or_undefined(mut cx: FunctionContext) -> JsResult<JsValue> {
let create_object = cx.argument::<JsBoolean>(0)?.value(&mut cx);
if create_object {
return Ok(cx.empty_object().upcast());
}
Ok(cx.undefined().upcast())
}
Ah that makes sense, must've missed that, thanks a lot!
Hi, I'm trying to create a function, that based on some parameter returns either a JSObject or undefined/null.
The returntype I have is
JsResult<JsObject>
because I can't find a way to do it optional.Is this supported?