aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-17 16:27:21 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-17 16:27:21 -0800
commit9f0d402a7d35f77fe868d6cb48727446cd80c531 (patch)
tree50b0d511e4a84b53b776625ef8d0ad11981ed3fe
parentf927567b9f0c9e374920069005abe01439150975 (diff)
downloadbun-9f0d402a7d35f77fe868d6cb48727446cd80c531.tar.gz
bun-9f0d402a7d35f77fe868d6cb48727446cd80c531.tar.zst
bun-9f0d402a7d35f77fe868d6cb48727446cd80c531.zip
[EventEmitter] Fix emitter.off("eventName")
-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());