RESOLVED FIXED 229843
Math.hypot checks for infinite values prematurely
https://bugs.webkit.org/show_bug.cgi?id=229843
Summary Math.hypot checks for infinite values prematurely
Richard Gibson
Reported 2021-09-02 16:58:43 PDT
The algorithm for Math.hypot at https://tc39.es/ecma262/#sec-math.hypot requires coercing each argument to a Number before doing anything else. However, this coercion is incorrectly aborted after encountering an infinite value. The following expression should throw an exception, but does not: Math.hypot({valueOf(){ return Infinity }}, {valueOf(){ throw new Error("arguments[1]") }})
Attachments
Patch (3.69 KB, patch)
2021-09-06 02:01 PDT, Yusuke Suzuki
ross.kirsling: review+
Yusuke Suzuki
Comment 1 2021-09-06 02:01:41 PDT
Ross Kirsling
Comment 2 2021-09-06 11:51:35 PDT
Comment on attachment 437397 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=437397&action=review r=me with comments. > Source/JavaScriptCore/ChangeLog:8 > + We should throw an error about non finite argument after coercing all arguments to doubles. Don't forget the spec link. :) https://tc39.es/ecma262/#sec-math.hypot > JSTests/stress/math-hypot-evaluation-ordering.js:18 > +shouldThrow(() => { > + Math.hypot({valueOf(){ return Infinity }}, {valueOf(){ throw new Error("arguments[1]") }}) > +}, `Error: arguments[1]`); I think this test should be upstreamed to test262.
Yusuke Suzuki
Comment 3 2021-09-07 06:50:54 PDT
Comment on attachment 437397 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=437397&action=review >> Source/JavaScriptCore/ChangeLog:8 >> + We should throw an error about non finite argument after coercing all arguments to doubles. > > Don't forget the spec link. :) > https://tc39.es/ecma262/#sec-math.hypot Added. >> JSTests/stress/math-hypot-evaluation-ordering.js:18 >> +}, `Error: arguments[1]`); > > I think this test should be upstreamed to test262. @Gibson, do you have a plan adding that?
Yusuke Suzuki
Comment 4 2021-09-07 06:52:13 PDT
Radar WebKit Bug Importer
Comment 5 2021-09-07 06:53:19 PDT
Richard Gibson
Comment 6 2021-09-07 13:23:35 PDT
Yes, I will submit a test262 PR unless someone beats me to it.
Richard Gibson
Comment 7 2021-09-10 21:37:07 PDT
Note You need to log in before you can comment on or make changes to this bug.