gecko-dev/layout
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
..
base Bug 1473631: Part 0b - Add helper for registering instance methods as pref callbacks. r=njn 2018-07-13 18:54:11 -07:00
build Backed out changeset b099e7e0b264 (bug 1454358) for build bustages on Element.h CLOSED TREE 2018-07-12 01:50:53 +03:00
doc Bug 1407059 - GECKO_DISPLAY_REFLOW_PROCESSES=a/p/c enables reflow logging in chosen processes - r=dbaron 2018-05-08 12:42:16 +10:00
forms Bug 1453795 - Layout - Initialize member fields in classes/ structures. r=dbaron 2018-07-12 09:42:14 +03:00
generic Merge autoland to mozilla-central. a=merge 2018-07-17 00:58:15 +03:00
inspector Bug 1453795 - Layout - Initialize member fields in classes/ structures. r=dbaron 2018-07-12 09:42:14 +03:00
ipc Bug 1467867 - Ensure we populate the event regions overrides properly. r=botond 2018-06-08 21:16:43 +00:00
mathml Bug 1470325 - s/FooBinding/Foo_Binding/g - r=qdot 2018-06-26 17:05:01 -07:00
media
painting Bug 1472465 - Update flattened nsDisplayOpacity geometry despite empty invalidation region r=mattwoodrow 2018-07-16 01:09:23 +02:00
printing Bug 1453795 - Layout - Initialize member fields in classes/ structures. r=dbaron 2018-07-12 09:42:14 +03:00
reftests Backed out changeset 4aa2f74bad5b (bug 1474663) for contain size failures CLOSED TREE 2018-07-16 21:11:42 +03:00
style Bug 1473631: Part 0a - Make preference callbacks typesafe. r=njn 2018-07-06 12:24:41 -07:00
svg Bug 1372458 - Fold opacity into filter drawing rather than using a temporary surface. r=bas,mstange 2018-07-14 15:25:49 +12:00
tables Bug 1453795 - Layout - Initialize member fields in classes/ structures. r=dbaron 2018-07-12 09:42:14 +03:00
tools Bug 1474877: Fix mach reftest --repeat N. r=jmaher 2018-07-12 09:06:28 +00:00
xul Merge mozilla-central to inbound. a=merge CLOSED TREE 2018-07-14 12:45:25 +03:00
moz.build