use std::cell::RefCell;
use std::rc::Rc;
use crate::RuntimeError;
use crate::vm::object::JSObject;
use crate::vm::value::Value;
pub fn register_boolean_prototype(proto: &Rc<RefCell<dyn JSObject>>) {
use super::set_prototype_method;
set_prototype_method(proto, "valueOf", |this, _args| boolean_value_of(this));
set_prototype_method(proto, "toString", |this, _args| boolean_to_string(this));
}
pub fn boolean_constructor(args: &[Value]) -> Result<Value, RuntimeError> {
if args.is_empty() {
Ok(Value::Bool(false))
} else {
Ok(Value::Bool(args[0].to_boolean()))
}
}
pub fn boolean_value_of(obj: &Value) -> Result<Value, RuntimeError> {
Ok(Value::Bool(obj.to_primitive("default").to_boolean()))
}
pub fn boolean_to_string(obj: &Value) -> Result<Value, RuntimeError> {
Ok(Value::string(&obj.to_boolean().to_string()))
}