pub(crate) fn create_list_from_array_like(
        &self,
        element_types: &[Type],
        context: &mut Context,
    ) -> Result<Vec<Value>> {
        // 1. If elementTypes is not present, set elementTypes to « Undefined, Null, Boolean, String, Symbol, Number, BigInt, Object ».
        let types = if element_types.is_empty() {
            &[
                Type::Undefined,
                Type::Null,
                Type::Boolean,
                Type::String,
                Type::Symbol,
                Type::Number,
                Type::BigInt,
                Type::Object,
            ]
        } else {
            element_types
        };

        // TODO: 2. If Type(obj) is not Object, throw a TypeError exception.

        // 3. Let len be ? LengthOfArrayLike(obj).
        let len = self.length_of_array_like(context)?;

        // 4. Let list be a new empty List.
        let mut list = Vec::with_capacity(len);

        // 5. Let index be 0.
        // 6. Repeat, while index < len,
        for index in 0..len {
            // a. Let indexName be ! ToString(𝔽(index)).
            // b. Let next be ? Get(obj, indexName).
            let next = self.get(index, context)?;
            // c. If Type(next) is not an element of elementTypes, throw a TypeError exception.
            if !types.contains(&next.get_type()) {
                return Err(context.construct_type_error("bad type"));
            }
            // d. Append next as the last element of list.
            list.push(next.clone());
            // e. Set index to index + 1.
        }

        // 7. Return list.
        Ok(list)
    }
/// It is used to create List value whose elements are provided by the indexed properties of
/// self.
///
/// More information:
/// - [EcmaScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-createlistfromarraylike
It is used to create List value whose elements are provided by the indexed properties of
self.

More information:
[EcmaScript reference][spec]


It is used to create List value whose elements are provided by the indexed properties of self . More information : [ EcmaScript reference ] [ spec ]
pub(crate) fn create_list_from_array_like(
        &self,
        element_types: &[Type],
        context: &mut Context,
    ) -> Result<Vec<Value>> {
        // 1. If elementTypes is not present, set elementTypes to « Undefined, Null, Boolean, String, Symbol, Number, BigInt, Object ».
        let types = if element_types.is_empty() {
            &[
                Type::Undefined,
                Type::Null,
                Type::Boolean,
                Type::String,
                Type::Symbol,
                Type::Number,
                Type::BigInt,
                Type::Object,
            ]
        } else {
            element_types
        };
        // TODO: 2. If Type(obj) is not Object, throw a TypeError exception.
        // 3. Let len be ? LengthOfArrayLike(obj).
        let len = self.length_of_array_like(context)?;
        // 4. Let list be a new empty List.
        let mut list = Vec::with_capacity(len);
        // 5. Let index be 0.
        // 6. Repeat, while index < len,
        for index in 0..len {
            // a. Let indexName be ! ToString(𝔽(index)).
            // b. Let next be ? Get(obj, indexName).
            let next = self.get(index, context)?;
            // c. If Type(next) is not an element of elementTypes, throw a TypeError exception.
            if !types.contains(&next.get_type()) {
                return Err(context.construct_type_error("bad type"));
            }
            // d. Append next as the last element of list.
            list.push(next.clone());
            // e. Set index to index + 1.
        }
        // 7. Return list.
        Ok(list)
    }
pub ( crate ) fn create_list_from_array_like ( & self , element_types : & [ Type ] , context : & mut Context , ) -> Result < Vec < Value > > { // 1. If elementTypes is not present, set elementTypes to « Undefined, Null, Boolean, String, Symbol, Number, BigInt, Object ». let types = if element_types . is_empty ( ) { & [ Type :: Undefined , Type :: Null , Type :: Boolean , Type :: String , Type :: Symbol , Type :: Number , Type :: BigInt , Type :: Object , ] } else { element_types } ; // TODO: 2. If Type(obj) is not Object, throw a TypeError exception. // 3. Let len be ? LengthOfArrayLike(obj). let len = self . length_of_array_like ( context ) ? ; // 4. Let list be a new empty List. let mut list = Vec :: with_capacity ( len ) ; // 5. Let index be 0. // 6. Repeat, while index < len, for index in 0 .. len { // a. Let indexName be ! ToString(𝔽(index)). // b. Let next be ? Get(obj, indexName). let next = self . get ( index , context ) ? ; // c. If Type(next) is not an element of elementTypes, throw a TypeError exception. if ! types . contains ( & next . get_type ( ) ) { return Err ( context . construct_type_error ( " " ) ) ; } // d. Append next as the last element of list. list . push ( next . clone ( ) ) ; // e. Set index to index + 1. } // 7. Return list. Ok ( list ) }
It is used to create List value whose elements are provided by the indexed properties of
self.
It is used to create List value whose elements are provided by the indexed properties of self .
&self
element_types
&[Type]
context
&mut Context
&self
element_types
&[Type]
context
&mut Context