-
-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specific Array.from(...).sort(...) leads to infinite loop #1028
Comments
I think this is related to the stable sort change. This only happens on full framework as .NET Core / NET 5> detects the case and stops trying (or something similar). |
We are using .NET Framework 4.7.2 |
Your function also gets called with both "Id1" + "Id1" and then "Id1" + "Id2", so seems that the sort algorithm gets into infinite loop. Would it be possible for you to compare always a vs b instead of checking directly a? , for strings this would be (c#) |
Sure we can rewrite the expression, but I checked it with the latest DevTools in Chrome and it works fine, so IMO sorting algorithm implementation is broken. |
Fair enough, let's keep this issue open and see if we can find a solution. |
I've observed this too, my modification to Jint was to cache comparison results in c#, also saves a few round trips to js code. Effectively as you compare a to b, you cache the result of a, b comparison, and also store negated result for b, a, forcing the comparisons to remain stable. |
Checked the .NET source code and |
On .net 6 I had exceptions thrown by Array.sort due to unstable sorts, i.e:
As result of a vs b is not the inverse of b vs a if both a and b are primary. Yet the same sort runs fine in v8/spidermonkey. |
Having this issue on .NET Framework 4.8 and latest version of Jint 3.1.3 Code sample:
|
Hello!
Starting from 3.0.0-beta-2002 expression like "Array.from(Root.Inner.Items).sort((a, b) => a.Value === '0001' ? -1 : 1)" causes application hang with high CPU consumption. Looks like infinite loop. See test case below:
This test case hangs at engine.Execute(...) starting 3.0.0-beta-2002, though it works fine in 3.0.0-beta-1914.
The text was updated successfully, but these errors were encountered: