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

Introduce a shorthand for ECMA262 abstract ops #539

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions infra.bs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ urlPrefix: https://tc39.github.io/ecma262/#; spec: ECMA-262;
type: dfn
text: %JSON.parse%; url: sec-json.parse
text: %JSON.stringify%; url: sec-json.stringify
text: Completion Record; url: sec-completion-record-specification-type
text: List; url: sec-list-and-record-specification-type
text: The String Type; url: sec-ecmascript-language-types-string-type
text: abrupt completion; url: sec-completion-record-specification-type
text: abstract operation; url: sec-algorithm-conventions-abstract-operations
text: realm; url: realm
type: method; for: Array; text: sort(); url: sec-array.prototype.sort
type: abstract-op;
Expand Down Expand Up @@ -644,6 +647,46 @@ Standard that should be reported and addressed.
</div>


<h3 id=ecma-262-abstract-operations>ECMA-262 Abstract Operations</h3>

jugglinmike marked this conversation as resolved.
Show resolved Hide resolved
<p>ECMA-262 defines some algorithms as [=abstract operations=] which may be invoked from algorithms
in other specifications. Some of these [=abstract operations=] return a type of value named
[=Completion Record=] which ECMA262 uses to model control flow interruptions such as thrown
exceptions. Because web specifications do not observe the same conventions (e.g.
<a href=#algorithm-control-flow>exception handling is built in to the processing model</a>),
preserving the operations' semantics necessarily involves handling [=Completion Records=].
[[!ECMA-262]]

<p>This specification defines a shorthand named <dfn export lt=throw-if-abrupt>?</dfn> as a
convenience for web specifications wishing to faithfully interpret ECMA-262 [=abstract operations=]
which return [=Completion Records=]. Algorithms which invoke such operations are encouraged to
integrate them concisely and consistently using this shorthand.

<p>Algorithm steps that say or are otherwise equivalent to:

<div class=example id=example-throw-if-abrupt>
<ol>
<li><p>Let |result| be <a lt=throw-if-abrupt>?</a> AbstractOperation().
</ol>
</div>

<p>mean the same thing as:

<div class=example id=example-throw-if-abrupt-expanded>
<ol>
<li><p>Let |hygienicTemp| be AbstractOperation().
<li><p><a>Assert</a>: |hygienicTemp| is a [=Completion Record=].
<li><p>If |hygienicTemp| is an [=abrupt completion=], throw |hygienicTemp|.\[[Value]].
<li><p>Let |result| be |hygienicTemp|.\[[Value]].
</ol>
</div>


<p class=XXX>This shorthand is intended to be suitable for use with any invocation, but the first
of the two preceding examples does not match all common calling conventions. See <a href=https://github.com/tc39/ecma262/pull/1573>tc39/ecma262 issue #1573</a>
for details.


<h2 id=primitive-data-types>Primitive data types</h2>

<h3 id=nulls>Nulls</h3>
Expand Down Expand Up @@ -1727,7 +1770,7 @@ specification. [[!ECMA-262]]
given a <a>string</a> |string|:

<ol>
<li><p>Return ? [$Call$](<a>%JSON.parse%</a>, undefined, « |string| »).
<li><p>Return <a lt=throw-if-abrupt>?</a> [$Call$](<a>%JSON.parse%</a>, undefined, « |string| »).
</ol>

<p>To <dfn export lt="parse JSON bytes to a JavaScript value|parsing JSON bytes to a JavaScript value|parse JSON from bytes">parse JSON bytes to a JavaScript value</dfn>,
Expand All @@ -1744,7 +1787,7 @@ given a JavaScript value |value|:

<ol>
<li>
<p>Let |result| be ? [$Call$](<a>%JSON.stringify%</a>, undefined, « |value| »).
<p>Let |result| be <a lt=throw-if-abrupt>?</a> [$Call$](<a>%JSON.stringify%</a>, undefined, « |value| »).

<p class=note>Since no additional arguments are passed to <a>%JSON.stringify%</a>, the resulting
string will have no whitespace inserted.
Expand Down Expand Up @@ -1781,7 +1824,7 @@ standards, it is often more convenient to convert between JSON and realm-indepen
given a <a>string</a> |string|:

<ol>
<li><p>Let |jsValue| be ? [$Call$](<a>%JSON.parse%</a>, undefined, « |string| »).
<li><p>Let |jsValue| be <a lt=throw-if-abrupt>?</a> [$Call$](<a>%JSON.parse%</a>, undefined, « |string| »).

<li><p>Return the result of [=converting a JSON-derived JavaScript value to an Infra value=], given
|jsValue|.
Expand Down