New check to reject 'virtual' in idl files

31 views
Skip to first unread message

Nika Layzell

unread,
Jul 6, 2022, 10:53:53 AM7/6/22
to dev-pl...@mozilla.org
As of bug 1778211 (https://bugzilla.mozilla.org/show_bug.cgi?id=1778211), a new check is being added to the XPIDL compiler to reject `%{C++` blocks which contain the keyword `virtual`. This is done to hopefully avoid future cases where people introduce new virtual methods to XPIDL classes directly, without declaring the methods in XPIDL.

The XPIDL compiler generates bindings for multiple languages, including Rust and JS through XPConnect. In order to do these cross-language bindings, it needs to know the actual layout of the VTable, including offsets and signatures of each method. Additional virtual methods implemented using CDATA blocks can potentially throw this off.

The lint was implemented in a fairly simple way (searching for the `virtual` keyword in the text of the CDATA block) so can have both false positives and false negatives, however the false-positive rate was low and easly worked around in practice. In the future we may introduce a custom clang lint to double-check vtable and struct layouts which will be more accurate (https://bugzilla.mozilla.org/show_bug.cgi?id=1778339).

If you are reaching to manually add a virtual method in an XPIDL header, consider instead declaring a `[notxpcom, nostdcall]` method, and using `native` type declarations to get the signature you're looking for. Using that approach we can get better checks and enforce other requirements like `[builtinclass]` more effectively.

-nika
Reply all
Reply to author
Forward
0 new messages