-
Notifications
You must be signed in to change notification settings - Fork 50
Implement EventTarget and Event builtin
#220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e72eae0
Implement EventTarget builtin
andreiltd 0499ed8
implement policy-based design for builtin classes
andreiltd c30d983
Address code review feedback
andreiltd 4f8f068
Add TODO about exception reporting
andreiltd a0abd76
Change subclass registry from vector to unordered_set
andreiltd f56b76e
Replace listener instances with RefPtr in the EventTarget listener list
andreiltd c3ebf87
Remove "once" listeners before dispatch
andreiltd 93d68d0
Defer removing listeners to after the dispatch loop
andreiltd c8cb3f3
Merge branch 'main' into event-target
andreiltd 461677e
Merge branch 'main' into event-target
andreiltd 8495be3
Addres code review feedback
andreiltd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| #include "custom-event.h" | ||
|
|
||
| namespace builtins { | ||
| namespace web { | ||
| namespace event { | ||
|
|
||
| const JSFunctionSpec CustomEvent::static_methods[] = { | ||
| JS_FS_END, | ||
| }; | ||
|
|
||
| const JSPropertySpec CustomEvent::static_properties[] = { | ||
| JS_PS_END, | ||
| }; | ||
|
|
||
| const JSFunctionSpec CustomEvent::methods[] = { | ||
| JS_FS_END, | ||
| }; | ||
|
|
||
| const JSPropertySpec CustomEvent::properties[] = { | ||
| JS_PSG("detail", CustomEvent::detail_get, JSPROP_ENUMERATE), | ||
| JS_STRING_SYM_PS(toStringTag, "CustomEvent", JSPROP_READONLY), | ||
| JS_PS_END, | ||
| }; | ||
|
|
||
| bool CustomEvent::detail_get(JSContext *cx, unsigned argc, JS::Value *vp) { | ||
| METHOD_HEADER(0); | ||
| // TODO: Change this class so that its prototype isn't an instance of the class | ||
| if (self == proto_obj) { | ||
| return api::throw_error(cx, api::Errors::WrongReceiver, "name get", "CustomEvent"); | ||
| } | ||
|
|
||
| args.rval().set(JS::GetReservedSlot(self, Slots::Detail)); | ||
| return true; | ||
| } | ||
|
|
||
| bool CustomEvent::constructor(JSContext *cx, unsigned argc, JS::Value *vp) { | ||
| CTOR_HEADER("CustomEvent", 2); | ||
|
|
||
| RootedValue type(cx, args.get(0)); | ||
| RootedValue opts(cx, args.get(1)); | ||
| RootedValue detail(cx); | ||
|
|
||
| RootedObject self(cx, JS_NewObjectForConstructor(cx, &class_, args)); | ||
| if (!self) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!Event::init(cx, self, type, opts)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (opts.isObject()) { | ||
| JS::RootedObject obj(cx, &opts.toObject()); | ||
| if (!JS_GetProperty(cx, obj, "detail", &detail)) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| SetReservedSlot(self, Slots::Detail, detail); | ||
|
|
||
| args.rval().setObject(*self); | ||
| return true; | ||
| } | ||
|
|
||
| bool CustomEvent::init_class(JSContext *cx, JS::HandleObject global) { | ||
| Event::register_subclass(&class_); | ||
| return init_class_impl(cx, global, Event::proto_obj); | ||
| } | ||
|
|
||
| } // namespace event | ||
| } // namespace web | ||
| } // namespace builtins |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #ifndef BUILTINS_WEB_CUSTOM_EVENT_H_ | ||
| #define BUILTINS_WEB_CUSTOM_EVENT_H_ | ||
|
|
||
| #include "builtin.h" | ||
| #include "event.h" | ||
|
|
||
| namespace builtins { | ||
| namespace web { | ||
| namespace event { | ||
|
|
||
| class CustomEvent : public BuiltinImpl<CustomEvent> { | ||
| static bool detail_get(JSContext *cx, unsigned argc, JS::Value *vp); | ||
|
|
||
| public: | ||
| static constexpr int ParentSlots = Event::Slots::Count; | ||
| enum Slots { Detail = ParentSlots, Count }; | ||
|
|
||
| static constexpr const char *class_name = "CustomEvent"; | ||
| static constexpr unsigned ctor_length = 2; | ||
|
|
||
| static const JSFunctionSpec static_methods[]; | ||
| static const JSPropertySpec static_properties[]; | ||
| static const JSFunctionSpec methods[]; | ||
| static const JSPropertySpec properties[]; | ||
|
|
||
| static JSString *name(JSObject *self); | ||
|
|
||
| static bool init_class(JSContext *cx, HandleObject global); | ||
| static bool constructor(JSContext *cx, unsigned argc, Value *vp); | ||
| }; | ||
|
|
||
| } // namespace event | ||
| } // namespace web | ||
| } // namespace builtins | ||
|
|
||
| #endif // BUILTINS_WEB_CUSTOM_EVENT_H_ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.