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
Add native EventEmitter #1123
Conversation
UNUSED_PARAM(callFrame); | ||
auto& impl = castedThis->wrapped(); | ||
if (UNLIKELY(callFrame->argumentCount() < 1)) | ||
return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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)]
}
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (auto* object = jsDynamicCast<JSObject*>(thisValue)) { | |
if (auto* object = jsDynamicCast<JSNonFinalObject*>(thisValue)) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
if (!value) { | |
if (!value || value.isUndefined()) { |
There was a problem hiding this comment.
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.
No description provided.