From e087a27e56269cece5e84059a671a8cb1e147488 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Tue, 3 Aug 2021 18:35:21 -0400 Subject: [PATCH] avm2: `Vector.sort` actually *does* calculate an indexed sort array, but then discards it. Normally we could skip sorting, but values in the vector may have side effects when coerced. So we need to make sure coercions run, at least. --- core/src/avm2/globals/vector.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/avm2/globals/vector.rs b/core/src/avm2/globals/vector.rs index 8d523a9b3..291554400 100644 --- a/core/src/avm2/globals/vector.rs +++ b/core/src/avm2/globals/vector.rs @@ -867,12 +867,6 @@ pub fn sort<'gc>( ) }; - //NOTE: RETURNINDEXEDARRAY is actually unimplemented in Flash Player - //and will turn the sort into a no-op. - if options.contains(SortOptions::RETURN_INDEXED_ARRAY) { - return Ok(this.into()); - } - let compare = move |activation: &mut Activation<'_, 'gc, '_>, a, b| { if let Some(compare_fnc) = compare_fnc { let order = compare_fnc @@ -918,6 +912,12 @@ pub fn sort<'gc>( error_signal?; + //NOTE: RETURNINDEXEDARRAY does NOT actually return anything useful. + //The actual sorting still happens, but the results are discarded. + if options.contains(SortOptions::RETURN_INDEXED_ARRAY) { + return Ok(this.into()); + } + if !options.contains(SortOptions::UNIQUE_SORT) || unique_sort_satisfied { let mut vs = this .as_vector_storage_mut(activation.context.gc_context)