Skip to content

Conversation

@gibson042
Copy link
Member

This implements JSON.parse source text access, currently at stage 3. Tests have already been merged, but might still be extended.

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

The rendered spec for this PR is available at https://tc39.es/ecma262/pr/3714.

@ljharb ljharb added normative change Affects behavior required to correctly evaluate some ECMAScript source text pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. proposal This is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4. labels Nov 8, 2025
spec.html Outdated
<p>The `rawJSON` function returns an object representing raw JSON text of a string, number, boolean, or null value.</p>
<emu-alg>
1. Let _jsonString_ be ? ToString(_text_).
1. Throw a *SyntaxError* exception if _jsonString_ is the empty String, or if either the first or last code unit of _jsonString_ is any of 0x0009 (CHARACTER TABULATION), 0x000A (LINE FEED), 0x000D (CARRIAGE RETURN), or 0x0020 (SPACE).
Copy link
Member

Choose a reason for hiding this comment

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

I noticed that we never use in algorithms the structure "Throw a exception if ", it's usually "If , throw a exception."

Copy link
Member

Choose a reason for hiding this comment

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

We did prior to #3540, when this text was originally written, but yeah we've done away with that now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed, and added tighter assertions.

Comment on lines 47301 to 47302
1. Let _internalSlotsList_ be « [[IsRawJSON]] ».
1. Let _obj_ be OrdinaryObjectCreate(*null*, _internalSlotsList_).
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for not inlining _internalSlotsList_, like we do in most OrdinaryObjectCreate calls where we pass extra slots?

Copy link
Member Author

Choose a reason for hiding this comment

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

We've got examples of both, and I personally like having the name as an explicit hint of semantics for an otherwise opaque list of slot references, but am willing to inline it if that's the consensus preference among editors.

spec.html Outdated
1. Else,
1. Assert: _typedValNode_ is an |ObjectLiteral| Parse Node.
1. Let _propertyNodes_ be PropertyDefinitionNodes of _typedValNode_.
1. NOTE: Because _val_ was produced from JSON text and has not been modified, all of its property keys are Strings and will be exhaustively enumerated in source text order.
Copy link
Member

Choose a reason for hiding this comment

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

Is this true? In Object.keys({ "a": 1, "0": 2 }) they are not enumerated in source text order.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch! I removed the "in source text order" part of the note, which isn't important anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

normative change Affects behavior required to correctly evaluate some ECMAScript source text pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. proposal This is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants