Skip to content
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

Define serialization and deserialization steps for Error #4665

Merged
merged 18 commits into from
Jul 3, 2019
90 changes: 88 additions & 2 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -3021,8 +3021,15 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<dfn>@@toStringTag</dfn></li>
<li><dfn data-x-href="https://tc39.github.io/ecma262/#sec-well-known-intrinsic-objects">Well-Known Intrinsic Objects</dfn>, including
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-properties-of-the-array-prototype-object">%ArrayPrototype%</dfn>,
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-json.parse">%JSONParse%</dfn>, and
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-object.prototype.valueof">%ObjProto_valueOf%</dfn></li>
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-properties-of-the-error-prototype-object">%ErrorPrototype%</dfn>,
<dfn>%EvalErrorPrototype%</dfn>,
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-json.parse">%JSONParse%</dfn>,
<dfn data-x-href="https://tc39.github.io/ecma262/#sec-object.prototype.valueof">%ObjProto_valueOf%</dfn>,
<dfn>%RangeErrorPrototype%</dfn>,
<dfn>%ReferenceErrorPrototype%</dfn>,
<dfn>%SyntaxErrorPrototype%</dfn>,
<dfn>%TypeErrorPrototype%</dfn>, and
<dfn>%URIErrorPrototype%</dfn></li>
yutakahirano marked this conversation as resolved.
Show resolved Hide resolved

<li>The <dfn data-x="js-prod-FunctionBody" data-x-href="https://tc39.github.io/ecma262/#prod-FunctionBody"><i>FunctionBody</i></dfn> production</li>
<li>The <dfn data-x="js-prod-Module" data-x-href="https://tc39.github.io/ecma262/#prod-Module"><i>Module</i></dfn> production</li>
Expand Down Expand Up @@ -3077,6 +3084,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-ordinaryset">OrdinarySet</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-ordinarydelete">OrdinaryDelete</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-ordinaryownpropertykeys">OrdinaryOwnPropertyKeys</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-objectcreate">ObjectCreate</dfn> abstract operation</li>
yutakahirano marked this conversation as resolved.
Show resolved Hide resolved
<li>The <dfn data-x="js-ParseModule" data-x-href="https://tc39.github.io/ecma262/#sec-parsemodule">ParseModule</dfn> abstract operation</li>
<li>The <dfn data-x="js-ParseScript" data-x-href="https://tc39.github.io/ecma262/#sec-parse-script">ParseScript</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.github.io/ecma262/#sec-runjobs">RunJobs</dfn> abstract operation</li>
Expand Down Expand Up @@ -8371,6 +8379,45 @@ interface <dfn>DOMStringList</dfn> {
</ol>
</li>

<li>
<p>Otherwise, if <var>value</var> has an [[ErrorData]] internal slot and <var>value</var> is not
yutakahirano marked this conversation as resolved.
Show resolved Hide resolved
a <span>platform object</span>, then:</p>
domenic marked this conversation as resolved.
Show resolved Hide resolved

<ol>
<li><p>Let <var>prototype</var> be "Error".</p></li>

<li><p>Let <var>valueProto</var> be ! <var>value</var>.[[GetPrototypeOf]]().</p></li>
Copy link
Member

@domenic domenic May 29, 2019

Choose a reason for hiding this comment

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

Because of the preconditions, I am 95% sure this is equivalent to your version, which checked [[Prototype]] directly each time. It's just a bit nicer to go through the semi-public API of [[GetPrototypeOf]](), which will return [[Prototype]].


<li><p>If <var>valueProto</var> is <span>%EvalErrorPrototype%</span>, then set
<var>prototype</var> to "EvalError".</p></li>
domenic marked this conversation as resolved.
Show resolved Hide resolved

<li><p>If <var>valueProto</var> is <span>%RangeErrorPrototype%</span>, then set
<var>prototype</var> to "RangeError".</p></li>

<li><p>If <var>valueProto</var> is <span>%ReferenceErrorPrototype%</span>, then set
<var>prototype</var> to "ReferenceError".</p></li>

<li><p>If <var>valueProto</var> is <span>%SyntaxErrorPrototype%</span>, then set
<var>prototype</var> to "SyntaxError".</p></li>

<li><p>If <var>valueProto</var> is <span>%TypeErrorPrototype%</span>, then set
yutakahirano marked this conversation as resolved.
Show resolved Hide resolved
<var>prototype</var> to "TypeError".</p></li>

yutakahirano marked this conversation as resolved.
Show resolved Hide resolved
<li><p>If <var>valueProto</var> is <span>%URIErrorPrototype%</span>, then set
<var>prototype</var> to "URIError".</p></li>

yutakahirano marked this conversation as resolved.
Show resolved Hide resolved
<li><p>Let <var>valueMessageDesc</var> be ? <var>value</var>.[[GetOwnProperty]]("<code
data-x="">message</code>").</p></li>
domenic marked this conversation as resolved.
Show resolved Hide resolved

<li><p>Let <var>message</var> be undefined if
<span>IsDataDescriptor</span>(<var>valueMessageDesc</var>) is false, and
? <span>ToString</span>(<var>valueMessageDesc</var>.[[Value]]) otherwise.</p></li>

<li><p>Set <var>serialized</var> to { [[Type]]: "Error", [[Prototype]]: <var>prototype</var>,
[[Message]]: <var>message</var> }.</p></li>
</ol>
</li>

yutakahirano marked this conversation as resolved.
Show resolved Hide resolved
<li>
domenic marked this conversation as resolved.
Show resolved Hide resolved
<p>Otherwise, if <var>value</var> is an Array exotic object, then:</p>
<!-- IsArray supports proxies too, which we cannot -->
Expand Down Expand Up @@ -8780,6 +8827,45 @@ o.myself = o;</code></pre>
</ol>
</li>

<li>
<p>Otherwise, if <var>serialized</var>.[[Type]] is "Error", then:</p>

<ol>
<li><p>Let <var>prototype</var> be <span>%ErrorPrototype%</span>.</p></li>

<li><p>If <var>serialized</var>.[[Prototype]] is "EvalError", then set <var>prototype</var> to
<span>%EvalErrorPrototype%</span>.</p></li>

<li><p>If <var>serialized</var>.[[Prototype]] is "RangeError", then set <var>prototype</var>
to <span>%RangeErrorPrototype%</span>.</p></li>

<li><p>If <var>serialized</var>.[[Prototype]] is "ReferenceError", then set
<var>prototype</var> to <span>%ReferenceErrorPrototype%</span>.</p></li>

<li><p>If <var>serialized</var>.[[Prototype]] is "SyntaxError", then set <var>prototype</var>
to <span>%SyntaxErrorPrototype%</span>.</p></li>

<li><p>If <var>serialized</var>.[[Prototype]] is "TypeError", then set <var>prototype</var> to
<span>%TypeErrorPrototype%</span>.</p></li>

<li><p>If <var>serialized</var>.[[Prototype]] is "URIError", then set <var>prototype</var> to
<span>%URIErrorPrototype%</span>.</p></li>

<li><p>Let <var>message</var> be <var>serialized</var>.[[Message]].</p></li>

<li><p>Set <var>value</var> to ! <span>ObjectCreate</span>(<var>prototype</var>, «
[[ErrorData]] »).</p></li>

<li><p>Let <var>messageDesc</var> be <span>PropertyDescriptor</span>{ [[Value]]:
<var>message</var>, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true
}.</p></li>

<li><p>If <var>message</var> is not undefined, then perform !
<span>OrdinaryDefineOwnProperty</span>(<var>value</var>, "<code data-x="">message</code>",
<var>messageDesc</var>).</p></li>
</ol>
</li>

<li>
<p>Otherwise:</p>

Expand Down