Open
Bug 1512817
Opened 6 years ago
Updated 2 years ago
JS classes with handleEvent method cannot be added as EventListener through SpecialPowers
Categories
(Testing :: Mochitest, enhancement)
Testing
Mochitest
Tracking
(Not tracked)
NEW
People
(Reporter: JanH, Unassigned)
Details
I have a JS class with a "handleEvent(aEvent)" method defined on it, i.e. something like > class Foo { > constructor(bar, baz) { > this.eventCount = 0; > } > > handleEvent(aEvent) { > this.eventCount++; > } > } If I register an instance of that class via plain EventTarget.addEventListener() as usual, everything works fine. However if I use e.g. SpecialPowers.addSystemEventListener() instead, instead of receiving the events I got some error messages in the console along the lines of "property 'handleEvent' not callable", or some words to that effect. As a workaround, I'm currently assigning the function to a property in the constructor instead, i.e. like > constructor(bar, baz) { > this.handleEvent = (aEvent) => { > this.eventCount++; > } > }
Reporter | ||
Comment 1•6 years ago
|
||
... and then explicitly passing fooInstance.handleEvent (respectively this.handleEvent when registering from within the class itself). Or I could omit the property definition in comment 0 and then use this.handleEvent.bind(this). If I only pass a reference to the class instance object itself, with the expectation that its handleEvent method will be implicitly called, then a) if handleEvent is defined as a method, I get > JavaScript Error: "TypeError: Property 'handleEvent' is not callable." b) if handleEvent is defined as a function assigned to a property, I get > JavaScript Warning: "XrayWrapper denied access to property "handleEvent" (reason: value is callable). See https://developer.mozilla.org/en-US/docs/Xray_vision for more information. Note that only the first denied property access from a given global object will be reported." > JavaScript Error: "TypeError: Property 'handleEvent' is not callable."
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•