Support WebIDL objects that are both non-nsISupports and cycle-collected as weak map keys

RESOLVED DUPLICATE of bug 1351501

Status

()

P5
normal
RESOLVED DUPLICATE of bug 1351501
6 years ago
2 months ago

People

(Reporter: mccr8, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

6 years ago
The trick here is figuring out whether they are wrapper cached or not. One solution would be to add a flag on the class info that indicates whether they are or not. See discussion in bug 777385 and bug 825053.

This will require modifying TryPreserveWrapper.  Assuming we cover all cases, then TryPreserveWrapper can be made infallible and renamed to PreserveWrapper.
We could add a hook to the DOMClass for preserving a wrapper, set it to null if the wrapper can't be preserved, generate it for non-nsISupports and have a generic one for nsISupports. Xrays also need to preserve, and they currently bail for non-nsISupports.
(Reporter)

Comment 2

5 years ago
This is going to be a bigger problem now, as many WebGL classes are being converted away from nsISupports.
Is the following TypeError related to this bug? In Chrome code:  

```
var wm = new WeakMap(); 
// messageManager is a "ChromeMessageSender" instance
var mm = gBrowser.tabs[0].linkedBrowser.messageManager;
wm.set(mm, "whatever");
// TypeError: cannot use the given object as a weak map key
```
If it helps, the __proto__ for messageManager is "XPC_WN_ModsAllowed_NoCall_Proto_JSClass"
(Reporter)

Comment 5

4 years ago
(In reply to Marcos Caceres [:marcosc] from comment #3)
> Is the following TypeError related to this bug? In Chrome code:  

I think it isn't the same.  It looks like ChromeMessageSender is implemented by nsFrameMessageManager, which is ISupports.  I think the issue is that we don't support non-WebIDL things as weak map keys.

The relevant line is PreserveWrapper in XPCJSRuntime.cpp:
  return mozilla::dom::IsDOMObject(obj) && mozilla::dom::TryPreserveWrapper(obj);

We did used to support nsINode, but I think that was removed after node was converted to WebIDL:
  http://hg.mozilla.org/mozilla-central/diff/d7553251cf43/js/xpconnect/src/XPCJSRuntime.cpp
(Reporter)

Updated

4 years ago
Summary: Support Paris bindings objects that are both non-nsISupports and cycle-collected as weak maps keys → Support WebIDL objects that are both non-nsISupports and cycle-collected as weak map keys
The answer to comment 3 is to convert message manager to webidl.  Which we need to do anyway.
(Reporter)

Comment 7

4 years ago
(In reply to Not doing reviews right now from comment #6)
> The answer to comment 3 is to convert message manager to webidl.  Which we
> need to do anyway.

Yeah.  That's bug 888600.
Thanks for the clarifications+pointers.
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5
(Reporter)

Comment 10

2 months ago
Oops, looks like I filed an even older bug about this. Oh well. The newer bug has some discussion so I'll dupe this.
Status: NEW → RESOLVED
Last Resolved: 2 months ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1351501
You need to log in before you can comment on or make changes to this bug.