Adding anonymous content to WeakMap key causes crashes [@ mozilla::dom::TryPreserveWrapper ]
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox76 | --- | affected |
People
(Reporter: emk, Unassigned)
Details
Steps to reproduce:
- Navigate to any web page.
- Open Browser Content Toolbox.
- Type into following scripts:
div = tabs[0].content.document.createElement("div");
div.textContent = "this is a test element";
anonymousContent = tabs[0].content.document.insertAnonymousContent(div);
wm = new WeakMap();
wm.set(anonymousContent, {});
Actual result:
Tab crashes.
https://crash-stats.mozilla.org/report/index/6952008a-005c-46aa-b371-fe21f0200507
Expected result:
Tab should not crash.
| Reporter | ||
Updated•6 years ago
|
| Reporter | ||
Comment 1•6 years ago
|
||
Bug 1020244 added AnonymouseContent. Why is AnonymouseContent a non-wrapper cached CC participant? It contradicts this assertion. (addProperty is nullptr for non-wrapper cached classes.)
Updated•6 years ago
|
Comment 2•6 years ago
|
||
I guess there wasn't any use case for AnonymousContent being wrapper cached. It was after all meant to be used by chrome JS only in such way that js keeps pointer to the object as long it needs it.
But it is https://bugzilla.mozilla.org/show_bug.cgi?id=1020244#c53 which caused dropping wrapper caching.
| Reporter | ||
Comment 3•6 years ago
|
||
Is a WeakMap key counted as a reference to the object? ChromeUtils.nondeterministicGetWeakMapKeys() will regain the object access even if all other references are dropped.
I hit this bug when I was trying to fix bug 1482279.
Comment 4•6 years ago
|
||
(In reply to Masatoshi Kimura [:emk] from comment #3)
Is a
WeakMapkey counted as a reference to the object?ChromeUtils.nondeterministicGetWeakMapKeys()will regain the object access even if all other references are dropped.
A WeakMap reference that doesn't keep the object alive is not counted as a reference. ChromeUtils.nondeterministicGetWeakMapKeys() was intended as a way to write tests, so I generally haven't thought about what the impacts are. The CC does have to track weak maps individually already, so we could probably actually clear weak maps that we have decided are dead. I filed bug 1636170 on that.
Also, SpiderMonkey now supports actual weak references, so it might be worth considering converting uses of nondeterministicGetWeakMapKeys outside of weak map tests to use them. I'm not sure if they are riding to release yet, so it may have to wait.
Comment 5•6 years ago
|
||
Although, weak references may have the same issue and the CC is not aware of them, so I'm not sure we can fix it easily in the CC...
| Reporter | ||
Comment 6•6 years ago
•
|
||
(In reply to Andrew McCreight [:mccr8] from comment #4)
ChromeUtils.nondeterministicGetWeakMapKeys()was intended as a way to write tests
To be clear, the affected code is test-only.
Without permissive COWs, we have to manage SpecialPowers proxies per global object. I tried using WeakMaps and hit this bug.
Updated•6 years ago
|
Comment 7•6 years ago
|
||
(clearing needinfo, apologies for not responding earlier, but I'm no longer participating actively in the development of the project)
Description
•