Nullish coalescing operator returns undefined for void expressions
Categories
(Core :: JavaScript Engine, defect, P1)
Tracking
()
Tracking | Status | |
---|---|---|
firefox-esr68 | --- | unaffected |
firefox70 | --- | unaffected |
firefox71 | --- | unaffected |
firefox72 | + | fixed |
People
(Reporter: wartmanm, Assigned: yulia)
References
Details
Attachments
(1 file)
(deleted),
text/x-phabricator-request
|
Details |
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0
Steps to reproduce:
I was trying out new language features, as one does, and typed in (void 0) ?? "test"
in the console.
Actual results:
The resulting value was undefined
.
Expected results:
I think the correct result is "test"
. Assigning void 0
to a temporary value produces that result, as does the original expression in Chromium.
I'm not sure when an expression like this would ever come up in practice, but I wanted to make a note of it just in case.
Updated•5 years ago
|
Comment 1•5 years ago
|
||
It looks like FoldAndOrCoalesce just needs to handle ParseNodeKind::VoidExpr
.
Comment 2•5 years ago
|
||
[Tracking Requested - why for this release]:
New feature.
Assignee | ||
Updated•5 years ago
|
Updated•5 years ago
|
Assignee | ||
Comment 3•5 years ago
|
||
Comment 4•5 years ago
|
||
mattheww, great catch. Thank you so much for the bug report. I think you saved us some real embarrassment.
The bug is fun. It happens in a part of the JS engine where we examine source code and try to simplify it a bit, "algebraically", before running it, an optimization called constant folding. So for example, if you have a function that does let x = 60 * 60;
, we simplify that to let x = 3600;
before anything runs -- the function will run faster if we multiply once, up front, rather than every time the function is called. Constant folding also throws away most if (false) { ... }
statements, and so on.
Unfortunately, in this case we were erroneously assuming that the only constant expressions that evaluate to null or undefined were null
and undefined
. As you found, there's one more we need to account for.
Comment 6•5 years ago
|
||
bugherder |
Description
•