aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-08 18:27:16 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-08 18:27:16 -0800
commit51e437e8a08013888efd39a4c248d3e913ec6165 (patch)
treee4ae15eb4b2e1a84f6273e7aa15aac53c69d533b
parente6c2f48895454426cda4eb7dcfd1c2db996897e7 (diff)
downloadbun-51e437e8a08013888efd39a4c248d3e913ec6165.tar.gz
bun-51e437e8a08013888efd39a4c248d3e913ec6165.tar.zst
bun-51e437e8a08013888efd39a4c248d3e913ec6165.zip
EventEmitter - return original this value for better chainability
-rw-r--r--src/bun.js/bindings/webcore/JSEventEmitter.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/bun.js/bindings/webcore/JSEventEmitter.cpp b/src/bun.js/bindings/webcore/JSEventEmitter.cpp
index ad10687f9..b50f77cae 100644
--- a/src/bun.js/bindings/webcore/JSEventEmitter.cpp
+++ b/src/bun.js/bindings/webcore/JSEventEmitter.cpp
@@ -223,6 +223,7 @@ static inline JSC::EncodedJSValue addListener(JSC::JSGlobalObject* lexicalGlobal
{
auto& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSC::JSValue actualThis = callFrame->thisValue();
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
auto& impl = castedThis->wrapped();
@@ -237,7 +238,7 @@ static inline JSC::EncodedJSValue addListener(JSC::JSGlobalObject* lexicalGlobal
auto result = JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.addListenerForBindings(WTFMove(eventType), WTFMove(listener), once, prepend); }));
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
vm.writeBarrier(&static_cast<JSObject&>(*castedThis), argument1.value());
- RELEASE_AND_RETURN(throwScope, JSValue::encode(castedThis));
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(actualThis));
}
static inline JSC::EncodedJSValue jsEventEmitterPrototypeFunction_addListenerBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSEventEmitter>::ClassParameter castedThis)
@@ -318,6 +319,7 @@ static inline JSC::EncodedJSValue jsEventEmitterPrototypeFunction_removeListener
{
auto& vm = JSC::getVM(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSC::JSValue actualThis = callFrame->thisValue();
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
auto& impl = castedThis->wrapped();
@@ -332,7 +334,7 @@ static inline JSC::EncodedJSValue jsEventEmitterPrototypeFunction_removeListener
auto result = JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.removeListenerForBindings(WTFMove(eventType), WTFMove(listener)); }));
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
vm.writeBarrier(&static_cast<JSObject&>(*castedThis), argument1.value());
- RELEASE_AND_RETURN(throwScope, JSValue::encode(castedThis));
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(actualThis));
}
JSC_DEFINE_HOST_FUNCTION(jsEventEmitterPrototypeFunction_removeListener, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))