Skip to content
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

fix(EventEmitter) only apply if listener #35577 #36087

Closed
wants to merge 6 commits into from

Conversation

DerBasler
Copy link

@DerBasler DerBasler commented Feb 8, 2023

Summary

During the rewrite of the event listeners in e5c5dcd a check was removed if the listener exists.
This change now checks that the listener is registred correctly.

Changelog

[INTERNAL] [FIXED] - make sure the event listener is registred correctly

Test Plan

Try to add an event listener without a proper func as parameter

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 8, 2023
@analysis-bot
Copy link

analysis-bot commented Feb 8, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,494,057 -110,556
android hermes armeabi-v7a 7,814,976 -103,547
android hermes x86 8,975,632 -114,849
android hermes x86_64 8,829,633 -115,932
android jsc arm64-v8a 9,660,410 +486,577
android jsc armeabi-v7a 8,395,784 +30,291
android jsc x86 9,724,865 +493,377
android jsc x86_64 10,201,463 +711,282

Base commit: a6690bf
Branch: main

@javache
Copy link
Member

javache commented Feb 8, 2023

Listeners should always be non-null. Could we consider fixing the calling packages instead?

@yungsters
Copy link
Contributor

I agree with @javache.

This can only happen if addListener() is invoked with a non-function argument as its second argument. This happening seems like a symptom of an issue further upstream in the calling code.

If the point at which this becomes an error is too confusing to debug dependent packages, I'd be amenable to introducing a type check in addListener, for example:

if (typeof listener !== 'function') {
  throw new TypeError('EventEmitter.addListener(…): 2nd argument must be a function.');
}

@yungsters yungsters self-requested a review February 8, 2023 19:04
@DerBasler
Copy link
Author

Yes you guys are right I can adjust it over the weekend.
I guess I just wanted a quick fix for my problem 😅

@github-actions
Copy link

github-actions bot commented Apr 7, 2023

Fails
🚫

📋 Missing Changelog - Please add a Changelog to your PR description. See Changelog format

Warnings
⚠️

Libraries/vendor/emitter/tests/EventEmitter-test.js#L137 - Libraries/vendor/emitter/tests/EventEmitter-test.js line 137 – Unexpected alias 'result' for 'this'. (consistent-this)

Generated by 🚫 dangerJS against d307154

@yungsters
Copy link
Contributor

I think I already landed this change in main. This PR can be closed now, right?

@DerBasler
Copy link
Author

@yungsters ah I didn't notice nice 👍 thx for the info

@DerBasler DerBasler closed this Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants