pub(crate) fn array_species_create(
        original_array: &GcObject,
        length: usize,
        context: &mut Context,
    ) -> Result<GcObject> {
        // 1. Let isArray be ? IsArray(originalArray).
        // 2. If isArray is false, return ? ArrayCreate(length).
        if !original_array.is_array() {
            return Self::array_create(length, None, context);
        }
        // 3. Let C be ? Get(originalArray, "constructor").
        let c = original_array.get("constructor", context)?;

        // 4. If IsConstructor(C) is true, then
        //     a. Let thisRealm be the current Realm Record.
        //     b. Let realmC be ? GetFunctionRealm(C).
        //     c. If thisRealm and realmC are not the same Realm Record, then
        //         i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined.
        // TODO: Step 4 is ignored, as there are no different realms for now

        // 5. If Type(C) is Object, then
        let c = if let Some(c) = c.as_object() {
            // 5.a. Set C to ? Get(C, @@species).
            let c = c.get(WellKnownSymbols::species(), context)?;
            // 5.b. If C is null, set C to undefined.
            if c.is_null_or_undefined() {
                Value::undefined()
            } else {
                c
            }
        } else {
            c
        };

        // 6. If C is undefined, return ? ArrayCreate(length).
        if c.is_undefined() {
            return Self::array_create(length, None, context);
        }

        // 7. If IsConstructor(C) is false, throw a TypeError exception.
        if let Some(c) = c.as_object() {
            if !c.is_constructable() {
                return Err(context.construct_type_error("Symbol.species must be a constructor"));
            }
            // 8. Return ? Construct(C, « 𝔽(length) »).
            Ok(
                c.construct(&[Value::from(length)], &c.clone().into(), context)?
                    .as_object()
                    .unwrap(),
            )
        } else {
            Err(context.construct_type_error("Symbol.species must be a constructor"))
        }
    }
/// Utility function used to specify the creation of a new Array object using a constructor
/// function that is derived from original_array.
///
/// see: <https://tc39.es/ecma262/#sec-arrayspeciescreate>
Utility function used to specify the creation of a new Array object using a constructor
function that is derived from original_array.


Utility function used to specify the creation of a new Array object using a constructor function that is derived from original_array .
pub(crate) fn array_species_create(
        original_array: &GcObject,
        length: usize,
        context: &mut Context,
    ) -> Result<GcObject> {
        // 1. Let isArray be ? IsArray(originalArray).
        // 2. If isArray is false, return ? ArrayCreate(length).
        if !original_array.is_array() {
            return Self::array_create(length, None, context);
        }
        // 3. Let C be ? Get(originalArray, "constructor").
        let c = original_array.get("constructor", context)?;
        // 4. If IsConstructor(C) is true, then
        //     a. Let thisRealm be the current Realm Record.
        //     b. Let realmC be ? GetFunctionRealm(C).
        //     c. If thisRealm and realmC are not the same Realm Record, then
        //         i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined.
        // TODO: Step 4 is ignored, as there are no different realms for now
        // 5. If Type(C) is Object, then
        let c = if let Some(c) = c.as_object() {
            // 5.a. Set C to ? Get(C, @@species).
            let c = c.get(WellKnownSymbols::species(), context)?;
            // 5.b. If C is null, set C to undefined.
            if c.is_null_or_undefined() {
                Value::undefined()
            } else {
                c
            }
        } else {
            c
        };
        // 6. If C is undefined, return ? ArrayCreate(length).
        if c.is_undefined() {
            return Self::array_create(length, None, context);
        }
        // 7. If IsConstructor(C) is false, throw a TypeError exception.
        if let Some(c) = c.as_object() {
            if !c.is_constructable() {
                return Err(context.construct_type_error("Symbol.species must be a constructor"));
            }
            // 8. Return ? Construct(C, « 𝔽(length) »).
            Ok(
                c.construct(&[Value::from(length)], &c.clone().into(), context)?
                    .as_object()
                    .unwrap(),
            )
        } else {
            Err(context.construct_type_error("Symbol.species must be a constructor"))
        }
    }
pub ( crate ) fn array_species_create ( original_array : & GcObject , length : usize , context : & mut Context , ) -> Result < GcObject > { // 1. Let isArray be ? IsArray(originalArray). // 2. If isArray is false, return ? ArrayCreate(length). if ! original_array . is_array ( ) { return Self :: array_create ( length , None , context ) ; } // 3. Let C be ? Get(originalArray, "constructor"). let c = original_array . get ( " " , context ) ? ; // 4. If IsConstructor(C) is true, then //     a. Let thisRealm be the current Realm Record. //     b. Let realmC be ? GetFunctionRealm(C). //     c. If thisRealm and realmC are not the same Realm Record, then //         i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined. // TODO: Step 4 is ignored, as there are no different realms for now // 5. If Type(C) is Object, then let c = if let Some ( c ) = c . as_object ( ) { // 5.a. Set C to ? Get(C, @@species). let c = c . get ( WellKnownSymbols :: species ( ) , context ) ? ; // 5.b. If C is null, set C to undefined. if c . is_null_or_undefined ( ) { Value :: undefined ( ) } else { c } } else { c } ; // 6. If C is undefined, return ? ArrayCreate(length). if c . is_undefined ( ) { return Self :: array_create ( length , None , context ) ; } // 7. If IsConstructor(C) is false, throw a TypeError exception. if let Some ( c ) = c . as_object ( ) { if ! c . is_constructable ( ) { return Err ( context . construct_type_error ( " " ) ) ; } // 8. Return ? Construct(C, « 𝔽(length) »). Ok ( c . construct ( & [ Value :: from ( length ) ] , & c . clone ( ) . into ( ) , context ) ? . as_object ( ) . unwrap ( ) , ) } else { Err ( context . construct_type_error ( " " ) ) } }
Utility function used to specify the creation of a new Array object using a constructor
function that is derived from original_array.
Utility function used to specify the creation of a new Array object using a constructor function that is derived from original_array .
original_array
&GcObject
length
usize
context
&mut Context
original_array
&GcObject
length
usize
context
&mut Context