pub fn to_string(&self, heap: &mut Heap) -> Result<String, Exception> {
        fn is_valid_identifier(s: &str) -> bool {
            let is_start = |c: char| (c.is_alphabetic() || c == '_' || c == '$');

            let mut it = s.chars();
            if let Some(c) = it.next() {
                is_start(c) && it.all(|c| is_start(c) || c.is_numeric())
            } else {
                false
            }
        }

        let is_array = self.as_array().is_some();

        let mut s = String::new();
        let mut empty = true;

        if let Some(array) = self.as_array() {
            s.push('[');
            for item in array.storage.iter() {
                empty = false;
                let itemstr = item.to_string(heap)?;
                s.push_str(&itemstr);
                s.push(',');
                s.push(' ');
            }
            if !empty {
                s.pop();
                s.push(' ');
            }
        } else {
            s.push('{');
        }

        for (key, property) in self.properties.iter() {
            if !property.access.enumerable() {
                continue;
            }

            s.push(' ');
            if is_valid_identifier(&key) {
                s.push_str(key);
            } else {
                let skey = JSON::from(key.as_str()).to_string();
                s.push_str(&skey);
            }
            s.push_str(": ");
            let val = property.content.to_value()?.to_string(heap)?;
            s.push_str(&val);
            s.push(',');
            empty = false;
        }
        if is_array {
            if !empty {
                s.pop();
                s.pop();
            }
            s.push(']');
        } else {
            if !empty {
                s.pop();
                s.push(' ');
            }
            s.push('}');
        }
        Ok(s)
    }
/// Create a human-readable representation of contents of an Array or an Object.
Create a human-readable representation of contents of an Array or an Object.
Create a human - readable representation of contents of an Array or an Object .
pub fn to_string(&self, heap: &mut Heap) -> Result<String, Exception> {
        fn is_valid_identifier(s: &str) -> bool {
            let is_start = |c: char| (c.is_alphabetic() || c == '_' || c == '$');
            let mut it = s.chars();
            if let Some(c) = it.next() {
                is_start(c) && it.all(|c| is_start(c) || c.is_numeric())
            } else {
                false
            }
        }
        let is_array = self.as_array().is_some();
        let mut s = String::new();
        let mut empty = true;
        if let Some(array) = self.as_array() {
            s.push('[');
            for item in array.storage.iter() {
                empty = false;
                let itemstr = item.to_string(heap)?;
                s.push_str(&itemstr);
                s.push(',');
                s.push(' ');
            }
            if !empty {
                s.pop();
                s.push(' ');
            }
        } else {
            s.push('{');
        }
        for (key, property) in self.properties.iter() {
            if !property.access.enumerable() {
                continue;
            }
            s.push(' ');
            if is_valid_identifier(&key) {
                s.push_str(key);
            } else {
                let skey = JSON::from(key.as_str()).to_string();
                s.push_str(&skey);
            }
            s.push_str(": ");
            let val = property.content.to_value()?.to_string(heap)?;
            s.push_str(&val);
            s.push(',');
            empty = false;
        }
        if is_array {
            if !empty {
                s.pop();
                s.pop();
            }
            s.push(']');
        } else {
            if !empty {
                s.pop();
                s.push(' ');
            }
            s.push('}');
        }
        Ok(s)
    }
pub fn to_string ( & self , heap : & mut Heap ) -> Result < String , Exception > { fn is_valid_identifier ( s : & str ) -> bool { let is_start = | c : char | ( c . is_alphabetic ( ) || c == '_' || c == '$' ) ; let mut it = s . chars ( ) ; if let Some ( c ) = it . next ( ) { is_start ( c ) && it . all ( | c | is_start ( c ) || c . is_numeric ( ) ) } else { false } } let is_array = self . as_array ( ) . is_some ( ) ; let mut s = String :: new ( ) ; let mut empty = true ; if let Some ( array ) = self . as_array ( ) { s . push ( '[' ) ; for item in array . storage . iter ( ) { empty = false ; let itemstr = item . to_string ( heap ) ? ; s . push_str ( & itemstr ) ; s . push ( ',' ) ; s . push ( ' ' ) ; } if ! empty { s . pop ( ) ; s . push ( ' ' ) ; } } else { s . push ( '{' ) ; } for ( key , property ) in self . properties . iter ( ) { if ! property . access . enumerable ( ) { continue ; } s . push ( ' ' ) ; if is_valid_identifier ( & key ) { s . push_str ( key ) ; } else { let skey = JSON :: from ( key . as_str ( ) ) . to_string ( ) ; s . push_str ( & skey ) ; } s . push_str ( " " ) ; let val = property . content . to_value ( ) ? . to_string ( heap ) ? ; s . push_str ( & val ) ; s . push ( ',' ) ; empty = false ; } if is_array { if ! empty { s . pop ( ) ; s . pop ( ) ; } s . push ( ']' ) ; } else { if ! empty { s . pop ( ) ; s . push ( ' ' ) ; } s . push ( '}' ) ; } Ok ( s ) }
Create a human-readable representation of contents of an Array or an Object.
Create a human - readable representation of contents of an Array or an Object .
&self
heap
&mut Heap
&self
heap
&mut Heap