Wrapping Event in a C++ class so that every where you pass an event it works.
Nessuno ha ancora preso questa issue.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
in JavaScript I can do this
class MyEvent extends Event {
constructor(type, msg) {
super(type);
this.message = msg;
}
}
const target = new EventTarget();
const e = await new Promise(resolve => {
target.addEventListener('custom', resolve);
target.dispatchEvent(new MyEvent('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(new MyEvent('custom', 'hello') instanceof Event);
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.
- Lingua principale
- C++
- Stelle
- 2.4k
- Fork
- 499
- Merge medio
- 2g 11h
- PR unite (30g)
- 2
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nodejs/node-addon-api
-
blocked SemVer-major
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
nodejs/node-addon-api#1748 ·
-
Support C++20 span types ApertaSemVer-major
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
nodejs/node-addon-api#1747 · 2 commenti ·
-
blocked SemVer-major
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
nodejs/node-addon-api#1746 ·
-
SemVer-major
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
nodejs/node-addon-api#1745 ·
-
stale
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
nodejs/node-addon-api#1724 · 2 commenti ·
Tutte le issue di nodejs/node-addon-api
Issue simili
-
Website Doc Typo Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 92/100
autowarefoundation/autoware_universe#13413 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
automated-analysis bug memory-safety
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100