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

Change typeof for prototype check to only process plain objects as mappers inputs #4258

Merged
merged 2 commits into from
Mar 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/reanimated2/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ export function createMapperRegistry() {
}
} else if (inputs.addListener) {
resultArray.push(inputs);
} else if (typeof inputs === 'object') {
} else if (Object.getPrototypeOf(inputs) === Object.prototype) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if that's valid scenario but if inputs is null or undefined it will throw an error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it can be null, otherwise typescript would've alerted us

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it was null, than the previous else if that I'm not chaging would already crash the app as it is accessing a addListener property of inputs

// we only extract inputs recursively from "plain" objects here, if object
// is of a derivative class (e.g. HostObject on web, or Map) we don't scan
// it recursively
for (const element of Object.values(inputs)) {
element && extractInputs(element, resultArray);
}
Expand Down