|
2523 | 2523 | </ul></div><div id="menu-toggle"><svg xmlns="http://www.w3.org/2000/svg" style="width:100%; height:100%; stroke:currentColor" viewBox="0 0 120 120"> |
2524 | 2524 | <title>Menu</title> |
2525 | 2525 | <path stroke-width="10" stroke-linecap="round" d="M30,60 h60 M30,30 m0,5 h60 M30,90 m0,-5 h60"></path> |
2526 | | - </svg></div><div id="menu-spacer" class="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins</div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle">◢</span><a href="#sec-json-object" title="The JSON Object"><span class="secnum">1</span> The JSON Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-json.israwjson" title="JSON.isRawJSON ( O )"><span class="secnum">1.1</span> JSON.isRawJSON ( <var>O</var> )</a></li><li><span class="item-toggle">◢</span><a href="#sec-json.parse" title="JSON.parse ( text [ , reviver ] )"><span class="secnum">1.2</span> JSON.parse ( <var>text</var> [ , <var>reviver</var> ] )</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-json-parse-record" title="JSON Parse Record"><span class="secnum">1.2.1</span> JSON Parse Record</a></li><li><span class="item-toggle-none"></span><a href="#sec-createjsonparserecord" title="CreateJSONParseRecord ( parseNode, key, val )"><span class="secnum">1.2.2</span> CreateJSONParseRecord ( <var>parseNode</var>, <var>key</var>, <var>val</var> )</a></li><li><span class="item-toggle-none"></span><a href="#sec-internalizejsonproperty" title="InternalizeJSONProperty ( holder, name, reviver, parseRecord )"><span class="secnum">1.2.3</span> InternalizeJSONProperty ( <var>holder</var>, <var>name</var>, <var>reviver</var>, <ins><var>parseRecord</var></ins> )</a></li><li><span class="item-toggle-none"></span><a href="#sec-static-semantics-shallowestcontainedjsonvalue" title="Static Semantics: ShallowestContainedJSONValue"><span class="secnum">1.2.4</span> SS: ShallowestContainedJSONValue</a></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-json.rawjson" title="JSON.rawJSON ( text )"><span class="secnum">1.3</span> JSON.rawJSON ( <var>text</var> )</a></li><li><span class="item-toggle">◢</span><a href="#sec-json.stringify" title="JSON.stringify ( value [ , replacer [ , space ] ] )"><span class="secnum">1.4</span> JSON.stringify ( <var>value</var> [ , <var>replacer</var> [ , <var>space</var> ] ] )</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-serializejsonproperty" title="SerializeJSONProperty ( state, key, holder )"><span class="secnum">1.4.1</span> SerializeJSONProperty ( <var>state</var>, <var>key</var>, <var>holder</var> )</a></li></ol></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-static-semantics-arrayliteralcontentnodes" title="Static Semantics: ArrayLiteralContentNodes"><span class="secnum">2</span> SS: ArrayLiteralContentNodes</a></li><li><span class="item-toggle-none"></span><a href="#sec-static-semantics-propertydefinitionnodes" title="Static Semantics: PropertyDefinitionNodes"><span class="secnum">3</span> SS: PropertyDefinitionNodes</a></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright & Software License"><span class="secnum">A</span> Copyright & Software License</a></li></ol></div></div><div id="spec-container"><h1 class="shortname">Proposal <a href="<no location>"></a><a href="https://github.com/tc39/proposal-json-parse-with-source">proposal-json-parse-with-source</a></h1><h1 class="version">Stage 3 Draft / September 26, 2023</h1><h1 class="title">JSON.parse source text access</h1> |
| 2526 | + </svg></div><div id="menu-spacer" class="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins</div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle">◢</span><a href="#sec-json-object" title="The JSON Object"><span class="secnum">1</span> The JSON Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-json.israwjson" title="JSON.isRawJSON ( O )"><span class="secnum">1.1</span> JSON.isRawJSON ( <var>O</var> )</a></li><li><span class="item-toggle">◢</span><a href="#sec-json.parse" title="JSON.parse ( text [ , reviver ] )"><span class="secnum">1.2</span> JSON.parse ( <var>text</var> [ , <var>reviver</var> ] )</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-json-parse-record" title="JSON Parse Record"><span class="secnum">1.2.1</span> JSON Parse Record</a></li><li><span class="item-toggle-none"></span><a href="#sec-createjsonparserecord" title="CreateJSONParseRecord ( parseNode, key, val )"><span class="secnum">1.2.2</span> CreateJSONParseRecord ( <var>parseNode</var>, <var>key</var>, <var>val</var> )</a></li><li><span class="item-toggle-none"></span><a href="#sec-internalizejsonproperty" title="InternalizeJSONProperty ( holder, name, reviver, parseRecord )"><span class="secnum">1.2.3</span> InternalizeJSONProperty ( <var>holder</var>, <var>name</var>, <var>reviver</var>, <ins><var>parseRecord</var></ins> )</a></li><li><span class="item-toggle-none"></span><a href="#sec-static-semantics-shallowestcontainedjsonvalue" title="Static Semantics: ShallowestContainedJSONValue"><span class="secnum">1.2.4</span> SS: ShallowestContainedJSONValue</a></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-json.rawjson" title="JSON.rawJSON ( text )"><span class="secnum">1.3</span> JSON.rawJSON ( <var>text</var> )</a></li><li><span class="item-toggle">◢</span><a href="#sec-json.stringify" title="JSON.stringify ( value [ , replacer [ , space ] ] )"><span class="secnum">1.4</span> JSON.stringify ( <var>value</var> [ , <var>replacer</var> [ , <var>space</var> ] ] )</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-serializejsonproperty" title="SerializeJSONProperty ( state, key, holder )"><span class="secnum">1.4.1</span> SerializeJSONProperty ( <var>state</var>, <var>key</var>, <var>holder</var> )</a></li></ol></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-static-semantics-arrayliteralcontentnodes" title="Static Semantics: ArrayLiteralContentNodes"><span class="secnum">2</span> SS: ArrayLiteralContentNodes</a></li><li><span class="item-toggle-none"></span><a href="#sec-static-semantics-propertydefinitionnodes" title="Static Semantics: PropertyDefinitionNodes"><span class="secnum">3</span> SS: PropertyDefinitionNodes</a></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright & Software License"><span class="secnum">A</span> Copyright & Software License</a></li></ol></div></div><div id="spec-container"><h1 class="shortname">Proposal <a href="<no location>"></a><a href="https://github.com/tc39/proposal-json-parse-with-source">proposal-json-parse-with-source</a></h1><h1 class="version">Stage 3 Draft / November 7, 2025</h1><h1 class="title">JSON.parse source text access</h1> |
2527 | 2527 | <code title="work around https://github.com/tc39/ecmarkup/issues/510"><script> |
2528 | 2528 | // Initialize to a reasonable amount of TOC expansion: |
2529 | 2529 | // * Expand any full nesting level up to an arbitrary limit of 20 total visible items. |
@@ -2658,7 +2658,7 @@ <h1><span class="secnum">1.2.3</span> InternalizeJSONProperty ( <var>holder</var |
2658 | 2658 | <emu-clause id="sec-static-semantics-shallowestcontainedjsonvalue" type="sdo" aoid="ShallowestContainedJSONValue"> |
2659 | 2659 | <h1><span class="secnum">1.2.4</span> Static Semantics: ShallowestContainedJSONValue</h1> |
2660 | 2660 | <p>The <emu-xref href="#sec-algorithm-conventions-syntax-directed-operations"><a href="https://tc39.es/ecma262/#sec-algorithm-conventions-syntax-directed-operations">syntax-directed operation</a></emu-xref> ShallowestContainedJSONValue takes no arguments and returns a <emu-xref href="#sec-syntactic-grammar"><a href="https://tc39.es/ecma262/#sec-syntactic-grammar">Parse Node</a></emu-xref> or <emu-const>empty</emu-const>. It performs a breadth-first search of the parse tree rooted at the context node, and returns the first node that is an instance of a nonterminal corresponding to a JSON value, or <emu-const>empty</emu-const> if there is no such node.</p> |
2661 | | - <emu-alg><ol><li>Let <var>F</var> be the <emu-xref href="#active-function-object"><a href="https://tc39.es/ecma262/#active-function-object">active function object</a></emu-xref>.</li><li><emu-xref href="#assert"><a href="https://tc39.es/ecma262/#assert">Assert</a></emu-xref>: <var>F</var> is a <code>JSON.parse</code> built-in <emu-xref href="#function-object"><a href="https://tc39.es/ecma262/#function-object">function object</a></emu-xref> (see <emu-xref href="#sec-json.parse" id="_ref_3"><a href="#sec-json.parse">JSON.parse</a></emu-xref>).</li><li>Let <var>types</var> be « <emu-nt><a href="https://tc39.es/ecma262/#prod-NullLiteral">NullLiteral</a></emu-nt>, <emu-nt><a href="https://tc39.es/ecma262/#prod-BooleanLiteral">BooleanLiteral</a></emu-nt>, <emu-nt><a href="https://tc39.es/ecma262/#prod-NumericLiteral">NumericLiteral</a></emu-nt>, <emu-nt><a href="https://tc39.es/ecma262/#prod-StringLiteral">StringLiteral</a></emu-nt>, <emu-nt><a href="https://tc39.es/ecma262/#prod-ArrayLiteral">ArrayLiteral</a></emu-nt>, <emu-nt><a href="https://tc39.es/ecma262/#prod-ObjectLiteral">ObjectLiteral</a></emu-nt>, <emu-nt><a href="https://tc39.es/ecma262/#prod-UnaryExpression">UnaryExpression</a></emu-nt> ».</li><li>Let <var>unaryExpression</var> be <emu-const>empty</emu-const>.</li><li>Let <var>queue</var> be « this <emu-xref href="#sec-syntactic-grammar"><a href="https://tc39.es/ecma262/#sec-syntactic-grammar">Parse Node</a></emu-xref> ».</li><li>Repeat, while <var>queue</var> is not empty,<ol><li>Let <var>candidate</var> be the first element of <var>queue</var>.</li><li>Remove the first element from <var>queue</var>.</li><li>Let <var>queuedChildren</var> be <emu-val>false</emu-val>.</li><li>For each nonterminal <var>type</var> of <var>types</var>, do<ol><li>If <var>candidate</var> is an instance of <var>type</var>, then<ol><li>NOTE: In the JSON grammar, a <code>number</code> token may represent a negative value. In ECMAScript, negation is represented as a unary operation.</li><li>If <var>type</var> is <emu-nt><a href="https://tc39.es/ecma262/#prod-UnaryExpression">UnaryExpression</a></emu-nt>, then<ol><li>Set <var>unaryExpression</var> to <var>candidate</var>.</li></ol></li><li>Else if <var>type</var> is <emu-nt><a href="https://tc39.es/ecma262/#prod-NumericLiteral">NumericLiteral</a></emu-nt>, then<ol><li><emu-xref href="#assert"><a href="https://tc39.es/ecma262/#assert">Assert</a></emu-xref>: <var>unaryExpression</var> <emu-xref aoid="Contains"><a href="https://tc39.es/ecma262/#sec-static-semantics-contains">Contains</a></emu-xref> <var>candidate</var> is <emu-val>true</emu-val>.</li><li>Return <var>unaryExpression</var>.</li></ol></li><li>Else,<ol><li>Return <var>candidate</var>.</li></ol></li></ol></li><li>If <var>queuedChildren</var> is <emu-val>false</emu-val> and <var>candidate</var> is an instance of a nonterminal and <var>candidate</var> <emu-xref aoid="Contains"><a href="https://tc39.es/ecma262/#sec-static-semantics-contains">Contains</a></emu-xref> <var>type</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>children</var> be a <emu-xref href="#sec-list-and-record-specification-type"><a href="https://tc39.es/ecma262/#sec-list-and-record-specification-type">List</a></emu-xref> containing each child node of <var>candidate</var>, in order.</li><li>Set <var>queue</var> to the <emu-xref href="#list-concatenation"><a href="https://tc39.es/ecma262/#list-concatenation">list-concatenation</a></emu-xref> of <var>queue</var> and <var>children</var>.</li><li>Set <var>queuedChildren</var> to <emu-val>true</emu-val>.</li></ol></li></ol></li></ol></li><li>Return <emu-const>empty</emu-const>.</li></ol></emu-alg> |
| 2661 | + <emu-alg><ol><li>Let <var>F</var> be the <emu-xref href="#active-function-object"><a href="https://tc39.es/ecma262/#active-function-object">active function object</a></emu-xref>.</li><li><emu-xref href="#assert"><a href="https://tc39.es/ecma262/#assert">Assert</a></emu-xref>: <var>F</var> is a <code>JSON.parse</code> built-in <emu-xref href="#function-object"><a href="https://tc39.es/ecma262/#function-object">function object</a></emu-xref> (see <emu-xref href="#sec-json.parse" id="_ref_3"><a href="#sec-json.parse">JSON.parse</a></emu-xref>).</li><li>Let <var>types</var> be « <emu-nt><a href="https://tc39.es/ecma262/#prod-NullLiteral">NullLiteral</a></emu-nt>, <emu-nt><a href="https://tc39.es/ecma262/#prod-BooleanLiteral">BooleanLiteral</a></emu-nt>, <emu-nt><a href="https://tc39.es/ecma262/#prod-NumericLiteral">NumericLiteral</a></emu-nt>, <emu-nt><a href="https://tc39.es/ecma262/#prod-StringLiteral">StringLiteral</a></emu-nt>, <emu-nt><a href="https://tc39.es/ecma262/#prod-ArrayLiteral">ArrayLiteral</a></emu-nt>, <emu-nt><a href="https://tc39.es/ecma262/#prod-ObjectLiteral">ObjectLiteral</a></emu-nt>, <emu-nt><a href="https://tc39.es/ecma262/#prod-UnaryExpression">UnaryExpression</a></emu-nt> ».</li><li>Let <var>unaryExpression</var> be <emu-const>empty</emu-const>.</li><li>Let <var>queue</var> be « this <emu-xref href="#sec-syntactic-grammar"><a href="https://tc39.es/ecma262/#sec-syntactic-grammar">Parse Node</a></emu-xref> ».</li><li>Repeat, while <var>queue</var> is not empty,<ol><li>Let <var>candidate</var> be the first element of <var>queue</var>.</li><li>Remove the first element from <var>queue</var>.</li><li>Let <var>queuedChildren</var> be <emu-val>false</emu-val>.</li><li>For each nonterminal <var>type</var> of <var>types</var>, do<ol><li>If <var>candidate</var> is an instance of <var>type</var>, then<ol><li>NOTE: In the JSON grammar, a <code>number</code> token may represent a negative value. In ECMAScript, negation is represented as a unary operation.</li><li>If <var>type</var> is <emu-nt><a href="https://tc39.es/ecma262/#prod-UnaryExpression">UnaryExpression</a></emu-nt>, then<ol><li>Set <var>unaryExpression</var> to <var>candidate</var>.</li></ol></li><li>Else if <var>type</var> is <emu-nt><a href="https://tc39.es/ecma262/#prod-NumericLiteral">NumericLiteral</a></emu-nt>, then<ol><li><emu-xref href="#assert"><a href="https://tc39.es/ecma262/#assert">Assert</a></emu-xref>: <var>candidate</var> is contained within <var>unaryExpression</var>.</li><li>Return <var>unaryExpression</var>.</li></ol></li><li>Else,<ol><li>Return <var>candidate</var>.</li></ol></li></ol></li><li>If <var>queuedChildren</var> is <emu-val>false</emu-val> and <var>candidate</var> is an instance of a nonterminal and <var>candidate</var> <emu-xref aoid="Contains"><a href="https://tc39.es/ecma262/#sec-static-semantics-contains">Contains</a></emu-xref> <var>type</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>children</var> be a <emu-xref href="#sec-list-and-record-specification-type"><a href="https://tc39.es/ecma262/#sec-list-and-record-specification-type">List</a></emu-xref> containing each child node of <var>candidate</var>, in order.</li><li>Set <var>queue</var> to the <emu-xref href="#list-concatenation"><a href="https://tc39.es/ecma262/#list-concatenation">list-concatenation</a></emu-xref> of <var>queue</var> and <var>children</var>.</li><li>Set <var>queuedChildren</var> to <emu-val>true</emu-val>.</li></ol></li></ol></li></ol></li><li>Return <emu-const>empty</emu-const>.</li></ol></emu-alg> |
2662 | 2662 | <emu-note type="editor"><span class="note">Editor's Note</span><div class="note-contents"> |
2663 | 2663 | <p> |
2664 | 2664 | It may make sense to generalize this operation and define <emu-xref aoid="Contains"><a href="https://tc39.es/ecma262/#sec-static-semantics-contains">Contains</a></emu-xref> in terms of it rather than vice versa, but <emu-xref aoid="Contains"><a href="https://tc39.es/ecma262/#sec-static-semantics-contains">Contains</a></emu-xref> is currently limited to a single target nonterminal and has specialized treatment for e.g. <emu-nt><a href="https://tc39.es/ecma262/#prod-ClassTail">ClassTail</a></emu-nt> descending into <emu-nt><a href="https://tc39.es/ecma262/#prod-ClassBody">ClassBody</a></emu-nt> exclusively to inspect computed names. |
@@ -2790,7 +2790,7 @@ <h1><span class="secnum">3</span> Static Semantics: PropertyDefinitionNodes</h1> |
2790 | 2790 | <h1><span class="secnum">A</span> Copyright & Software License</h1> |
2791 | 2791 | |
2792 | 2792 | <h2>Copyright Notice</h2> |
2793 | | - <p>© 2023 Richard Gibson</p> |
| 2793 | + <p>© 2025 Richard Gibson</p> |
2794 | 2794 |
|
2795 | 2795 | <h2>Software License</h2> |
2796 | 2796 | <p>All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.</p> |
|
0 commit comments