Open Bug 1838071 Opened 3 years ago Updated 3 years ago

Don't allow non-WebIDL DOM objects to be used as WeakMap keys or with WeakRefs

Categories

(Core :: XPConnect, defect)

defect

Tracking

()

People

(Reporter: mccr8, Unassigned)

References

Details

DOM objects need to have their wrappers preserved in order to work properly as WeakMap keys. The basic issue is that non-preserved wrappers will get removed from the weak map if there are no other references to it, even if the underlying C++ object is still alive. For reasons I don't remember, this is hard to do for non-WebIDL objects, so we don't.

We should change the behavior to reject these objects as keys entirely, so they don't appear to work under light testing, only to disappear randomly when we GC. This doesn't affect web content, but it can still be annoying for Firefox developers.

Peter said:

I think it would require returning false from MaybePreserveDOMWrapper. It seems like the other user is FinalizationRegistry, not sure if blocking it from that would be ok.

I just landed a test for this behavior in js/xpconnect/tests/browser/browser_weak_xpcwn.js, which will have to rewritten to check whatever new behavior we have.

You need to log in before you can comment on or make changes to this bug.