[webkit-changes] [WebKit/WebKit] a6b231: [JSC] Iterator.prototype.reduce() doesn't properly...
Commit Queue
noreply at github.com
Thu Oct 3 17:40:37 PDT 2024
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: a6b23120280d34f77b9276d4f6e7414eb58c6f39
https://github.com/WebKit/WebKit/commit/a6b23120280d34f77b9276d4f6e7414eb58c6f39
Author: Alexey Shvayka <ashvayka at apple.com>
Date: 2024-10-03 (Thu, 03 Oct 2024)
Changed paths:
M JSTests/stress/iterator-prototype-reduce.js
M Source/JavaScriptCore/builtins/JSIteratorPrototype.js
Log Message:
-----------
[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@main
To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications
More information about the webkit-changes
mailing list