fix(code-runtime): accept deeply nested JSON

This commit is contained in:
Tianyi Cui
2026-07-22 02:13:37 +08:00
parent 3f93d4ddbd
commit f2d86b232e
7 changed files with 119 additions and 44 deletions

View File

@@ -64,6 +64,18 @@ describe('snapshotCodeJsonValue', () => {
expect(snapshot[0]?.['__proto__']).toEqual({ safe: true })
})
it('accepts deeply nested valid JSON without using the JavaScript call stack', () => {
let value: unknown = 'leaf'
for (let depth = 0; depth < 5_000; depth++) value = [value]
let cursor = snapshotCodeJsonValue(value)
for (let depth = 0; depth < 5_000; depth++) {
expect(Array.isArray(cursor)).toBe(true)
cursor = Array.isArray(cursor) ? cursor[0] : undefined
}
expect(cursor).toBe('leaf')
})
it('rejects exotic containers, sparse arrays, cycles, and invalid children', () => {
class ExoticObject {
readonly value = 1