jasnell / proposal-istypes

TC-39 Proposal for additional is{Type} APIs
201 stars 7 forks source link

Include example with Symbol.toStringTag #1

Closed cjihrig closed 7 years ago

cjihrig commented 7 years ago

This is another thing that causes problems. Node's util functions used to check the result of toString(), but that is no longer feasible because of Symbol.toStringTag.

See the note and example on this in https://nodejs.org/api/util.html#util_util_iserror_object.

ljharb commented 7 years ago

The only way to reliably polyfill the ability to brand check is with try/catch.

See http://npmjs.com/is-string, https://www.npmjs.com/package/is-number-object, https://www.npmjs.com/package/is-typed-array, https://www.npmjs.com/package/is-symbol, etc.

jasnell commented 7 years ago

I believe the current proposal handles this issue. So long as a reference to the default @@builtin function is grabbed, it should be possible to reliably check for the existence of the [[Builtin]] internal slot despite user monkeypatching.