aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/bindings/webcore/JSEventEmitter.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/bun.js/bindings/webcore/JSEventEmitter.cpp b/src/bun.js/bindings/webcore/JSEventEmitter.cpp
index 542de1339..28a18c31c 100644
--- a/src/bun.js/bindings/webcore/JSEventEmitter.cpp
+++ b/src/bun.js/bindings/webcore/JSEventEmitter.cpp
@@ -332,11 +332,16 @@ static inline JSC::EncodedJSValue jsEventEmitterPrototypeFunction_removeListener
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
auto& impl = castedThis->wrapped();
- if (UNLIKELY(callFrame->argumentCount() < 2))
+ if (UNLIKELY(callFrame->argumentCount() < 1))
return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));
EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0);
auto eventType = argument0.value().toPropertyKey(lexicalGlobalObject);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ if (callFrame->argumentCount() < 2) {
+ impl.removeAllListeners(eventType);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(actualThis));
+ }
+
EnsureStillAliveScope argument1 = callFrame->uncheckedArgument(1);
auto listener = convert<IDLNullable<IDLEventListener<JSEventListener>>>(*lexicalGlobalObject, argument1.value(), *castedThis, [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeObjectError(lexicalGlobalObject, scope, 1, "listener", "EventEmitter", "removeListener"); });
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());