Files
bun.sh/src/buntime/bindings/webcore/JSEventTargetNode.cpp
Claude Bot 0620ff58fe refactor: move error files to api/error/
Step 4.3 of source reorganization - move error-related files:
- DeferredError.zig
- ErrorCode.cpp/h/ts/zig
- ErrorStackFrame.cpp/h
- ErrorStackTrace.cpp/h
- Errorable.zig
- JSErrorCode.zig
- SystemError.zig
- ZigErrorType.zig

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-31 08:53:21 +00:00

51 lines
1.6 KiB
C++

#include "root.h"
#include "JavaScriptCore/JSGlobalObject.h"
#include "JavaScriptCore/ArgList.h"
#include "JavaScriptCore/JSGlobalObjectInlines.h"
#include "JSEventTarget.h"
#include "JavaScriptCore/JSArray.h"
#include "wtf/text/MakeString.h"
#include "ErrorCode.h"
namespace Bun {
using namespace JSC;
using namespace WebCore;
JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeEventsGetEventListeners, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
auto& vm = JSC::getVM(globalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
if (callFrame->argumentCount() < 2) {
throwTypeError(globalObject, throwScope, "getEventListeners needs 2 arguments"_s);
return {};
}
JSValue thisValue = callFrame->argument(0);
auto* thisObject = jsDynamicCast<JSEventTarget*>(thisValue);
RETURN_IF_EXCEPTION(throwScope, {});
auto eventType = callFrame->argument(1).toWTFString(globalObject);
RETURN_IF_EXCEPTION(throwScope, {});
if (!thisObject) [[unlikely]] {
return Bun::throwError(globalObject, throwScope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE,
"ERR_INVALID_ARG_TYPE: first argument must be of type EventEmitter"_s);
}
MarkedArgumentBuffer values;
auto& listeners = thisObject->wrapped().eventListeners(WTF::makeAtomString(eventType));
for (auto& listener : listeners) {
auto* function = listener->callback().jsFunction();
if (function) {
values.append(function);
}
}
RELEASE_AND_RETURN(throwScope, JSValue::encode(constructArray(globalObject, static_cast<ArrayAllocationProfile*>(nullptr), values)));
}
}