Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 493
Open
Labels
Description
in JavaScript I can do this
classMyEventextendsEvent{constructor(type,msg){super(type);this.message=msg;}}consttarget=newEventTarget();conste=awaitnewPromise(resolve=>{target.addEventListener('custom',resolve);target.dispatchEvent(newMyEvent('custom','hello'));});assert.ok(e.message==='hello');Is it possible to have MyEvent be a C++ class?
In my current attempt, when I call target.dispatchEvent I get
node:internal/event_target:220 throw new ERR_INVALID_THIS('Event'); ^ TypeError [ERR_INVALID_THIS]: Value of "this" must be of type Event at get type [as type] (node:internal/event_target:220:13) at EventTarget.dispatchEvent (node:internal/event_target:755:40) I tried setting the prototype chain in C++ and this passes
assert.ok(newMyEvent('custom','hello')instanceofEvent);but of course it's not actually an Event, it's a non-event who's prototype chain contains Event which is what node is complaining about.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Has PR