pub fn to_object(&self, context: &mut Context) -> JsResult<JsObject> {
        match self {
            JsValue::Undefined | JsValue::Null => {
                Err(context.construct_type_error("cannot convert 'null' or 'undefined' to object"))
            }
            JsValue::Boolean(boolean) => {
                let prototype = context.standard_objects().boolean_object().prototype();
                Ok(JsObject::new(Object::with_prototype(
                    prototype.into(),
                    ObjectData::boolean(*boolean),
                )))
            }
            JsValue::Integer(integer) => {
                let prototype = context.standard_objects().number_object().prototype();
                Ok(JsObject::new(Object::with_prototype(
                    prototype.into(),
                    ObjectData::number(f64::from(*integer)),
                )))
            }
            JsValue::Rational(rational) => {
                let prototype = context.standard_objects().number_object().prototype();
                Ok(JsObject::new(Object::with_prototype(
                    prototype.into(),
                    ObjectData::number(*rational),
                )))
            }
            JsValue::String(ref string) => {
                let prototype = context.standard_objects().string_object().prototype();

                let object = JsObject::new(Object::with_prototype(
                    prototype.into(),
                    ObjectData::string(string.clone()),
                ));
                // Make sure the correct length is set on our new string object
                object.insert_property(
                    "length",
                    PropertyDescriptor::builder()
                        .value(string.encode_utf16().count())
                        .writable(false)
                        .enumerable(false)
                        .configurable(false),
                );
                Ok(object)
            }
            JsValue::Symbol(ref symbol) => {
                let prototype = context.standard_objects().symbol_object().prototype();
                Ok(JsObject::new(Object::with_prototype(
                    prototype.into(),
                    ObjectData::symbol(symbol.clone()),
                )))
            }
            JsValue::BigInt(ref bigint) => {
                let prototype = context.standard_objects().bigint_object().prototype();
                Ok(JsObject::new(Object::with_prototype(
                    prototype.into(),
                    ObjectData::big_int(bigint.clone()),
                )))
            }
            JsValue::Object(jsobject) => Ok(jsobject.clone()),
        }
    }
/// Converts the value to an Object.
///
/// This function is equivalent to `Object(value)` in JavaScript
///
/// See: <https://tc39.es/ecma262/#sec-toobject>
Converts the value to an Object.
This function is equivalent to `Object(value)` in JavaScript


Converts the value to an Object . This function is equivalent to ` Object ( value ) ` in JavaScript
pub fn to_object(&self, context: &mut Context) -> JsResult<JsObject> {
        match self {
            JsValue::Undefined | JsValue::Null => {
                Err(context.construct_type_error("cannot convert 'null' or 'undefined' to object"))
            }
            JsValue::Boolean(boolean) => {
                let prototype = context.standard_objects().boolean_object().prototype();
                Ok(JsObject::new(Object::with_prototype(
                    prototype.into(),
                    ObjectData::boolean(*boolean),
                )))
            }
            JsValue::Integer(integer) => {
                let prototype = context.standard_objects().number_object().prototype();
                Ok(JsObject::new(Object::with_prototype(
                    prototype.into(),
                    ObjectData::number(f64::from(*integer)),
                )))
            }
            JsValue::Rational(rational) => {
                let prototype = context.standard_objects().number_object().prototype();
                Ok(JsObject::new(Object::with_prototype(
                    prototype.into(),
                    ObjectData::number(*rational),
                )))
            }
            JsValue::String(ref string) => {
                let prototype = context.standard_objects().string_object().prototype();
                let object = JsObject::new(Object::with_prototype(
                    prototype.into(),
                    ObjectData::string(string.clone()),
                ));
                // Make sure the correct length is set on our new string object
                object.insert_property(
                    "length",
                    PropertyDescriptor::builder()
                        .value(string.encode_utf16().count())
                        .writable(false)
                        .enumerable(false)
                        .configurable(false),
                );
                Ok(object)
            }
            JsValue::Symbol(ref symbol) => {
                let prototype = context.standard_objects().symbol_object().prototype();
                Ok(JsObject::new(Object::with_prototype(
                    prototype.into(),
                    ObjectData::symbol(symbol.clone()),
                )))
            }
            JsValue::BigInt(ref bigint) => {
                let prototype = context.standard_objects().bigint_object().prototype();
                Ok(JsObject::new(Object::with_prototype(
                    prototype.into(),
                    ObjectData::big_int(bigint.clone()),
                )))
            }
            JsValue::Object(jsobject) => Ok(jsobject.clone()),
        }
    }
pub fn to_object ( & self , context : & mut Context ) -> JsResult < JsObject > { match self { JsValue :: Undefined | JsValue :: Null => { Err ( context . construct_type_error ( " " ) ) } JsValue :: Boolean ( boolean ) => { let prototype = context . standard_objects ( ) . boolean_object ( ) . prototype ( ) ; Ok ( JsObject :: new ( Object :: with_prototype ( prototype . into ( ) , ObjectData :: boolean ( * boolean ) , ) ) ) } JsValue :: Integer ( integer ) => { let prototype = context . standard_objects ( ) . number_object ( ) . prototype ( ) ; Ok ( JsObject :: new ( Object :: with_prototype ( prototype . into ( ) , ObjectData :: number ( f64 :: from ( * integer ) ) , ) ) ) } JsValue :: Rational ( rational ) => { let prototype = context . standard_objects ( ) . number_object ( ) . prototype ( ) ; Ok ( JsObject :: new ( Object :: with_prototype ( prototype . into ( ) , ObjectData :: number ( * rational ) , ) ) ) } JsValue :: String ( ref string ) => { let prototype = context . standard_objects ( ) . string_object ( ) . prototype ( ) ; let object = JsObject :: new ( Object :: with_prototype ( prototype . into ( ) , ObjectData :: string ( string . clone ( ) ) , ) ) ; // Make sure the correct length is set on our new string object object . insert_property ( " " , PropertyDescriptor :: builder ( ) . value ( string . encode_utf16 ( ) . count ( ) ) . writable ( false ) . enumerable ( false ) . configurable ( false ) , ) ; Ok ( object ) } JsValue :: Symbol ( ref symbol ) => { let prototype = context . standard_objects ( ) . symbol_object ( ) . prototype ( ) ; Ok ( JsObject :: new ( Object :: with_prototype ( prototype . into ( ) , ObjectData :: symbol ( symbol . clone ( ) ) , ) ) ) } JsValue :: BigInt ( ref bigint ) => { let prototype = context . standard_objects ( ) . bigint_object ( ) . prototype ( ) ; Ok ( JsObject :: new ( Object :: with_prototype ( prototype . into ( ) , ObjectData :: big_int ( bigint . clone ( ) ) , ) ) ) } JsValue :: Object ( jsobject ) => Ok ( jsobject . clone ( ) ) , } }
Converts the value to an Object.
Converts the value to an Object .
&self
context
&mut Context
&self
context
&mut Context