From 56db4235df006bdeed501fe3ac3c428c3dacc958 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 25 Jul 2022 09:52:06 -0400 Subject: [PATCH] LibJS: Add missing spec step to CompareTypedArrayElements This isn't actually much of an issue because if the LHS side value is -0 and the RHS value is +0, errantly returning 0 in the comparison function here has the same effect as correctly returning -1. In both cases, the -0 is left on the LHS. --- Userland/Libraries/LibJS/Runtime/TypedArray.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 96a33aef508..832f1df2f42 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -412,6 +412,10 @@ ThrowCompletionOr compare_typed_array_elements(GlobalObject& global_obje : (x.as_double() > y.as_double())) return 1; + // 8. If x is -0𝔽 and y is +0𝔽, return -1𝔽. + if (x.is_negative_zero() && y.is_positive_zero()) + return -1; + // 9. If x is +0𝔽 and y is -0𝔽, return 1𝔽. if (x.is_positive_zero() && y.is_negative_zero()) return 1;