mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
The reference's native stringify throws past depth 32 and its internal walk, with a replacer or a property list, past 100, a primitive included: RangeError "Value exceeds the maximum depth of N.". Rust allowed 512. Recorded in the std-json-stringify-depth case and a busy loop of failing walks.
28 lines
981 B
JavaScript
28 lines
981 B
JavaScript
const nest = (n, v, wrap) => {
|
|
let o = v
|
|
for (let i = 0; i < n; i++) o = wrap(o)
|
|
return o
|
|
}
|
|
const t = (f) => {
|
|
try {
|
|
return f()
|
|
} catch (e) {
|
|
return [e.name, e.message]
|
|
}
|
|
}
|
|
const obj = (o) => ({ o })
|
|
const arr = (o) => [o]
|
|
return [
|
|
t(() => JSON.stringify(nest(32, 1, obj)).length),
|
|
t(() => JSON.stringify(nest(33, 1, obj)).length),
|
|
t(() => JSON.stringify(nest(32, {}, obj)).length),
|
|
t(() => JSON.stringify(nest(33, {}, obj)).length),
|
|
t(() => JSON.stringify(nest(32, 1, arr)).length),
|
|
t(() => JSON.stringify(nest(33, 1, arr)).length),
|
|
t(() => JSON.stringify(nest(33, undefined, obj)).length),
|
|
t(() => JSON.stringify(nest(100, 1, obj), (k, v) => v).length),
|
|
t(() => JSON.stringify(nest(101, 1, obj), (k, v) => v).length),
|
|
t(() => JSON.stringify(nest(40, 1, obj), null, 1).length),
|
|
t(() => JSON.stringify(nest(40, { toJSON: () => 1 }, obj)).length),
|
|
t(() => JSON.stringify([nest(20, { toJSON: () => 1 }, obj), nest(40, 1, obj)]).length),
|
|
]
|