Skip to content

fix: emit source_loc around iterator_close so for/of return() stack traces report correct line#1473

Open
mvanhorn wants to merge 1 commit into
quickjs-ng:masterfrom
mvanhorn:fix/1266-emit-source-loc-around-iterator-close-so-for-of-re
Open

fix: emit source_loc around iterator_close so for/of return() stack traces report correct line#1473
mvanhorn wants to merge 1 commit into
quickjs-ng:masterfrom
mvanhorn:fix/1266-emit-source-loc-around-iterator-close-so-for-of-re

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Summary

When a for/of loop early-exits (break/return inside the body) saghul's iterator_close op runs to release the iterator. Any error thrown from the iterator's return() method was reported with the source_loc of the bytecode AFTER the loop, not the line of the actual for/of. Fix is to emit a source_loc op around iterator_close so the stack trace points at the loop.

Why this matters

Reporter pinpointed the exact OP and gave a minimal repro. The misleading line number made these errors very hard to diagnose, especially in generators where the iterator's return() can fail far from the call site.

Changes

  • quickjs.c::js_for_of_close_callback (and the bytecode emitter) - bracket iterator_close with source_loc ops carrying the line of the originating for/of.

Testing

make all && ./run-test262 -c tests/test262.conf clean. Added a script case under tests/bugs that asserts the stack trace line matches the for/of source line.

Fixes #1266

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Line numbers are off in for/of

1 participant