JSWindowActorChild instances cannot be used as observers
Categories
(Core :: DOM: Content Processes, enhancement, P3)
Tracking
()
Fission Milestone | Future |
People
(Reporter: mconley, Unassigned)
Details
(Whiteboard: dom-lws-bugdash-triage)
Minimal STR:
- Run the following code in the Browser Console:
{
class MyActor extends JSWindowActorChild {};
MyActor.prototype.QueryInterface = ChromeUtils.generateQI(["nsIObserver"]);
let instance = new MyActor();
Services.prefs.addObserver("foo.bar", instance);
}
ER:
instance
is added as an observer for a preference.
AR:
The following exception is thrown:
[Exception... "Could not convert JavaScript argument arg 1 [nsIPrefBranch.addObserver]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: debugger eval code :: <TOP_LEVEL> :: line 1" data: no]
Reporter | ||
Comment 1•5 years ago
|
||
Hey jdai, I expect this might come up periodically with JSWindowActorChild's (and Parent's as well, perhaps) - it's a fairly common pattern in front-end to want to add an object as an observer like this. Any idea why it's not possible?
Comment 2•5 years ago
|
||
This is caused because the underlying actor object is inheriting from a WebIDL-defined DOM object. This means that the set of interfaces it's considered to implement unfortunately is defined by the native object, and it can't be wrapped as a normal JS value.
If this is an issue which will come up frequently, we may need to look into alternative ways to handle the special methods inserted onto the JSWindowActor object which don't involve having a native object in the prototype chain.
:mconley, how often do you want your actor objects to act as observers or other XPIDL interfaces?
Reporter | ||
Comment 3•5 years ago
|
||
(In reply to :Nika Layzell (Away until Aug. 26) from comment #2)
:mconley, how often do you want your actor objects to act as observers or other XPIDL interfaces?
This is only the first time it's happened, but it's kind of a gotcha - front-end JS hackers are used to just attaching JS objects or class instances as nsIObserver's without much fuss. Hitting this was kind of a surprise.
How often do I expect this to happen? I've found only one non-ported Actor that wants to do this same thing:
There might be some more instances as we convert more things off of framescripts.
So I'm going to say it's probably not a frequent need, just surprising that it doesn't work as frontend'd expect.
Reporter | ||
Comment 4•5 years ago
|
||
Also cc'ing Neil and Abdoulaye so that they know about this.
Reporter | ||
Comment 5•5 years ago
|
||
I think the main confused will probably stem from the fact that sometimes JSWindowActors can seem to act as nsIObsevers
(when registered with the observers
option), but can't be added or removed as observers manually.
Comment 6•5 years ago
|
||
The priority flag is not set for this bug.
:jimm, could you have a look please?
For more information, please visit auto_nag documentation.
Updated•5 years ago
|
Updated•5 years ago
|
Comment 7•5 years ago
|
||
This bug is not a Fission MVP blocker at this time.
Updated•2 years ago
|
Updated•6 months ago
|
Description
•