Don't use instanceof
in lib/util.js "is" checks.
#1942
Conversation
It seems to be intentional... |
Well let's get @isaacs' and @bnoordhuis' opinions on this again. Because honestly, I don't see any benefit in these false-positives, and it's even exposing a crash in the REPL (#1941). |
It's a bug so let's get it fixed. I would add comments explaining why the functions are implemented the way they are, so some overzealous optimizer doesn't reintroduce the problem in the future. Tests would be nice too. We decided on the ML to export the functions to user land, testability is a nice side effect of that. |
@bnoordhuis I've added a comment to I've opened #1948, so once that is merged then we can add some tests regarding this broken behavior to that test case. |
While using `instanceof`, these functions could easily be faked with something like: Object.create(Date.prototype) So let's just not use it at all. A little slower, but these functions are only used in the REPL / for debugging so it's OK.
OK, test cases added. This one is ready! |
Thanks, fixed. |
Add test for the false-positives from #1942. Fix test-sys.js.
While using
instanceof
, these functions could easily be faked with somethinglike: Object.create(Date.prototype)
So let's just not use it at all. A little slower, but these functions are only
used in the REPL / for debugging so it's OK.
This fixes #1941.