gecko-dev/js/xpconnect
Andrew McCreight fee317ab0d Bug 1351501, part 2 - Preserve wrappers for non-nsISupports cycle collected weak map keys r=bzbarsky
A C++ object that is exposed to JS can have its reflector used as a
key in a weak map. Because a weak map does not keep its keys alive,
this means that the reflector can be discarded if it has no other
references aside from the C++ object, which will in turn remove its
weak map entry. If the C++ object can be accessed again later from JS,
it will get a new reflector which will have no weak map entry. This is
bad because it means some internal implementation detail has resulted
in data loss that is visible to JS. (Side note: this is also an issue
for cross compartment wrappers, which is handled by another
mechanism.)

To fix this, we can preserve the wrapper of any DOM reflector used as
a weak map key. This ensures that the reflector and its C++ object
have the same lifetime. If a WebIDL object is not wrapper cached, that
means that it cannot be accessed via C++, so we don't need to preserve
the wrapper. This is currently implemented for nsISupports classes,
but not other classes. For non-nsISupports classes, it would throw an
error rather than silently fail.

My patch adds support for non-nsISupports cycle collected objects. It
turns out that the existing addProperty hook just does wrapper
preservation, so we just call it for cycle collected classes. This
does mean that if addProperty changes in the future to do something
else, this code will need to be changed.

I verified that this test fails if TryPreserveWrapper is changed to do
nothing besides return true in the non-nsISuports case.

Depends on D6197

Differential Revision: https://phabricator.services.mozilla.com/D6198

--HG--
extra : moz-landing-system : lando
2018-09-21 18:20:35 +00:00
..
crashtests Bug 1476142 part 4. Remove some unnecessary QIs on window in various parts of the tree. r=kmag 2018-08-02 15:26:48 -04:00
idl Bug 1491561 follow-up: Add back Cu.createCommandParams() which was accidentally removed 2018-09-18 11:12:21 -04:00
loader Bug 1486147: Part 3 - Remove unused XPCOMUtils.IterStringEnumerator method. r=mccr8 2018-08-24 16:23:03 -07:00
public Bug 1453011 - Remove PostCreatePrototype. r=bz. 2018-03-22 11:31:05 +01:00
shell Bug 1467736: Add support for DllBlocklist_Shutdown;r=aklotz 2018-08-29 18:49:49 +00:00
src Bug 1351501, part 1 - Handlify TryPreserveWrapper r=bzbarsky 2018-09-21 18:20:33 +00:00
tests Bug 1351501, part 2 - Preserve wrappers for non-nsISupports cycle collected weak map keys r=bzbarsky 2018-09-21 18:20:35 +00:00
wrappers Bug 1491342 - Ignore document.domain in ShouldWaiveXray. r=bholley 2018-09-21 07:13:15 +00:00
moz.build Bug 1400406 - js/xpconnect/moz.build contains a reference to a non-existent directory. r=gps 2017-09-15 14:35:15 -07:00