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

8258147: Modernize Nashorn code #5

Closed
wants to merge 22 commits into from
Closed

Conversation

szegedi
Copy link
Collaborator

@szegedi szegedi commented Dec 13, 2020

Most of Nashorn code was written to be compatible with Java 7 and never updated. It is high time to introduce diamonds, lambdas, modern collection operations (List.of, Map.computeIfAbsent, etc.), elimination of most StringBuffer use (since string concatenation has been indified) and bring it up to at least Java 11 standards.

In addition to these, I added more code tidying mostly governed by judicious evaluation of IntelliJ IDEA recommendations. Expressions have been simplified, statically known values have been respected, unused parameters and dead code removed. I did not blindly follow IDEA's recommendations; I refrained from eliminating asserts even when they're statically proven to always be true, as I like them as safeguards against future breakage. I also did not convert any switch statements into switch expressions; those have been introduced very recently in Java 14 and I'd rather give them more time. Who knows, maybe some poor soul out there plans to compile standalone Nashorn for Java 11?

All tests, including the 262 test suite, pass after these changes.


Progress

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed

Issue

Reviewers

Download

$ git fetch https://git.openjdk.java.net/nashorn pull/5/head:pull/5
$ git checkout pull/5

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 13, 2020

👋 Welcome back attila! A progress list of the required criteria for merging this PR into main will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label Dec 13, 2020
@@ -829,7 +829,7 @@ public Object eval(final ScriptObject initialScope, final String string,

Class<?> clazz;
try {
clazz = compile(source, new ThrowErrorManager(), strictFlag, true);
clazz = compile(source, new ThrowErrorManager(), strictFlag);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vaguely isEval or not was used in compilation to compile differently. Or perhaps only for loading post compilation? (eval code as throw-away anon class?). But if the current code does not use it, then fine.

@@ -82,7 +82,7 @@ public URLReader(final URL url, final Charset cs) {
}

@Override
public int read(final char cbuf[], final int off, final int len) throws IOException {
public int read(final char[] cbuf, final int off, final int len) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Never knew we had those in the code :)

Did you run any tool to find these or just found while code inspection/reading?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IntelliJ IDEA warns about them. Most of this code changes were driven by IDEA highlighting things.

Copy link
Member

@sundararajana sundararajana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this cleanup. Reads much better now.

I recommend raising many PRs instead of one big PR. I understand this is code cleanup but easier to work smaller changes at a time.

@openjdk
Copy link

openjdk bot commented Dec 17, 2020

@szegedi This change now passes all automated pre-integration checks.

After integration, the commit message for the final commit will be:

8258147: Modernize Nashorn code

Reviewed-by: sundar

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the main branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the main branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Dec 17, 2020
@szegedi
Copy link
Collaborator Author

szegedi commented Dec 20, 2020

/integrate

@openjdk openjdk bot closed this Dec 20, 2020
@openjdk openjdk bot added integrated and removed ready rfr labels Dec 20, 2020
@openjdk
Copy link

openjdk bot commented Dec 20, 2020

@szegedi Since your change was applied there have been 3 commits pushed to the main branch:

  • cab0c85: 8233195: Don't hoist block-scoped variables from dead code
  • 9ac6efe: 8244586: Opportunistic type evaluation should gracefully handle undefined lets and consts
  • 9b87e5d: 8240299: A possible bug about Object.setPrototypeOf().

Your commit was automatically rebased without conflicts.

Pushed as commit e782364.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@szegedi szegedi deleted the tidying branch December 23, 2020 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants