WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
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+
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Yusuke Suzuki
Comment 1
2021-09-06 02:01:41 PDT
Created
attachment 437397
[details]
Patch
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
Committed
r282081
(
241381@main
): <
https://commits.webkit.org/241381@main
>
Radar WebKit Bug Importer
Comment 5
2021-09-07 06:53:19 PDT
<
rdar://problem/82819521
>
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
Forgot that I'd already done it:
https://github.com/tc39/test262/commit/50f3fca7a0eac6b6e8e5e9aee7af3c2a05831261
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug