Clean up redundant NaN canonicalizing methods
Categories
(Core :: JavaScript Engine, task, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox-esr115 | --- | unaffected |
| firefox-esr140 | --- | unaffected |
| firefox-esr153 | --- | wontfix |
| firefox152 | --- | unaffected |
| firefox153 | --- | wontfix |
| firefox154 | --- | fixed |
People
(Reporter: mccr8, Assigned: jandem)
References
(Blocks 1 open bug)
Details
(Keywords: sec-other, Whiteboard: [adv-main154-])
Attachments
(6 external files)
When passing floating point values from C++ to JS, we need to canonicalize any NaN values, to avoid security problems, because non-canonical-NaNs JS values are interpreted as pointers. Currently we have a hodge podge of ways to convert floating point values to JS values, and some are safe and some are not. Bug 2049714 is going to fix this so that all of the ways to do it are safe, except for the variations that are explicitly unsafe.
Once bug 2049714 lands and sticks for long enough that we are confident it won't be backed out, we should go through and eliminate all of the redundant APIs.
Jandem mentioned JS_NumberValue and CanonicalizedDoubleValue.
The patches that block bug 2049714 also introduce some gross changes we could revert, like going from v.setNumber(x) to v.set(JS_NumberValue(x)). A simple search and replace won't quite work as in at least one place it ended up getting split across multiple lines.
| Reporter | ||
Comment 1•4 months ago
|
||
To spell it out a bit more, these two functions can be inlined like so:
CanonicalizedDoubleValue(d) --> DoubleValue(d)
JS_NumberValue(d) --> JS::NumberValue(d)
Part 3 does some cleanups like v.set(NumberValue(JS::CanonicalizeNaN(d)) --> v.set(NumberValue(d)) but I don't see any calls to CanonicalizeNaN outside of the JS engine.
| Assignee | ||
Updated•4 months ago
|
| Reporter | ||
Comment 2•4 months ago
|
||
Arguable we could also change .set(JS_NumberValue(x)) to .setNumber(x) but I think it would be fair to call that out of scope for this issue and do that separately if we want to. I think that should be completely equivalent? But maybe it would be nice to do it while you are changing the JS_NumberValue calls anyways.
| Assignee | ||
Comment 3•4 months ago
|
||
(In reply to Andrew McCreight [:mccr8] from comment #2)
Arguable we could also change
.set(JS_NumberValue(x))to.setNumber(x)but I think it would be fair to call that out of scope for this issue and do that separately if we want to. I think that should be completely equivalent? But maybe it would be nice to do it while you are changing theJS_NumberValuecalls anyways.
Yeah it's equivalent. I'll make that change when I get to this :)
Updated•4 months ago
|
| Assignee | ||
Comment 4•4 months ago
|
||
These are equivalent now that setNumber also canonicalizes NaNs by default (bug 2049714).
| Assignee | ||
Comment 5•4 months ago
|
||
In nsJSContext::AddSupportsPrimitiveTojsvals in nsJSEnvironment.cpp, use
aArgv->setNumber to match the other aArgv->set* calls there.
In Codegen.py this fixes two stale references to TI. This is for generating the
JSJitInfo data used by the JIT.
| Assignee | ||
Comment 6•4 months ago
|
||
| Assignee | ||
Comment 7•4 months ago
|
||
JS::DoubleValue is in NamespaceImports.h so some files now use DoubleValue
instead of JS::DoubleValue to match code for other types.
| Assignee | ||
Comment 8•4 months ago
|
||
setDouble now looks more similar to setDoubleAssumeCanonicalNaN.
| Assignee | ||
Updated•4 months ago
|
| Assignee | ||
Comment 10•4 months ago
|
||
Comment 11•4 months ago
|
||
Comment 12•4 months ago
|
||
https://hg.mozilla.org/mozilla-central/rev/55736de70495
https://hg.mozilla.org/mozilla-central/rev/84888e1477c5
https://hg.mozilla.org/mozilla-central/rev/04dfb7f96a5a
https://hg.mozilla.org/mozilla-central/rev/97e8b58b3187
https://hg.mozilla.org/mozilla-central/rev/28d71385104b
https://hg.mozilla.org/mozilla-central/rev/334409e970cb
Updated•4 months ago
|
Updated•4 months ago
|
Updated•3 months ago
|
Updated•3 months ago
|
Updated•23 days ago
|
Description
•