avm2: Fix Array.sort(function)

This commit is contained in:
Nathan Adams 2023-07-11 22:32:09 +02:00 committed by Adrian Wielgosik
parent 3e193214df
commit 26cf380aa4
4 changed files with 19 additions and 19 deletions

View File

@ -1015,15 +1015,15 @@ pub fn sort<'gc>(
), ),
) )
} else { } else {
( let arg = args.get(0).cloned().unwrap_or(Value::Undefined);
None, if let Ok(callable) = arg.as_callable(activation, None, None) {
SortOptions::from_bits_truncate( (Some(callable), SortOptions::empty())
args.get(0) } else {
.cloned() (
.unwrap_or_else(|| 0.into()) None,
.coerce_to_u32(activation)? as u8, SortOptions::from_bits_truncate(arg.coerce_to_u32(activation)? as u8),
), )
) }
}; };
let mut values = if let Some(values) = extract_array_values(activation, this.into())? { let mut values = if let Some(values) = extract_array_values(activation, this.into())? {

View File

@ -26,7 +26,7 @@ function length_based_comparison(a, b) {
} }
function sub_comparison(a, b) { function sub_comparison(a, b) {
return a - b; return b - a;
} }
function lbc(a, b) { function lbc(a, b) {

View File

@ -263,17 +263,17 @@ false
//Array.prototype[10] = "hole in slot 10"; //Array.prototype[10] = "hole in slot 10";
//var a = new Array(7,2,1,"3","4") //var a = new Array(7,2,1,"3","4")
//(contents of a.sort(sub_comparison)) //(contents of a.sort(sub_comparison))
1
2
3
4
7 7
4
3
2
1
//(contents of a.sort(sub_comparison, 2)) //(contents of a.sort(sub_comparison, 2))
7
4
3
2
1 1
2
3
4
7
//(contents of a.sort(sub_comparison, Array.RETURNINDEXEDARRAY)) //(contents of a.sort(sub_comparison, Array.RETURNINDEXEDARRAY))
4 4
3 3
@ -293,5 +293,5 @@ false
true true
//var d = new Array(3,"4") //var d = new Array(3,"4")
//(contents of d.sort(sub_comparison, 4)) //(contents of d.sort(sub_comparison, 4))
3
4 4
3