Observable when an iterator's .return method produces a stack trace. ```js var iter = { next() { return {value:"."[this.i], done:!!this.i++} }, return() { print(new Error().stack) return {value:undefined, done:true} }, i: 0, } var iterable = {[Symbol.iterator](){ return iter }} for (var _ of iterable) break ``` Prints: ``` at return (u.js:6:19) // okay at <anonymous> (u.js:1:1) // WRONG ``` The relevant bytecode with `qjs --script -D2`: ``` 111: get_var iterable for_of_start goto 2:152 label 5:127 127: put_var _ goto 3:142 label 3:142 142: goto 4:165 label 2:152 152: for_of_next 0 if_false 5:127 drop label 4:165 165: iterator_close get_loc 0 ; "<ret>" return ``` Note how there are no `source_loc` opcodes anywhere to be seen. There should be one around `iterator_close`. Change the body of the loop so it's not functionally empty... ```js for (var _ of iterable) { Math; break } ``` ...and the right line numbers appear: ``` at return (u.js:6:19) at <anonymous> (u.js:12:27) ```
Activity
Fix line numbers in for/of iterator return
Fix stack trace source position for for/of IteratorClose
mvanhorn commentedon May 16, 2026
Implemented in #1473 - bracket iterator_close with source_loc ops carrying the for/of source line.
fix: emit source_loc around iterator_close so for/of return() stack t…
fix: emit source_loc around iterator_close so for/of return() stack t…