This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 27062 - DOMException constructor should allow name to be supplied
Summary: DOMException constructor should allow name to be supplied
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-15 17:23 UTC by Domenic Denicola
Modified: 2016-10-21 21:07 UTC (History)
4 users (show)

See Also:


Attachments

Description Domenic Denicola 2014-10-15 17:23:53 UTC
I am trying to create e.g. an IndexedSizeError so as to better match the behavior of native elements, and cannot do so since the DOMException constructor only takes a message, and not a name.

Happy to do a PR for this (presumably making the name the second argument) if you agree this is a good idea.
Comment 1 Boris Zbarsky 2014-10-15 18:16:56 UTC
This seems reasonable to me, yeah.

I wish we could use this for http://heycam.github.io/webidl/#es-creating-throwing-exceptions too, but ES exceptions do .name based on which constructor you called...
Comment 2 Domenic Denicola 2014-10-15 18:19:04 UTC
Right, that whole section is largely about why DOMException is a special flower that behaves unlike all the standard ES Error classes :(.

Cool, I'll work up a PR.
Comment 3 Cameron McCormack 2014-11-14 05:54:12 UTC
(In reply to Domenic Denicola from comment #0)
> I am trying to create e.g. an IndexedSizeError so as to better match the
> behavior of native elements, and cannot do so since the DOMException
> constructor only takes a message, and not a name.

I'm fine with this, but did you mean you can't do it all, or just not in a single line?

  var e = new DOMException("...");
  e.name = "IndexSizeError";
  e.code = 1;
Comment 4 Domenic Denicola 2014-11-24 18:58:52 UTC
> I'm fine with this, but did you mean you can't do it all, or just not in a single line?

You're right; I didn't read far enough to realize that DOMExceptions created using the constructor actually don't have any name or code properties. It doesn't help that the constructor isn't implemented anywhere :).

Nevertheless the PR's refactoring gives a nicer solution IMO, both for authors and at a spec level.
Comment 6 Domenic Denicola 2016-10-21 21:07:43 UTC
This now works, although the spec still needs some rescuing; see https://github.com/heycam/webidl/issues/55