Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Possible JavaScript Breakage Between 4.1.0 and 4.4.0 #844

Closed
tntim96 opened this issue Aug 9, 2024 · 5 comments
Closed

Possible JavaScript Breakage Between 4.1.0 and 4.4.0 #844

tntim96 opened this issue Aug 9, 2024 · 5 comments

Comments

@tntim96
Copy link

tntim96 commented Aug 9, 2024

I was using HTMLUnit 4.1.0 waiting for #808 to be solved and have now swapped 4.4.0 to get the fix. I've noticed now that, with no other change to my code-base in JSCover, that a test is failing.

You can probably checkout the branch 'htmlunit-4.4.0' of JSCover and debug to see what's going on.

The test is HtmlUnitUITest.shouldSortFilesByName.

I also tested with 4.5.0-SNAPSHOT but got the same error.

It's strange that a very similar test HtmlUnitUITest.shouldSortFilesByCoverage works.

Modifying https://github.com/tntim96/JSCover/blob/5fbf74c65a85cbfaa59a2c3911d8509d13a0bafb/src/main/resources/jscoverage.js line 839 to add console output...the JavaScript sort code is

      files.sort(function (file1, file2) {
        console.error('file1,2', file1.file, file2.file);
        return file1.file >= file2.file
      });

Output with HTMLUnit 4.4.0 is

20240809 15:09:45.706,1,SEVERE,"file1,2 /scripts/script-line.js /scripts/script-empty.js",org.htmlunit.WebConsole,
20240809 15:09:45.707,1,SEVERE,"file1,2 /scripts/script-d.js /scripts/script-line.js",org.htmlunit.WebConsole,
20240809 15:09:45.708,1,SEVERE,"file1,2 /scripts/script-c.js /scripts/script-d.js",org.htmlunit.WebConsole,
20240809 15:09:45.708,1,SEVERE,"file1,2 /scripts/script-b.js /scripts/script-c.js",org.htmlunit.WebConsole,
20240809 15:09:45.709,1,SEVERE,"file1,2 /scripts/script-a.js /scripts/script-b.js",org.htmlunit.WebConsole,

...which looks wrong.

With HTML 4.1.0 it's

20240809 15:14:22.975,1,SEVERE,"file1,2 /scripts/script-empty.js /scripts/script-line.js",org.htmlunit.WebConsole,
20240809 15:14:22.976,1,SEVERE,"file1,2 /scripts/script-line.js /scripts/script-d.js",org.htmlunit.WebConsole,
20240809 15:14:22.976,1,SEVERE,"file1,2 /scripts/script-empty.js /scripts/script-d.js",org.htmlunit.WebConsole,
20240809 15:14:22.977,1,SEVERE,"file1,2 /scripts/script-line.js /scripts/script-c.js",org.htmlunit.WebConsole,
20240809 15:14:22.977,1,SEVERE,"file1,2 /scripts/script-empty.js /scripts/script-c.js",org.htmlunit.WebConsole,
20240809 15:14:22.978,1,SEVERE,"file1,2 /scripts/script-d.js /scripts/script-c.js",org.htmlunit.WebConsole,
20240809 15:14:22.978,1,SEVERE,"file1,2 /scripts/script-line.js /scripts/script-b.js",org.htmlunit.WebConsole,
20240809 15:14:22.979,1,SEVERE,"file1,2 /scripts/script-empty.js /scripts/script-b.js",org.htmlunit.WebConsole,
20240809 15:14:22.979,1,SEVERE,"file1,2 /scripts/script-d.js /scripts/script-b.js",org.htmlunit.WebConsole,
20240809 15:14:22.980,1,SEVERE,"file1,2 /scripts/script-c.js /scripts/script-b.js",org.htmlunit.WebConsole,
20240809 15:14:22.980,1,SEVERE,"file1,2 /scripts/script-line.js /scripts/script-a.js",org.htmlunit.WebConsole,
20240809 15:14:22.980,1,SEVERE,"file1,2 /scripts/script-empty.js /scripts/script-a.js",org.htmlunit.WebConsole,
20240809 15:14:22.981,1,SEVERE,"file1,2 /scripts/script-d.js /scripts/script-a.js",org.htmlunit.WebConsole,
20240809 15:14:22.981,1,SEVERE,"file1,2 /scripts/script-c.js /scripts/script-a.js",org.htmlunit.WebConsole,
20240809 15:14:22.982,1,SEVERE,"file1,2 /scripts/script-b.js /scripts/script-a.js",org.htmlunit.WebConsole,
20240809 15:14:22.975,1,SEVERE,"file1,2 /scripts/script-empty.js /scripts/script-line.js",org.htmlunit.WebConsole,
20240809 15:14:22.976,1,SEVERE,"file1,2 /scripts/script-line.js /scripts/script-d.js",org.htmlunit.WebConsole,
20240809 15:14:22.976,1,SEVERE,"file1,2 /scripts/script-empty.js /scripts/script-d.js",org.htmlunit.WebConsole,
20240809 15:14:22.977,1,SEVERE,"file1,2 /scripts/script-line.js /scripts/script-c.js",org.htmlunit.WebConsole,
20240809 15:14:22.977,1,SEVERE,"file1,2 /scripts/script-empty.js /scripts/script-c.js",org.htmlunit.WebConsole,
20240809 15:14:22.978,1,SEVERE,"file1,2 /scripts/script-d.js /scripts/script-c.js",org.htmlunit.WebConsole,
20240809 15:14:22.978,1,SEVERE,"file1,2 /scripts/script-line.js /scripts/script-b.js",org.htmlunit.WebConsole,
20240809 15:14:22.979,1,SEVERE,"file1,2 /scripts/script-empty.js /scripts/script-b.js",org.htmlunit.WebConsole,
20240809 15:14:22.979,1,SEVERE,"file1,2 /scripts/script-d.js /scripts/script-b.js",org.htmlunit.WebConsole,
20240809 15:14:22.980,1,SEVERE,"file1,2 /scripts/script-c.js /scripts/script-b.js",org.htmlunit.WebConsole,
20240809 15:14:22.980,1,SEVERE,"file1,2 /scripts/script-line.js /scripts/script-a.js",org.htmlunit.WebConsole,
20240809 15:14:22.980,1,SEVERE,"file1,2 /scripts/script-empty.js /scripts/script-a.js",org.htmlunit.WebConsole,
20240809 15:14:22.981,1,SEVERE,"file1,2 /scripts/script-d.js /scripts/script-a.js",org.htmlunit.WebConsole,
20240809 15:14:22.981,1,SEVERE,"file1,2 /scripts/script-c.js /scripts/script-a.js",org.htmlunit.WebConsole,
20240809 15:14:22.982,1,SEVERE,"file1,2 /scripts/script-b.js /scripts/script-a.js",org.htmlunit.WebConsole,

Which looks correct

@rbri
Copy link
Member

rbri commented Aug 9, 2024

Thanks for the report - will have a look

first guess - HtmlUnit/htmlunit-rhino-fork@caff4d9
but just a guess.

@rbri
Copy link
Member

rbri commented Aug 9, 2024

Hi @tntim96, i guess this might be related to jour comperator impl

  files.sort(function (file1, file2) {
    console.error('file1,2', file1.file, file2.file);
    return file1.file >= file2.file
  });

file1.file >= file2.file returns a boolean but the spec says you have to return 1/0/-1.

The handling of boolean return values seems to be different between Chrome and FF - FF converts false to -1 and Chrome converts false to 0.

The current HtmlUnit impl uses the chrome way for all browsers - i will fix that.

rbri added a commit that referenced this issue Aug 9, 2024
@rbri
Copy link
Member

rbri commented Aug 9, 2024

@tntim96 have released a new snapshot but the changed behavior is only done for ff (liek the real browsers). Can you please fix your sort comperator impl and report if this solves the problem.

@tntim96
Copy link
Author

tntim96 commented Aug 10, 2024

Sort algorithm corrected and problem is gone. Thanks

@tntim96 tntim96 closed this as completed Aug 10, 2024
@rbri
Copy link
Member

rbri commented Aug 10, 2024

Sort algorithm corrected and problem is gone. Thanks

Happy to see, thanks for reporting this, another difference between FF and Chrome is now simulated by HtmlUnit.
Have fun and success with JSCover

Crydust added a commit to Crydust/htmlunit that referenced this issue Aug 14, 2024
Crydust added a commit to Crydust/htmlunit that referenced this issue Aug 14, 2024
rbri pushed a commit that referenced this issue Sep 5, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants