Open Bug 1570744 Opened 5 years ago Updated 2 years ago

JSWindowActorChild instances cannot be used as observers

Categories

(Core :: DOM: Content Processes, defect, P3)

defect

Tracking

()

Fission Milestone Future

People

(Reporter: mconley, Unassigned)

Details

Minimal STR:

  1. 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]

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?

Flags: needinfo?(jdai)

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?

Flags: needinfo?(jdai) → needinfo?(mconley)

(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.

Flags: needinfo?(mconley)

Also cc'ing Neil and Abdoulaye so that they know about this.

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.

The priority flag is not set for this bug.
:jimm, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(jmathies)
Flags: needinfo?(jmathies)
Priority: -- → P3
Fission Milestone: --- → ?

This bug is not a Fission MVP blocker at this time.

Fission Milestone: ? → Future
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.