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(): Replace 'hasOwn' with 'in' operator in typeAssertions check #9812

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [next]

- fix(): Replace 'hasOwn' with 'in' operator in typeAssertions check [#9812](https://github.com/fabricjs/fabric.js/pull/9812)

## [6.0.0-rc1]

- fix(Canvas): Fix searchPossibleTargets for non-interactive nested targets [#9762](https://github.com/fabricjs/fabric.js/pull/9762)
Expand Down
6 changes: 2 additions & 4 deletions src/util/typeAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export const isSerializableFiller = (

export const isPattern = (filler: TFiller): filler is Pattern => {
return (
!!filler &&
(filler as Pattern).offsetX !== undefined &&
Object.hasOwn(filler, 'source')
!!filler && (filler as Pattern).offsetX !== undefined && 'source' in filler
);
};

Expand All @@ -46,4 +44,4 @@ export const isPath = (fabricObject?: FabricObject): fabricObject is Path => {
export const isActiveSelection = (
fabricObject?: FabricObject
): fabricObject is ActiveSelection =>
!!fabricObject && Object.hasOwn(fabricObject, 'multiSelectionStacking');
!!fabricObject && 'multiSelectionStacking' in fabricObject;
Copy link

Choose a reason for hiding this comment

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

keep in mind that in also checks if property exists down the prototype chain, where hasOwnProperty just makes sure that it is a direct property of an object

Copy link
Member

Choose a reason for hiding this comment

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

Yes i was commenting while you posted this, and indeed it also make more sense for the subclasses.
While 'multiSelectionStacking' or 'source' are a property that get defined over and over through the getDefaults() in the contructors, that may not be the case if getDefaults() is emptied and you decide to work on the prototype chain with values. In that case on a subclass ownProperty would fail, but in no.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I used in as well because for the filler.source case it should be an own property typically, whereas with the ActiveSelection case it's even safer if the class is subclassed

Loading