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

A bug in Array.prototype.sort #1315

Closed
Georgezxh opened this issue Apr 6, 2023 · 4 comments
Closed

A bug in Array.prototype.sort #1315

Georgezxh opened this issue Apr 6, 2023 · 4 comments
Labels
Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec
Milestone

Comments

@Georgezxh
Copy link

Georgezxh commented Apr 6, 2023

Description

Build version: 1.7.14
OS version: ubuntu20.04

I executed the following code and found the result of rhino was different from other js engines' results. It seems like rhino has a reversed result.

Testcase

function foo1() {
  foo2.prototype = arguments;
  new foo2();
}

function foo2() {
  var x = Array.prototype.sort.call(this,foo2);
  for (var i = 0; i < x.length; i++) {
    print(x[i]);
  }
}
foo1(3,2,4,1);

Output

1
4
2
3

Expected behavior

3
2
4
1

@tuchida
Copy link
Contributor

tuchida commented Apr 6, 2023

3,2,4,1 in other browsers, but 1,4,2,3 in Rhino.

var a = [3, 2, 4, 1].sort(() => {});
for (var i = 0; i < a.length; i++) {
  console.log(a[i]);
}

ref. #1151
This is probably the cause.

@p-bakker p-bakker added the Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec label Jun 30, 2023
@p-bakker p-bakker added this to the ES2019 milestone Jun 30, 2023
@p-bakker
Copy link
Collaborator

@tuchida think we can close this one as well now?

@tuchida
Copy link
Contributor

tuchida commented Jul 18, 2024

@p-bakker OK!

js> function foo1() {
  foo2.prototype = arguments;
  new foo2();
}

function foo2() {
  var x = Array.prototype.sort.call(this,foo2);
  for (var i = 0; i < x.length; i++) {
    print(x[i]);
  }
}
foo1(3,2,4,1);
  >   >   > js> js>   >   >   >   >   > js> js> 3
2
4
1

@p-bakker
Copy link
Collaborator

Fixed by #1494

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec
Projects
None yet
Development

No branches or pull requests

3 participants