Commit a6b2312
Alexey Shvayka
[JSC] Iterator.prototype.reduce() doesn't properly forward return() call to underlying iterator
https://bugs.webkit.org/show_bug.cgi?id=280813
<rdar://problem/137181340>
Reviewed by Yusuke Suzuki.
If an exception occurs in `reducer` [1], for/of correctly retrieves "return" method from the underlying
iterator (via forwarding getter on the wrapper), yet it calls the method with `this` value of the wrapper
instead of underlying iterator, which for example makes Generator.prototype.return() throw a TypeError.
This is a very subtle bug because if IteratorClose is called due to throw completion, it "swallows"
throw completion of return() call [2].
While this can be fixed by rewriting iterator wrapper just like one in flatMap(), this patch instead
utilizes @iteratorGenericNext() and @ifAbruptCloseIterator() to get rid of the wrapper for performance
and code expressiveness reasons.
[1]: https://tc39.es/proposal-iterator-helpers/#sec-iteratorprototype.reduce (steps 7.c-d)
[2]: https://tc39.es/ecma262/#sec-iteratorclose (steps 5-6)
* JSTests/stress/iterator-prototype-reduce.js:
(sameValue.const.gen):
(sameValue):
* Source/JavaScriptCore/builtins/JSIteratorPrototype.js:
(reduce):
(reduce.wrapper.return.next): Deleted.
(reduce.wrapper.return.get return): Deleted.
(reduce.wrapper.iterator): Deleted.
Canonical link: https://commits.webkit.org/284648@main1 parent 2ad9fbc commit a6b2312
File tree
2 files changed
+35
-15
lines changed- JSTests/stress
- Source/JavaScriptCore/builtins
2 files changed
+35
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | | - | |
| 286 | + | |
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
292 | | - | |
293 | | - | |
294 | | - | |
| 292 | + | |
295 | 293 | | |
296 | 294 | | |
297 | 295 | | |
298 | 296 | | |
299 | 297 | | |
300 | 298 | | |
301 | 299 | | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
313 | 309 | | |
314 | 310 | | |
315 | 311 | | |
| |||
0 commit comments