Discussion:
New CEnum enumeration type in XPIDL
Kyle Machulis
2018-11-06 18:36:39 UTC
Permalink
Since just about forever (no, really:
https://bugzilla.mozilla.org/show_bug.cgi?id=8781), there's not really been
an enum type in XPIDL. This means that we have a lot of interfaces with
lots of similarly named consts, that are usually passed around in C++ as
uint32_t's, though sometimes we redefine them as enums in C++ too and then
mix everything together. This can get extremely confusing, especially in
situations involving multiple enums from multiple interfaces.

Having run into this problem while doing docshell work, I talked to Nika
about adding enums to XPIDL. With copious amounts of help from her since
this is my first foray into the XPIDL parser, I've now managed to land a
new type, called CEnums.

CEnums are exactly what they sound like, c-style enums in XPIDL. For C/C++,
they'll turn into enums on the Interface class type. In Javascript, they'll
continue to be constants on the interface, and should not require any
changes to code referring to the enum values. Enum member value assignment
follows the C/C++ specs, where any unspecified value is incremented from
the value of the previous enum member.

There are examples of how CEnums look and work in our tests:

https://searchfox.org/mozilla-central/rev/b096dcf0ea226af628fe03f7e7acb56a25853533/js/xpconnect/tests/idl/xpctest_cenums.idl
https://searchfox.org/mozilla-central/rev/b096dcf0ea226af628fe03f7e7acb56a25853533/js/xpconnect/tests/components/js/xpctest_cenums.js
https://searchfox.org/mozilla-central/rev/b096dcf0ea226af628fe03f7e7acb56a25853533/js/xpconnect/tests/components/native/xpctest_cenums.cpp

Note that the type names differ between C++ and XPIDL. In C++, the enum
name is the type, within in the interface class. When referring to the enum
type in XPIDL, the format is [interface]_[enum], e.g.
nsIXPCTestCEnums_testFlagsExplicit when passed as an interface method
argument in xpctest_cenums.idl.

I'll have the XPIDL MDN pages updated with this information soon.

There is a metabug at https://bugzilla.mozilla.org/show_bug.cgi?id=1503630
for converting const lists to CEnums.
Valentin Gosu
2018-11-07 22:16:55 UTC
Permalink
OMG, this is amazing work!
Thanks a lot for working on this!
Post by Kyle Machulis
https://bugzilla.mozilla.org/show_bug.cgi?id=8781), there's not really been
an enum type in XPIDL. This means that we have a lot of interfaces with
lots of similarly named consts, that are usually passed around in C++ as
uint32_t's, though sometimes we redefine them as enums in C++ too and then
mix everything together. This can get extremely confusing, especially in
situations involving multiple enums from multiple interfaces.
Having run into this problem while doing docshell work, I talked to Nika
about adding enums to XPIDL. With copious amounts of help from her since
this is my first foray into the XPIDL parser, I've now managed to land a
new type, called CEnums.
CEnums are exactly what they sound like, c-style enums in XPIDL. For C/C++,
they'll turn into enums on the Interface class type. In Javascript, they'll
continue to be constants on the interface, and should not require any
changes to code referring to the enum values. Enum member value assignment
follows the C/C++ specs, where any unspecified value is incremented from
the value of the previous enum member.
https://searchfox.org/mozilla-central/rev/b096dcf0ea226af628fe03f7e7acb56a25853533/js/xpconnect/tests/idl/xpctest_cenums.idl
https://searchfox.org/mozilla-central/rev/b096dcf0ea226af628fe03f7e7acb56a25853533/js/xpconnect/tests/components/js/xpctest_cenums.js
https://searchfox.org/mozilla-central/rev/b096dcf0ea226af628fe03f7e7acb56a25853533/js/xpconnect/tests/components/native/xpctest_cenums.cpp
Note that the type names differ between C++ and XPIDL. In C++, the enum
name is the type, within in the interface class. When referring to the enum
type in XPIDL, the format is [interface]_[enum], e.g.
nsIXPCTestCEnums_testFlagsExplicit when passed as an interface method
argument in xpctest_cenums.idl.
I'll have the XPIDL MDN pages updated with this information soon.
There is a metabug at https://bugzilla.mozilla.org/show_bug.cgi?id=1503630
for converting const lists to CEnums.
_______________________________________________
dev-platform mailing list
https://lists.mozilla.org/listinfo/dev-platform
Loading...