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

Allow adding callbacks to org.mozilla.javascript.Parser #435

Open
allvo opened this issue May 9, 2018 · 3 comments
Open

Allow adding callbacks to org.mozilla.javascript.Parser #435

allvo opened this issue May 9, 2018 · 3 comments
Labels
feature Issues considered a new feature

Comments

@allvo
Copy link

allvo commented May 9, 2018

The parser in Rhino 1.7.7.2 was looping forever on the following simple [incorrect] script: `hangsforever(function() {

)`.
Although the bug has been fixed in d30a8eb (if I'm not mistaken) and is not reproducible in 1.7.9, this rises the question of how to identify a situation where the parser has got into a similar loop.

I suggest adding callbacks functionality similar to what Rhino has for script execution (Context#observeInstructionCount and ContextFactory#observeInstructionCount) to the parser.

This may be useful not only in preventing endless looping, but also stopping parsing of a too heavy script.

If you are ok with this suggestion or have an alternative solution, I can implement it and submit a pull request.

@gbrail
Copy link
Collaborator

gbrail commented May 9, 2018 via email

@morj
Copy link

morj commented May 14, 2018

@gbrail obviously not, but making sure the compiler doesn't go into real infinite loop without any instruction count or time limit would mean to solve the Halting problem

@allvo
Copy link
Author

allvo commented May 15, 2018

I'd want to add that having such callbacks not only helps to recover from potential parser issues. Let me share a usecase that will illustrate the need for such callbacks. I'm a member of a team developing a Java application that leverages Rhino to run arbitrary JS submitted by users. The above mentioned hooks allow us to make sure a script does not run too long. What we can not handle, however, is user's call to eval, which uses the same parser under the hood.

@p-bakker p-bakker added the feature Issues considered a new feature label Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Issues considered a new feature
Projects
None yet
Development

No branches or pull requests

4 participants