Skip to content

Commit 704b615

Browse files
committed
feat(module): add QuickJS extended JSON modules
1 parent 5782f57 commit 704b615

8 files changed

Lines changed: 655 additions & 55 deletions

File tree

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ module-host callbacks can synchronously compile and return same-Context
1414
modules, including nested loader re-entry protected by a finite host-stack
1515
budget. Parse-in-progress module identities and source-order request prefixes
1616
are visible to those callbacks in QuickJS order, with unsafe failed identities
17-
represented deterministically. JSON5/byte-oriented loading and the remaining
18-
conformance gaps are still parity work.
17+
represented deterministically. QuickJS extended-JSON text modules are
18+
supported; byte-oriented loading and the remaining conformance gaps are still
19+
parity work.
1920

2021
<!-- current-test262-metrics:start -->
2122
The authoritative R3eu Test262 baseline records **79,475 full-corpus passes
@@ -45,6 +46,10 @@ cargo run --quiet --bin qjs -- --print-result -e \
4546
cargo run --quiet --bin qjs -- examples/module-42.mjs # 42
4647
```
4748

49+
The file loader follows QuickJS policy: `.json` is strict JSON,
50+
`type: "json5"` selects QuickJS extended JSON for any suffix, and a `.json5`
51+
file without that attribute remains a JavaScript module.
52+
4853
## Status
4954

5055
- [Current implementation status](docs/status.md)

docs/status.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ The exact profile, inputs, summary, line counts, and report hashes live in
3838
QuickJS-matched early errors
3939
- static-module graphs, live namespaces, default exports, top-level await with
4040
async dependency/SCC scheduling, static import attributes with loader
41-
validation, JSON synthetic modules, and canonical host-populated
42-
`import.meta` objects
41+
validation, strict and QuickJS-extended JSON synthetic modules, and
42+
canonical host-populated `import.meta` objects
4343
- Script-goal dynamic `import()` with FIFO load/finish jobs, live host-loader
4444
callback sampling, import attributes, cached cycle-root evaluation Promises,
4545
namespace reuse, Promise assimilation, and exact propagation of arbitrary
@@ -64,9 +64,10 @@ host is isolated behind a non-default feature.
6464

6565
## Remaining parity work
6666

67-
Major open frontiers include JSON5/byte-oriented host loading, remaining
68-
module-host lifetime and allocation-failure edge matrices, and the
69-
unsupported/failed leaves recorded by the current Test262 vector. Failed
67+
Major open frontiers include raw-byte module payloads such as malformed UTF-8
68+
and WTF-8, remaining module-host lifetime and allocation-failure edge matrices,
69+
and the unsupported/failed leaves recorded by the current Test262 vector.
70+
Failed
7071
acyclic source graphs retry like QuickJS. Parse-time resolution success and
7172
one-shot failure latches match the pinned callback order; an incomplete graph
7273
is non-executable and dynamic import rejects deterministically. Rust safely

src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ impl ModuleLoader for FileModuleLoader {
6161
.map_err(|_| ModuleLoaderError::new("module filename is not valid Unicode"))?;
6262
let source = std::fs::read_to_string(&filename)
6363
.map_err(|_| ModuleLoaderError::new(format!("module filename '{filename}'")))?;
64+
if import_type_is(attributes, "json5") {
65+
return Ok(ModuleLoadResult::Json5Text(source));
66+
}
6467
if filename.ends_with(".json") || import_type_is(attributes, "json") {
6568
return Ok(ModuleLoadResult::JsonText(source));
6669
}

0 commit comments

Comments
 (0)