-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
[New] compare .toString
, .valueOf
, and [Symbol.toPrimitive]
completions
#79
Conversation
…pletions Co-authored-by: Andrew Rasmussen <andrew@canny.io> Co-authored-by: Jordan Harband <ljharb@gmail.com>
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
@ljharb hmm how do you want to proceed here? If we're adding toString comparisons then technically this test should be flipped. Alternatively, if you want to maintain backwards compatibility, we could skip the toString comparison if we detect > const foo = Object(function(){});
undefined
> const bar = Object(function () {});
undefined
> foo.toString()
'function(){}'
> bar.toString()
'function () {}' |
Codecov ReportAll modified lines are covered by tests ✅
📢 Thoughts on this report? Let us know!. |
@ljharb updated PR per your feedback. pretty sure the one test failure is flaky but don't think I'm able to re-run. |
@ljharb thanks for the feedback! ready for another pass, hopefully last one 😄 |
var valueIsFn = typeof value === 'function'; | ||
var otherIsFn = typeof other === 'function'; | ||
|
||
if (!valueIsFn || !otherIsFn) { |
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.
why this line? surely either a function or an object could both have toStrings or valueOfs that need comparing?
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.
otherwise functions with same arity/name/body are equal despite whitespace between signature and body
will fail because:
> const foo = Object(function(){});
undefined
> const bar = Object(function () {});
undefined
> foo.toString()
'function(){}'
> bar.toString()
'function () {}'
our options are to include this line, or delete that test. including this line is more backwards compatible.
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.
aha, hmm. that means this new functionality wouldn't apply to functions, which is weird. at the least, let's document that in the readme?
an alternative, tho, would be to skip the check for a function whenever the function's toString
is ===
to Function.prototype.toString
?
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.
Looks great overall; I've rebased and squashed it.
.toString
, .valueOf
, and [Symbol.toPrimitive]
completions
If
val
orother
are objects:val.toString()
andother.toString()
val.valueOf()
andother.valueOf()
es-to-primitive
to perform the above checks, with two separate hints (String
andNumber
)toString
andvalueOf
can throw, and makes sure both or neither arguments throwTest plan: