-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Normative: Extend JSON.parse and JSON.stringify for interaction with the source text of primitive values #3714
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
base: main
Are you sure you want to change the base?
Conversation
…the source text of primitive values
|
The rendered spec for this PR is available at https://tc39.es/ecma262/pr/3714. |
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). |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 1. Let _internalSlotsList_ be « [[IsRawJSON]] ». | ||
| 1. Let _obj_ be OrdinaryObjectCreate(*null*, _internalSlotsList_). |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…n with the source text of primitive values
…n with the source text of primitive values
…n with the source text of primitive values
This implements JSON.parse source text access, currently at stage 3. Tests have already been merged, but might still be extended.