Re: [whatwg/webidl] Allow DOMException subclasses to be used as exceptions (PR #1211)

@kainino0x commented on this pull request.



> +    the additional information that needs to be exposed.
+*   They should have [=read only=] [=attributes=], whose names are the same as the members of the
+    constructor dictionary, which return the values accepted by the constructor operation.
+*   They should be [=serializable objects=], whose [=serialization steps=] and
+    [=deserialization steps=] preserve the additional information.
+
+<p class=note>These requirements mean that the inherited {{DOMException/code}} property of these
+interfaces will always return 0.
+
+<div class=example id=example-domexception-derived-interface>
+    The definition for a {{DOMException}} derived interface which carries along an additional
+    "protocol error code", which is derived from what the server sent over some some hypothetical
+    network protocol "protocol X", could look something like this:
+
+    <pre highlight=webidl>
+        [Exposed=Window]

Should be marked `[Serializable]`?

> +    constructor dictionary, which return the values accepted by the constructor operation.
+*   They should be [=serializable objects=], whose [=serialization steps=] and
+    [=deserialization steps=] preserve the additional information.
+
+<p class=note>These requirements mean that the inherited {{DOMException/code}} property of these
+interfaces will always return 0.
+
+<div class=example id=example-domexception-derived-interface>
+    The definition for a {{DOMException}} derived interface which carries along an additional
+    "protocol error code", which is derived from what the server sent over some some hypothetical
+    network protocol "protocol X", could look something like this:
+
+    <pre highlight=webidl>
+        [Exposed=Window]
+        interface ProtocolXError : DOMException {
+          constructor(optional DOMString message = "", ProtocolXErrorOptions options);

`Required argument "options" cannot follow optional argument "message"`

> +          readonly attribute unsigned long long errorCode;
+        };
+
+        dictionary ProtocolXErrorOptions {
+            required [EnforceRange] unsigned long long errorCode;
+        };
+    </pre>
+
+    Every <code>ProtocolXError</code> instance has an <dfn for="ProtocolXError">error code</dfn>,
+    a number.
+
+    <div algorithm="ProtocolXError constructor">
+        The <b><code>new ProtocolXError(|message|, |options|)</code></b> constructor steps are:
+
+        1.  Set [=this=]'s [=DOMException/name=] to "<code>ProtocolXError</code>".
+        1.  Set [=this=]'s [=DOMException/message=] to |message|.

Could this call the "super" constructor of DOMException instead?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/pull/1211#pullrequestreview-1190903257
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/pull/1211/review/1190903257@github.com>

Received on Wednesday, 23 November 2022 00:00:49 UTC