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

do-whiles within any block cause a panic #1929

Closed
addisoncrump opened this issue Mar 14, 2022 · 1 comment
Closed

do-whiles within any block cause a panic #1929

addisoncrump opened this issue Mar 14, 2022 · 1 comment
Labels
bug Something isn't working execution Issues or PRs related to code execution vm Issues and PRs related to the Boa Virtual Machine.
Milestone

Comments

@addisoncrump
Copy link
Contributor

Describe the bug
do-whiles within any block cause a panic ("attempt to subtract with overflow" in call_frame.rs)

To Reproduce
This JavaScript code reproduces the issue:

{
    do {
    } while (false);
}

Another case:

while (true) { do {} while (false); }

But notably not:

while (true) do {} while (false);

Expected behavior
do-while should execute as expected and not panic.

Additional context
Discovered with #1902.

@addisoncrump addisoncrump added the bug Something isn't working label Mar 14, 2022
@addisoncrump addisoncrump reopened this Mar 14, 2022
@addisoncrump
Copy link
Contributor Author

Mistakenly closed.

@Razican Razican added execution Issues or PRs related to code execution vm Issues and PRs related to the Boa Virtual Machine. labels Mar 14, 2022
@Razican Razican added this to the v0.15.0 milestone Mar 14, 2022
@bors bors bot closed this as completed in e2630fa Mar 22, 2022
Razican pushed a commit that referenced this issue Jun 8, 2022
 `Node::DoWhileLoop` ast node had a buggy bytecode generation where `self.patch_jump(exit)` was called after emitting `LoopEnd` opcode. This would patch the loop exit to the instruction following the do while code, which would panic in cases where do while was enclosed in a block statement.

This Pull Request fixes #1929.

It changes the following:
- Patch jump before emitting `Opcode::LoopEnd`
- Add test which has do while statement inside a block statement to demonstrate that the change fixes the panic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working execution Issues or PRs related to code execution vm Issues and PRs related to the Boa Virtual Machine.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants