Combine testHasValue and testGetValue in C++/JS API
Categories
(Toolkit :: Telemetry, enhancement, P1)
Tracking
()
Tracking | Status | |
---|---|---|
firefox85 | --- | fixed |
People
(Reporter: janerik, Assigned: chutten)
References
Details
(Whiteboard: [telemetry:fog:m?])
Attachments
(2 files)
Right now we expose both a testHasValue
and a testGetValue
function on metrics for both C++ and JavaScript.
In Rust we only have the latter, which returns an Option<T>
, with None
signalling that there is just no value.
We can combine the functions in a similar way for C++ and JavaScript.
- In C++ use
mozilla::Maybe
to returnSome(T)
orNothing()
- In JavaScript throw a proper JavaScript exception from
testGetValue
instead (or usenull
?)
Comment 1•4 years ago
|
||
Please note that this should probably be validated with developers as well.
The reason why we have testHasValue
and testGetValue
is that it was strongly advocated for by a group of devs. We could have unified them in Kotlin, too!
Reporter | ||
Comment 2•4 years ago
|
||
(In reply to Alessio Placitelli [:Dexter] from comment #1)
Please note that this should probably be validated with developers as well.
The reason why we have
testHasValue
andtestGetValue
is that it was strongly advocated for by a group of devs. We could have unified them in Kotlin, too!
I wasn't aware this was by request. Interesting.
The Option<T>
way is definitely much more idiomatic in Rust (plus it kinda prevents the small window where the value could change inbetween hasValue
and getValue
)
Comment 3•4 years ago
|
||
(In reply to Jan-Erik Rediger [:janerik] from comment #2)
(In reply to Alessio Placitelli [:Dexter] from comment #1)
Please note that this should probably be validated with developers as well.
The reason why we have
testHasValue
andtestGetValue
is that it was strongly advocated for by a group of devs. We could have unified them in Kotlin, too!I wasn't aware this was by request. Interesting.
TheOption<T>
way is definitely much more idiomatic in Rust (plus it kinda prevents the small window where the value could change inbetweenhasValue
andgetValue
)
Yup, and for reference, I'm with you on this proposal, and I made the mistake of not pushing back hard enough on the request back then :-)
Assignee | ||
Comment 4•4 years ago
|
||
From my experience the idiomatic gecko JS way would be to return null or undefined (and document which one). Exceptions would be a bit loud and weird.
Assignee | ||
Comment 5•4 years ago
|
||
Alrighty, looks like we can do this if we return jsval
from xpidl, and use mozilla::Maybe
in C++. Design for how to handle "no value" is to return undefined
in JS and Nothing()
in C++.
Assignee | ||
Comment 6•4 years ago
|
||
Assignee | ||
Comment 7•4 years ago
|
||
Depends on D97032
Comment 9•4 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/ddff3b34f104
https://hg.mozilla.org/mozilla-central/rev/87c9fbffd69d
Description
•