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

Catch ParserException in IRFactory #1519

Merged
merged 3 commits into from
Jul 17, 2024
Merged

Catch ParserException in IRFactory #1519

merged 3 commits into from
Jul 17, 2024

Conversation

tuchida
Copy link
Contributor

@tuchida tuchida commented Jul 14, 2024

Closes #967
Errors in IRFactory have the following issues.

  1. Parser$ParserException not caught.
    js> 1=1
    js: line 1: Invalid assignment left-hand side.
    js: 
    js: ^
    Exception in thread "main" org.mozilla.javascript.Parser$ParserException
    	at org.mozilla.javascript.Parser.reportError(Parser.java:340)
    	at org.mozilla.javascript.Parser.reportError(Parser.java:326)
    	at org.mozilla.javascript.Parser.reportError(Parser.java:321)
    	at org.mozilla.javascript.IRFactory.createAssignment(IRFactory.java:2325)
    
  2. Wrong line position.
    js> var a = 1;
    var b = 2;
    const [c, c] = [3, 4];
    
    js> js> js: line 1: TypeError: redeclaration of const c.
    

IRFactory is re-parsing ASTs that have already been parsed by Parser, but the error thrown at that time was not handled properly.
So, I have fixed 0cd0e2b for 1. and 436d3f6 for 2.

@tuchida tuchida mentioned this pull request Jul 14, 2024
@gbrail
Copy link
Collaborator

gbrail commented Jul 15, 2024

Thanks -- this looks really nice and I'm glad you did it.

I'm trying to also improve code coverage across the board, and from running "./gradlew testCodeCoverageReport" I can see that there are a few spots in IRFactory that we aren't testing. Specifically, there's some new exception-handling code around line 129 of IRFactory.java that doesn't seem to be hit by any of the tests. Would it be possible for you to come up with some sort of test code that would help us hit that spot?

Specifically, from looking at the coverage report, the part below in "transformTree" is new code, it seems pretty important, and it seems to be missing coverage.

    ScriptNode script = null;
    astNodePos.push(root);
    try {
        script = (ScriptNode) transform(root);
    } catch (Parser.ParserException e) {
        // Doesn't seem to have any code coverage here...
        parser.reportErrorsIfExists(root.getLineno());
        return null;
    } finally {
        astNodePos.pop();
    }

Thanks!

@tuchida
Copy link
Contributor Author

tuchida commented Jul 15, 2024

@gbrail I added test to see if runtimeError was called ref. 6480350. However, the result of ./gradlew testCodeCoverageReport did not change. What should I do?

@gbrail
Copy link
Collaborator

gbrail commented Jul 15, 2024 via email

@p-bakker
Copy link
Collaborator

Hi @tuchida while rummaging though the backlog of issues, I ran into the following issues of which I wonder if this PR either resolved them or at least moves the needle somewhat:

@tuchida
Copy link
Contributor Author

tuchida commented Jul 16, 2024

@p-bakker #405 was fixed. Others remained the same or had other errors.

@p-bakker p-bakker linked an issue Jul 16, 2024 that may be closed by this pull request
@gbrail
Copy link
Collaborator

gbrail commented Jul 17, 2024

This is great and thanks for doing it!

@gbrail gbrail merged commit 244b2b7 into mozilla:master Jul 17, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants