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

Add warning for Infra to JSON-JS-value algorithm #646

Merged
merged 3 commits into from
Nov 14, 2024
Merged
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
65 changes: 43 additions & 22 deletions infra.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1841,24 +1841,28 @@ without breaking literal syntax used by their dependencies. In that case a tuple
<p class=note>The conventions used in the algorithms in this section are those of the JavaScript
specification. [[!ECMA-262]]

<p>To <dfn export lt="parse a JSON string to a JavaScript value|parsing a JSON string to a JavaScript value">parse a JSON string to a JavaScript value</dfn>,
given a <a>string</a> |string|:
<div algorithm>
<p>To <dfn export>parse a JSON string to a JavaScript value</dfn>, given a <a>string</a> |string|:

<ol>
<li><p>Return ? [$Call$](<a>%JSON.parse%</a>, undefined, « |string| »).
</ol>
</div>

<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>,
given a <a>byte sequence</a> |bytes|:
<div algorithm>
<p>To <dfn export>parse JSON bytes to a JavaScript value</dfn>, given a <a>byte sequence</a>
|bytes|:

<ol>
<li><p>Let |string| be the result of running <a>UTF-8 decode</a> on |bytes|. [[!ENCODING]]

<li><p>Return the result of <a>parsing a JSON string to a JavaScript value</a> given |string|.
</ol>
</div>

<p>To <dfn export lt="serialize a JavaScript value to a JSON string|serializing a JavaScript value to a JSON string">serialize a JavaScript value to a JSON string</dfn>,
given a JavaScript value |value|:
<div algorithm>
<p>To <dfn export>serialize a JavaScript value to a JSON string</dfn>, given a JavaScript value
|value|:

<ol>
<li>
Expand All @@ -1877,16 +1881,19 @@ given a JavaScript value |value|:

<li><p>Return |result|.
</ol>
</div>

<p>To <dfn export lt="serialize a JavaScript value to JSON bytes|serializing a JavaScript value to JSON bytes|serialize JSON to bytes">serialize a JavaScript value to JSON bytes</dfn>,
given a JavaScript value |value|:
<div algorithm>
<p>To <dfn export>serialize a JavaScript value to JSON bytes</dfn>, given a JavaScript value
|value|:

<ol>
<li><p>Let |string| be the result of <a>serializing a JavaScript value to a JSON string</a> given
|value|.

<li><p>Return the result of running <a>UTF-8 encode</a> on |string|. [[!ENCODING]]
</ol>
</div>

<hr>

Expand All @@ -1895,7 +1902,9 @@ the involved objects or arrays are tied to a particular <a lt="realm">JavaScript
standards, it is often more convenient to convert between JSON and realm-independent <a>maps</a>,
<a>lists</a>, <a>strings</a>, <a>booleans</a>, numbers, and nulls.

<p>To <dfn export lt="parse a JSON string to an Infra value|parsing a JSON string to an Infra value|parse JSON into Infra values">parse a JSON string to an Infra value</dfn>,
<div algorithm>
<p>To
<dfn export lt="parse a JSON string to an Infra value|parse JSON into Infra values">parse a JSON string to an Infra value</dfn>,
given a <a>string</a> |string|:

<ol>
Expand All @@ -1904,18 +1913,21 @@ given a <a>string</a> |string|:
<li><p>Return the result of [=converting a JSON-derived JavaScript value to an Infra value=], given
|jsValue|.
</ol>
</div>

<p>To <dfn export lt="parse JSON bytes to an Infra value|parsing JSON bytes to an Infra value">parse JSON bytes to an Infra value</dfn>,
given a <a>byte sequence</a> |bytes|:
<div algorithm>
<p>To <dfn export>parse JSON bytes to an Infra value</dfn>, given a <a>byte sequence</a> |bytes|:

<ol>
<li><p>Let |string| be the result of running <a>UTF-8 decode</a> on |bytes|. [[!ENCODING]]

<li><p>Return the result of <a>parsing a JSON string to an Infra value</a> given |string|.
</ol>
</div>

<p>To <dfn lt="convert a JSON-derived JavaScript value to an Infra value|converting a JSON-derived JavaScript value to an Infra value">convert a JSON-derived JavaScript value to an Infra value</dfn>,
given a JavaScript value |jsValue|:
<div algorithm>
<p>To <dfn>convert a JSON-derived JavaScript value to an Infra value</dfn>, given a JavaScript value
|jsValue|:

<ol>
<li><p>If |jsValue| is <emu-val>null</emu-val>, |jsValue| [=is a Boolean=], |jsValue|
Expand Down Expand Up @@ -1965,10 +1977,11 @@ given a JavaScript value |jsValue|:

<li><p>Return |result|.
</ol>
</div>

<p>To <dfn export lt="serialize an Infra value to a JSON string|serializing an Infra value to a JSON string">serialize an Infra value to a JSON string</dfn>,
given a <a>string</a>, <a>boolean</a>, number, null, <a>list</a>, or <a>string</a>-keyed <a>map</a>
|value|:
<div algorithm>
<p>To <dfn export>serialize an Infra value to a JSON string</dfn>, given a <a>string</a>,
<a>boolean</a>, number, null, <a>list</a>, or <a>string</a>-keyed <a>map</a> |value|:

<ol>
<li><p>Let |jsValue| be the result of
Expand All @@ -1980,21 +1993,22 @@ given a <a>string</a>, <a>boolean</a>, number, null, <a>list</a>, or <a>string</
<p class=note>Since no additional arguments are passed to <a>%JSON.stringify%</a>, the resulting
string will have no whitespace inserted.
</ol>
</div>

<p>To <dfn export lt="serialize an Infra value to JSON bytes|serializing an Infra value to JSON bytes">serialize an Infra value to JSON bytes</dfn>,
given a <a>string</a>, <a>boolean</a>, number, null, <a>list</a>, or <a>string</a>-keyed <a>map</a>
|value|:
<div algorithm>
<p>To <dfn export>serialize an Infra value to JSON bytes</dfn>, given a <a>string</a>,
<a>boolean</a>, number, null, <a>list</a>, or <a>string</a>-keyed <a>map</a> |value|:

<ol>
<li><p>Let |string| be the result of <a>serializing an Infra value to a JSON string</a>, given
|value|.

<li><p>Return the result of running <a>UTF-8 encode</a> on |string|. [[!ENCODING]]
</ol>
</div>

<p>To
<dfn export lt="convert an Infra value to a JSON-compatible JavaScript value|converting an Infra value to a JSON-compatible JavaScript value">convert an Infra value to a JSON-compatible JavaScript value</dfn>,
given |value|:
<div algorithm>
<p>To <dfn export>convert an Infra value to a JSON-compatible JavaScript value</dfn>, given |value|:

<ol>
<li><p>If |value| is a <a>string</a>, <a>boolean</a>, number, or null, then return |value|.
Expand Down Expand Up @@ -2043,6 +2057,13 @@ given |value|:
</ol>
</ol>

<p class=warning>Because it is rarely appropriate to manipulate JavaScript values directly in
specifications, prefer using <a>serialize an Infra value to a JSON string</a> or
<a>serialize an Infra value to JSON bytes</a> instead of using this algorithm. Please
<a href="https://github.com/whatwg/infra/issues/new">file an issue</a> to discuss your use case if
you believe you need to use <a>convert an Infra value to a JSON-compatible JavaScript value</a>.
</div>
annevk marked this conversation as resolved.
Show resolved Hide resolved


<h2 id=forgiving-base64>Forgiving base64</h2>

Expand Down
Loading