Commit dfddac0
committed
[JSC] DFG should preserve ToNumber side-effect for Math.pow with one argument
https://bugs.webkit.org/show_bug.cgi?id=309541
Reviewed by Justin Michaud.
When Math.pow(x) is called with a single argument, DFG ByteCodeParser
unconditionally folds it to a NaN constant and drops the argument
entirely. However, the runtime implementation (mathProtoFuncPow) always
calls argument(0).toNumber(), which has observable side effects:
valueOf/Symbol.toPrimitive invocations, or throwing TypeError for
Symbol/BigInt.
This causes tier-inconsistent behavior: before DFG tier-up, valueOf is
invoked on every call; after tier-up, the side effect silently
disappears.
Fix by splitting the < 3 argument check: for the 1-argument case, emit
a Phantom with NumberUse edge on the argument before returning NaN.
This forces OSR exit when a non-number is passed, falling back to
baseline where ToNumber runs correctly. This mirrors the existing
pattern in handleMinMax for Math.max(x)/Math.min(x).
Test: JSTests/stress/math-pow-one-argument-to-number.js
* JSTests/stress/math-pow-one-argument-to-number.js: Added.
(shouldBe):
(let.obj.valueOf):
(test):
(testThrow):
(let.throwObj.valueOf):
(catch):
* Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::handleIntrinsicCall):
Canonical link: https://commits.webkit.org/308954@main1 parent 8b67517 commit dfddac0
2 files changed
Lines changed: 47 additions & 2 deletions
File tree
- JSTests/stress
- Source/JavaScriptCore/dfg
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2630 | 2630 | | |
2631 | 2631 | | |
2632 | 2632 | | |
2633 | | - | |
2634 | | - | |
| 2633 | + | |
| 2634 | + | |
| 2635 | + | |
| 2636 | + | |
| 2637 | + | |
| 2638 | + | |
| 2639 | + | |
| 2640 | + | |
2635 | 2641 | | |
| 2642 | + | |
2636 | 2643 | | |
2637 | 2644 | | |
2638 | 2645 | | |
| |||
0 commit comments