StarlingMonkey icon indicating copy to clipboard operation
StarlingMonkey copied to clipboard

Implement `EventTarget` and `Event` builtin

Open andreiltd opened this issue 10 months ago • 3 comments

This patch sets the stage for incoming AbortController and AbortSignal:

  • implements Event interface: https://dom.spec.whatwg.org/#interface-event,
  • implements CustomEvent interface: https://dom.spec.whatwg.org/#interface-customevent,
  • implement EventTarget interface: https://dom.spec.whatwg.org/#interface-eventtarget,
  • adds a global EventTarget instance,
  • makes FetchEvent a subclass of Event and uses global EventTarget.

Closes: https://github.com/bytecodealliance/StarlingMonkey/issues/156

andreiltd avatar Feb 25 '25 14:02 andreiltd

Great to see this. Strictly speaking FetchEvent is supposed to be a subclass of this Event. Not sure how practical that will be though, but I think that's the WinterTC expectation.

guybedford avatar Feb 25 '25 16:02 guybedford

Great to see this. Strictly speaking FetchEvent is supposed to be a subclass of this Event. Not sure how practical that will be though, but I think that's the WinterTC expectation.

Yeah, I think it should be doable similar to how we made File extending Blob. I will look into this when I have a moment. I think the other nice to have event would be CustomEvent.

andreiltd avatar Feb 25 '25 16:02 andreiltd

Strictly speaking FetchEvent is supposed to be a subclass of this Event.

So this is now working as expected, for instance this code shows FetchEvent using Event interface (event.type).

async function handler(event) {
  console.log(event.type);
}

addEventListener("fetch", (event) =>
  event.respondWith(
    (async () => {
      await handler(event);
      return new Response(`Success`);
    })(),
  ),
);

andreiltd avatar Mar 11 '25 10:03 andreiltd

Looks great! Feel free to merge whenever

tschneidereit avatar Jul 14 '25 12:07 tschneidereit