Commit b3d8203
feat(json): Implement json-parse-with-source proposal (ES2026) (boa-dev#4873)
Related: https://github.com/tc39/proposal-json-parse-with-source
It changes the following:
- Implement `JSON.rawJSON(text)`: creates frozen raw JSON objects with
`[[IsRawJSON]]` internal slot and a `rawJSON` property. Validates input
is a valid JSON primitive (not object/array), rejects empty and
whitespace-padded strings.
- Implement `JSON.isRawJSON(value)`: checks for the `[[IsRawJSON]]`
internal slot.
- Update `JSON.stringify` to serialize raw JSON objects by outputting
their `rawJSON` property value directly.
- Implement `JSON.parse` reviver `context.source`: the reviver function
now receives a third `context` argument. For primitive JSON values,
`context` contains a
[source](cci:1://file:///d:/boa/core/engine/src/builtins/json/mod.rs:188:0-193:1)
property with the original source text (e.g., `"1.1e1"` instead of
`"11"`). For objects/arrays, `context` is an empty object. A
value-matching guard ensures
[source](cci:1://file:///d:/boa/core/engine/src/builtins/json/mod.rs:188:0-193:1)
is omitted when the reviver forward-modifies values during iteration.
- Add a `JsonNode` source tree builder that parses JSON to extract
byte-accurate source text spans for all primitive values.
- Remove `"json-parse-with-source"` from ignored features in
[test262_config.toml](cci:7://file:///d:/boa/test262_config.toml:0:0-0:0).
**Test262 Results: 165/165 (100% conformance)**
| Suite | Pass | Total |
|-------|------|-------|
| `JSON.parse` | 77 | 77 |
| `JSON.stringify` | 66 | 66 |
| `JSON.rawJSON` | 10 | 10 |
| `JSON.isRawJSON` | 6 | 6 |
---------
Co-authored-by: Elior Nguyen <anhtunguyendev@wavenet.com.tw>1 parent 6bd8334 commit b3d8203
File tree
4 files changed
+397
-35
lines changed- core
- ast/src/expression/literal
- engine/src/builtins/json
- parser/src/parser/expression/primary
4 files changed
+397
-35
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
54 | 71 | | |
55 | 72 | | |
56 | 73 | | |
| |||
68 | 85 | | |
69 | 86 | | |
70 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
71 | 95 | | |
72 | 96 | | |
73 | 97 | | |
| |||
0 commit comments