Skip to content

support DOMException via iserror from npm #913

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

Closed
wants to merge 1 commit into from

Conversation

graingert
Copy link
Contributor

Before submitting a pull request, please verify the following:

  • If you've added code that should be tested, please add tests.
  • If you've modified the API (e.g. added a new config or public method), update the docs and TypeScript declaration file.
  • [?] Ensure your code lints and the test suite passes (npm test).

@graingert
Copy link
Contributor Author

graingert commented Mar 30, 2017

hmm probably not worth adding this until yefremov/iserror#8

You don't need an isObject check here.

// with some tiny modifications
function isError(what) {
var toString = {}.toString.call(what);
return isObject(what) &&
Copy link
Contributor Author

@graingert graingert Mar 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benvinegar what is this isObject check for? There's no way to override what Object.prototype.toString does. without being an object. (ES2016, @@toStringTag)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commented: https://github.com/joyent/node/blob/aa3b4b4/lib/util.js#L560

This was just yanked from Node core, so I'm not entirely sure what this is doing. Just standing on top of giants here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it's a bit mysterious. Node has moved to a special internal isError that cannot be implemented in plain JS, because objects can override the behaviour of Object.prototype.toString via @@toStringTag

Of course legacy JS could still replace Object.prototype.toString.

@LewisJEllis
Copy link
Contributor

I'd rather just add a line || toString === '[object DOMException]' to our existing isError (or refactor to a switch/case) than introduce a dependency when we don't otherwise have any.

@graingert
Copy link
Contributor Author

@LewisJEllis you already depend on json-stringify-safe

@LewisJEllis
Copy link
Contributor

No we don't, we vendored it in #883 for IE8 compat, I just forgot to remove it from package.json until #917.

@graingert
Copy link
Contributor Author

Closing in favour on #919

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants