The Wayback Machine - https://web.archive.org/web/20201016160648/https://github.com/microsoft/ChakraCore/issues/6503
Skip to content
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

An issue about the TypedArray.prototype.sort(). #6503

Open
NWU-NISL opened this issue Sep 18, 2020 · 6 comments
Open

An issue about the TypedArray.prototype.sort(). #6503

NWU-NISL opened this issue Sep 18, 2020 · 6 comments

Comments

@NWU-NISL
Copy link

@NWU-NISL NWU-NISL commented Sep 18, 2020

A typeerror occurred in ChakraCore when I passed an undefined parameter in TypedArray.prototype.sort(), but other engines, such as V8 and quickjs, did not throw an error. Therefore, I think there may be a problem here.

version

1.11.19

command

ChakraCore/out/Debug/ch testcase.js

testcase

var NISLFuzzingFunc = function(){
    var a = new Uint32Array(1);
    var b = a.sort(undefined);
}
NISLFuzzingFunc();

output

TypeError:[TypedArray].prototype.sort: argument is not a Function object.

expected behavior

No error occurred.

Contributor : @Haobin-Lee

@ppenzin
Copy link
Collaborator

@ppenzin ppenzin commented Sep 24, 2020

@chicoxyzzy, @zenparsing, how does this look from spec point of view?

@chicoxyzzy
Copy link

@chicoxyzzy chicoxyzzy commented Sep 24, 2020

The compareFn could be undefined in both Array.prototype.sort and %TypedArray%.prototype.sort. The runtime semantics for the latter is defined in https://tc39.es/ecma262/#sec-%typedarray%.prototype.sort

@ppenzin
Copy link
Collaborator

@ppenzin ppenzin commented Sep 25, 2020

Thank you @chicoxyzzy!

@NWU-NISL thank you for the report.

@ppenzin
Copy link
Collaborator

@ppenzin ppenzin commented Sep 25, 2020

To re-iterate, the behavior should be to do nothing if the sort function is undefined.

@chicoxyzzy
Copy link

@chicoxyzzy chicoxyzzy commented Sep 25, 2020

That's not quite correct. If compare function is undefined, then algorithm for comparison is

If x and y are both NaN, return +0.
If x is NaN, return 1.
If y is NaN, return -1.
If x < y, return -1.
If x > y, return 1.
If x is -0 and y is +0, return -1.
If x is +0 and y is -0, return 1.
Return +0.

@ppenzin
Copy link
Collaborator

@ppenzin ppenzin commented Sep 26, 2020

Thanks @chicoxyzzy! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.