From 137856d678f67b6f79f0c3ef4bd7d233629a685f Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Fri, 24 Oct 2014 17:02:00 -0400 Subject: [PATCH] Make the DOMException constructor accept a name It will automatically set the code from the name (if it is one of the legacy names that have codes). It now just calls `super(message)` to initialize the message and all of the internal error-related state. The "creating exceptions" section was refactored to work in terms of the new, fully-functional constructor. Closes https://www.w3.org/Bugs/Public/show_bug.cgi?id=27062. --- index.html | 92 +++++++++++++++++++++--------------------------------- index.xml | 86 +++++++++++++++++++------------------------------- 2 files changed, 67 insertions(+), 111 deletions(-) diff --git a/index.html b/index.html index 162f457a..3816dbdc 100644 --- a/index.html +++ b/index.html @@ -19,7 +19,7 @@ -
W3C

Web IDL (Second Edition)

W3C Editor’s Draft 9 April 2015

This Version:
http://heycam.github.io/webidl/
Latest Version:
http://www.w3.org/TR/WebIDL/
Previous Versions:
http://www.w3.org/TR/2012/CR-WebIDL-20120419/
http://www.w3.org/TR/2012/WD-WebIDL-20120207/
http://www.w3.org/TR/2011/WD-WebIDL-20110927/
http://www.w3.org/TR/2011/WD-WebIDL-20110712/
http://www.w3.org/TR/2010/WD-WebIDL-20101021/
http://www.w3.org/TR/2008/WD-WebIDL-20081219/
http://www.w3.org/TR/2008/WD-WebIDL-20080829/
http://www.w3.org/TR/2008/WD-DOM-Bindings-20080410/
http://www.w3.org/TR/2007/WD-DOM-Bindings-20071017/
Participate:
+
@@ -72,7 +72,7 @@

Status of This Document

report can be found in the W3C technical reports index at http://www.w3.org/TR/.

- This document is the 9 April 2015 Editor’s Draft of the + This document is the 13 April 2015 Editor’s Draft of the Web IDL (Second Edition) specification. Please send comments about this document to @@ -124,7 +124,7 @@

Status of This Document

Table of Contents

-
+
@@ -3654,7 +3654,7 @@

3.2.7. Iterable declarations

can change during iteration, the behaviour of an iterator defined to to loop through the items in order, starting at index 0, and advancing this index on each iteration. Iteration ends when - the index has gone past the end of the list. + the index has gone past the end of the list.

Note

This is how array iterator objects work. @@ -4270,7 +4270,7 @@

3.4. Exceptions

SyntaxError, which is deliberately omitted as it is for use only by the ECMAScript parser). The meaning of - each simple exception matches + each simple exception matches its corresponding Error object in the ECMAScript specification.

@@ -14281,7 +14281,8 @@

4.10. Exceptions

There MUST exist a property on the ECMAScript global object whose name is “DOMException” and value is an object called the DOMException constructor object, - which provides access to legacy DOMException code constants. + which provides access to legacy DOMException code constants and allows construction of + DOMException instances. The property has the attributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.

@@ -14307,31 +14308,27 @@

4.10.1. DOMException constructor object

-
4.10.1.1. DOMException constructor object [[Call]] method
+
4.10.1.1. DOMException(message, name)
+ +

When the DOMException function is called with arguments message and name, the following steps are taken:

-

- The internal [[Call]] method of the - DOMException constructor object - MUST behave as follows, assuming - arg0..n−1 is the list - of argument values passed to the function: -

    -
  1. Let O be a new object whose [[Prototype]] - internal property is set to the DOMException prototype object - and whose class string is “DOMException”.
  2. -
  3. If n > 0 and arg0 is not undefined, then: +
  4. Let F be the active function object.
  5. +
  6. If NewTarget is undefined, let newTarget be F, else let newTarget be NewTarget.
  7. +
  8. Let super be F.[[GetPrototypeOf]]().
  9. +
  10. ReturnIfAbrupt(super).
  11. +
  12. If IsConstructor(super) is false, throw a TypeError exception.
  13. +
  14. Let O be Construct(super, «‍message», newTarget).
  15. +
  16. If name is not undefined, then
      -
    1. Let S be the result of calling ToString(arg0).
    2. -
    3. Call the [[DefineOwnProperty]] internal method of O passing - “message”, Property Descriptor { [[Value]]: S, - [[Writable]]: true, [[Enumerable]]: false, - [[Configurable]]: true }, and false - as arguments. -
      Note
      -

      This shadows the “message” property from Error.prototype, whose initial value is the empty string.

      -
    4. -
  17. +
  18. Let name be ToString(name).
  19. +
  20. Let status be DefinePropertyOrThrow(O, "name", PropertyDescriptor{[[Value]]: name, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}).
  21. +
  22. ReturnIfAbrupt(status).
  23. +
  24. Let code be the legacy code indicated in the error names table for error name name, or 0 if there is none.
  25. +
  26. Let status be DefinePropertyOrThrow(O, "code", PropertyDescriptor{[[Value]]: code, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}).
  27. +
  28. ReturnIfAbrupt(status).
  29. +
+
  • Return O.
  • @@ -14464,15 +14461,17 @@

    4.12. Creating and throwing exceptions

    the following steps MUST be followed:

      -
    1. Let args be a list of ECMAScript - values. If the optional user agent-defined message M was specified, then this list - has a single element whose value is the result of - converting - M to a String value. - Otherwise, the list is empty.
    2. - +
    3. If M was not specified, let M be undefined. Otherwise, let it be the result of converting M to a String value.
    4. +
    5. Let N be the result of converting N to a String value.
    6. +
    7. Let args be a list of ECMAScript values. +
      +
      E is DOMException
      +
      args is (undefined, N).
      +
      E is a simple exception
      +
      args is (M)
      +
      +
    8. Let G be the current global environment.
    9. -
    10. Let X be an object determined based on the type of E:
      E is DOMException
      @@ -14483,29 +14482,8 @@

      4.12. Creating and throwing exceptions

      from the global environment G.
    -
  • Let O be the result of calling X as a function with args as the argument list.
  • - -
  • If E is DOMException, then: -
      -
    1. Call the [[DefineOwnProperty]] internal method of O passing - “name”, Property Descriptor { [[Value]]: N, - [[Writable]]: true, [[Enumerable]]: true, - [[Configurable]]: true }, and false - as arguments.
    2. - -
    3. Let code be the legacy code indicated in the error names table - for error name N, or 0 if there is none.
    4. - -
    5. Call the [[DefineOwnProperty]] internal method of O passing - “code”, Property Descriptor { [[Value]]: code, - [[Writable]]: true, [[Enumerable]]: true, - [[Configurable]]: true }, and false - as arguments.
    6. -
    -
  • -
  • Return O.
  • diff --git a/index.xml b/index.xml index 148d6597..8403aacb 100644 --- a/index.xml +++ b/index.xml @@ -3618,7 +3618,7 @@ iterable<key-type, value-type>; can change during iteration, the behaviour of an iterator defined to to loop through the items in order, starting at index 0, and advancing this index on each iteration. Iteration ends when - the index has gone past the end of the list. + the index has gone past the end of the list.

    This is how array iterator objects work. @@ -4222,7 +4222,7 @@ ctx.drawRectangle(300, 200, { fillPattern: "red", position: new Point(10, 10) }) SyntaxError, which is deliberately omitted as it is for use only by the ECMAScript parser). The meaning of - each simple exception matches + each simple exception matches its corresponding Error object in the ECMAScript specification.

    @@ -14136,7 +14136,8 @@ C implements A; There MUST exist a property on the ECMAScript global object whose name is “DOMException” and value is an object called the DOMException constructor object, - which provides access to legacy DOMException code constants. + which provides access to legacy DOMException code constants and allows construction of + DOMException instances. The property has the attributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.

    @@ -14162,31 +14163,27 @@ C implements A;

    -
    DOMException constructor object [[Call]] method
    +
    DOMException(message, name)
    + +

    When the DOMException function is called with arguments message and name, the following steps are taken:

    -

    - The internal [[Call]] method of the - DOMException constructor object - MUST behave as follows, assuming - arg0..n−1 is the list - of argument values passed to the function: -

      -
    1. Let O be a new object whose [[Prototype]] - internal property is set to the DOMException prototype object - and whose class string is “DOMException”.
    2. -
    3. If n > 0 and arg0 is not undefined, then: +
    4. Let F be the active function object.
    5. +
    6. If NewTarget is undefined, let newTarget be F, else let newTarget be NewTarget.
    7. +
    8. Let super be F.[[GetPrototypeOf]]().
    9. +
    10. ReturnIfAbrupt(super).
    11. +
    12. If IsConstructor(super) is false, throw a TypeError exception.
    13. +
    14. Let O be Construct(super, «‍message», newTarget).
    15. +
    16. If name is not undefined, then
        -
      1. Let S be the result of calling ToString(arg0).
      2. -
      3. Call the [[DefineOwnProperty]] internal method of O passing - “message”, Property Descriptor { [[Value]]: S, - [[Writable]]: true, [[Enumerable]]: false, - [[Configurable]]: true }, and false - as arguments. -
        -

        This shadows the “message” property from Error.prototype, whose initial value is the empty string.

        -
      4. -
    17. +
    18. Let name be ToString(name).
    19. +
    20. Let status be DefinePropertyOrThrow(O, "name", PropertyDescriptor{[[Value]]: name, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}).
    21. +
    22. ReturnIfAbrupt(status).
    23. +
    24. Let code be the legacy code indicated in the error names table for error name name, or 0 if there is none.
    25. +
    26. Let status be DefinePropertyOrThrow(O, "code", PropertyDescriptor{[[Value]]: code, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}).
    27. +
    28. ReturnIfAbrupt(status).
    29. +
    +
  • Return O.
  • @@ -14319,15 +14316,17 @@ C implements A; the following steps MUST be followed:

      -
    1. Let args be a list of ECMAScript - values. If the optional user agent-defined message M was specified, then this list - has a single element whose value is the result of - converting - M to a String value. - Otherwise, the list is empty.
    2. - +
    3. If M was not specified, let M be undefined. Otherwise, let it be the result of converting M to a String value.
    4. +
    5. Let N be the result of converting N to a String value.
    6. +
    7. Let args be a list of ECMAScript values. +
      +
      E is DOMException
      +
      args is (undefined, N).
      +
      E is a simple exception
      +
      args is (M)
      +
      +
    8. Let G be the current global environment.
    9. -
    10. Let X be an object determined based on the type of E:
      E is DOMException
      @@ -14338,29 +14337,8 @@ C implements A; from the global environment G.
    11. -
    12. Let O be the result of calling X as a function with args as the argument list.
    13. - -
    14. If E is DOMException, then: -
        -
      1. Call the [[DefineOwnProperty]] internal method of O passing - “name”, Property Descriptor { [[Value]]: N, - [[Writable]]: true, [[Enumerable]]: true, - [[Configurable]]: true }, and false - as arguments.
      2. - -
      3. Let code be the legacy code indicated in the error names table - for error name N, or 0 if there is none.
      4. - -
      5. Call the [[DefineOwnProperty]] internal method of O passing - “code”, Property Descriptor { [[Value]]: code, - [[Writable]]: true, [[Enumerable]]: true, - [[Configurable]]: true }, and false - as arguments.
      6. -
      -
    15. -
    16. Return O.