gecko-dev/modules
Kris Maglione 8d585408dc Bug 1473631: Part 0b - Add helper for registering instance methods as pref callbacks. r=njn
I also tried to avoid this change but, again, given the number of times I was
repeating the same pattern of defining a static method just to forward a
callback to an instance method, decided it was probably necessary. Without an
easy way to do this, people are more likely to register observers rather than
callbacks, for which we'll wind up paying a continued memory and performance
penalty.

This patch adds a helper which creates a type-safe preference callback
function which forwards calls to an instance method on its closure object.

The implementation is somewhat complicated, mainly due to the constraint that
unregistering a callback requires passing the exact same function pointer that
was used to register it. The patch achieves this by creating the callback
function as a template, with the method pointer as a template parameter. As
long as the Register and Unregister calls happen in the same translation unit,
the same template instance is guaranteed to be used for both.

The main difficulty is that, until C++ 17, there's no way match a value as a
template parameter unless you know its complete type, or can at least compute
its complete type based on earlier template parameters. That means that we
need a macro to extract the type of the method, and construct the template
with the full set of explicit parameters.

MozReview-Commit-ID: 10N3R2SRtPc

--HG--
extra : rebase_source : 7d0a8ddeb77e01d4a6f421459514e93bc0875598
2018-07-13 18:54:11 -07:00
..
brotli Bug 1474122 - Update brotli to version 1.0.5. r=jfkthame 2018-07-07 16:00:53 -04:00
fdlibm Bug 1438599 - Part 2: Import fdlibm from FreeBSD (revision b21ccf63f28a3a4692d8a31419e0a725a1b1a800). r=jwalden 2018-02-18 22:56:46 +09:00
freetype2 Bug 1458905 - Update to FreeType 2.9.1. r=jfkthame 2018-05-08 11:48:29 -04:00
libjar Bug 1469769 - Part 6: Replace non-failing NS_NOTREACHED with MOZ_ASSERT_UNREACHABLE. r=froydnj 2018-06-17 22:43:11 -07:00
libmar Bug 1432992, part 1 - Remove definitions of Ci, Cr, Cc, and Cu. r=florian 2018-02-06 09:36:57 -08:00
libpref Bug 1473631: Part 0b - Add helper for registering instance methods as pref callbacks. r=njn 2018-07-13 18:54:11 -07:00
pdfium Bug 1465585: Switch from mozilla::Move to std::move. r=froydnj 2018-06-01 10:45:27 +02:00
woff2 Bug 1440658 - Update woff2 library to latest upstream code (currently at 1bccf208bca986e53a647dfe4811322adb06ecf8, release 1.0.2). r=fredw 2018-02-23 14:32:23 +00:00
xz-embedded Bug 1403346 - Replace all uses of ALLOW_COMPILER_WARNINGS with a template, remove ALLOW_COMPILER_WARNINGS. r=glandium 2017-10-25 15:12:09 -07:00
zlib Backed out 5 changesets (bug 1418425) requested per comment #83. on a CLOSED TREE a=backout 2018-01-15 15:30:30 +02:00
moz.build