awslabs / llrt

LLRT (Low Latency Runtime) is an experimental, lightweight JavaScript runtime designed to address the growing demand for fast and efficient Serverless applications.
Apache License 2.0
7.73k stars 341 forks source link

feat: Implement of EventTarget #436

Open nabetti1720 opened 3 days ago

nabetti1720 commented 3 days ago

Issue # (if available)

Closes #262

Description of changes

This PR is intended to address the following issues:

It is not yet complete in the following respects: 1. type property of CustomEvent is not available. We know that we need to modify EventKey::from_value(). ==>We were able to avoid this by preparing a dedicated dispatchEvent(). 2. the test code is not written yet.

// event_target3.js
const catFound = new CustomEvent("animalfound", {
  detail: {
    name: "cat",
  },
});
const dogFound = new CustomEvent("animalfound", {
  detail: {
    name: "dog",
  },
});

console.log(catFound);
console.log(dogFound);

const obj = new EventTarget()
obj.addEventListener("animalfound", (e) => console.log(e.detail.name));

obj.dispatchEvent(catFound);
obj.dispatchEvent(dogFound);
% ./llrt event_target3.js
CustomEvent {
  detail: {
    name: 'cat'
  },
  type: 'animalfound'
}
CustomEvent {
  detail: {
    name: 'dog'
  },
  type: 'animalfound'
}
cat
dog

Checklist

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

nabetti1720 commented 3 hours ago

I think it is fine as a minimal implementation. Please merge if you have no problem with the review.