Open danilofuchs opened 3 months ago
hm, interesting - we have some copying that would lose the internal URL slots, so this isn't too surprising.
In general, this library is built for plain objects - if you do traverse({ x: new Map() }).map(function () { return this.node.size; })
you'll get a similar error.
In general, instanceof
is simply not a reliable tool in the language and should be avoided, both because it doesn't check internal slots and because Symbol.hasInstance
can be broken or forged.
In this case, to avoid the crash, you'd need to be guarding with a proper isURL
predicate (which doesn't exist on npm, so i guess i'll have to make one :-p ) - but that still wouldn't solve your underlying issue which is that you want to be able to get at the native toString behavior on a URL.
I think the general problem of "how do i get to the original, uncopied value" is worth addressing and considering a flaw, if not a bug.
tbh I'm not sure how to fix this.
One option is to laboriously list all language, node, and web builtins, and check for these as a "leaf".
A simpler option would be to accept a callback option, like isLeaf
, so you can decide if the value should be traversed further, or not.
For instance: