Commit 5e4f275
authored
refactor(javascript): move serialization runtime state into contexts (#3549)
## Why?
- Align the JavaScript runtime ownership model with context-based
operation state instead of ambient `Fory` state.
- Remove internal `Fory` retention from serializers and codegen while
preserving the existing wire format and early-bound closure performance
model.
## What does this PR do?
- Introduces reusable `WriteContext` and `ReadContext` objects and moves
binary reader/writer, ref tracking, meta string handling, and type-meta
state under those contexts.
- Keeps `Fory` as the top-level facade, renames
`registerSerializer(...)` to `register(...)`, removes
`serializeVolatile(...)`, and exports `WriteContext` / `ReadContext` for
custom serializers.
- Refactors `TypeResolver`, `TypeInfo`, codegen, and generated
serializers to stop retaining `Fory` and instead bind hot
reader/writer/resolver locals from resolver-rooted reusable contexts.
- Splits legacy `ReferenceResolver` / `MetaStringResolver` into
directional helpers and folds `TypeMetaResolver` logic into the new
contexts.
- Updates JavaScript docs, benchmark scripts, and tests to the new
context-first custom serializer API without changing serialization
behavior or wire format.
- Normalizes the new JavaScript context/codegen files to satisfy the
repository code style checks.
## Related issues
- None.
## AI Contribution Checklist
- [ ] Substantial AI assistance was used in this PR: `yes` / `no`
- [ ] If `yes`, I included a completed [AI Contribution
Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs)
in this PR description and the required `AI Usage Disclosure`.
- [ ] If `yes`, my PR description includes the required `ai_review`
summary and screenshot evidence of the final clean AI review results
from both fresh reviewers on the current PR diff or current HEAD after
the latest code changes.
## Does this PR introduce any user-facing change?
- [x] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
JavaScript public API changes include `fory.register(...)`, removal of
`serializeVolatile(...)`, and context-first custom serializer
signatures.
## Benchmark
Preserves the existing early-bound closure strategy for generated
serializers; no wire-format change is intended.1 parent a3095c4 commit 5e4f275
38 files changed
Lines changed: 1342 additions & 1122 deletions
File tree
- javascript
- benchmark
- packages/core
- lib
- gen
- meta
- test
- protocol
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
| 231 | + | |
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
| 43 | + | |
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
0 commit comments