Skip to content
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

Add native EventEmitter #1123

Merged
merged 5 commits into from Aug 21, 2022
Merged

Add native EventEmitter #1123

merged 5 commits into from Aug 21, 2022

Conversation

zhuzilin
Copy link
Collaborator

No description provided.

UNUSED_PARAM(callFrame);
auto& impl = castedThis->wrapped();
if (UNLIKELY(callFrame->argumentCount() < 1))
return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

later this will need to be a node error with the code set to match

We have that in Zig but not in C++ yet

JSC::VM& vm = lexicalGlobalObject->vm();
GlobalObject* globalObject = reinterpret_cast<GlobalObject*>(lexicalGlobalObject);

exportNames.append(JSC::Identifier::fromString(vm, "EventEmitter"_s));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to export both the class but also the properties of the class

<ref *1> [Function: EventEmitter] {
  once: [AsyncFunction: once],
  on: [Function: on],
  getEventListeners: [Function: getEventListeners],
  EventEmitter: [Circular *1],
  usingDomains: false,
  captureRejectionSymbol: Symbol(nodejs.rejection),
  captureRejections: [Getter/Setter],
  EventEmitterAsyncResource: [Getter],
  errorMonitor: Symbol(events.errorMonitor),
  defaultMaxListeners: [Getter/Setter],
  setMaxListeners: [Function (anonymous)],
  init: [Function (anonymous)],
  listenerCount: [Function (anonymous)]
}

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but maybe its fine if its the default export too

{
if (auto* target = jsDynamicCast<JSEventEmitter*>(thisValue))
return makeUnique<JSEventEmitterWrapper>(target->wrapped(), *target);
if (auto* object = jsDynamicCast<JSObject*>(thisValue)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (auto* object = jsDynamicCast<JSObject*>(thisValue)) {
if (auto* object = jsDynamicCast<JSNonFinalObject*>(thisValue)) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that will handle the case where it's a constructor or prototype

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

// use `mapPrivateName` as it is not occupied.
auto emitterTag = WebCore::clientData(vm)->builtinNames().mapPrivateName();
JSC::JSValue value = object->getDirect(vm, emitterTag);
if (!value) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh i'm not 100% sure if this should be !value.isUndefined or !value

maybe we want

Suggested change
if (!value) {
if (!value || value.isUndefined()) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least for the express example, !value works.

@Jarred-Sumner Jarred-Sumner merged commit 3d8bc14 into oven-sh:main Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants