-
Notifications
You must be signed in to change notification settings - Fork 448
Replace instanceof check with duck-typing in Filter#toBer mixin #630
Conversation
Not sure what happened here with the CI:
Random failure? |
@jsumners That helped, thanks! |
lib/filters/filter.js
Outdated
function mixin (target) { | ||
target.prototype.toBer = function toBer (ber) { | ||
if (!ber || !(ber instanceof BerWriter)) { throw new TypeError('ber (BerWriter) required') } | ||
if (!ber || !isBerWriter(ber)) { throw new TypeError('ber (BerWriter) required') } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!ber || !isBerWriter(ber)) { throw new TypeError('ber (BerWriter) required') } | |
if (isBerWriter(ber) === false) { throw new TypeError('ber (BerWriter) required') } |
And make the undefined check part isBerWriter
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should check for null
in isBerWriter
otherwise the error Uncaught TypeError: Cannot read property 'startSequence' of null
will be thrown with this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's the coerced check for !ber
. I just want to see it in the check function instead as another inlined condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I've just moved the falsiness check into the function to shorten the condition. Is this OK?
Co-authored-by: James Sumners <james@sumners.email>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Will merge and release when I am able.
Please include a minimal reproducible example |
This fixes #629 where, if this package was used in 2 instances (e.g. depended upon by 2 different packages) where one passes a Client object to the other, they would not recognize each other's
BerWriter
instances and throw an error on.search()
with filters.