Skip to content

Commit b652575

Browse files
committed
fix(logs): read boxed boolean and bigint values the way JSON.stringify does
1 parent 12abe8c commit b652575

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎apps/sim/lib/logs/execution/json-byte-size.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ describe('getJsonByteSize', () => {
2929
['holes in a sparse array', { list: [1, undefined, 3, undefined, undefined] }],
3030
['an omitted member before the first written one', { skipped: undefined, kept: 1 }],
3131
['boxed primitives', { n: new Number(12345), s: new String('boxed'), b: new Boolean(false) }],
32+
[
33+
'a boxed boolean whose valueOf is overridden',
34+
{
35+
b: Object.assign(new Boolean(true), {
36+
valueOf: () => {
37+
throw new Error('JSON.stringify reads the internal value, not valueOf')
38+
},
39+
}),
40+
},
41+
],
3242
['a function with toJSON', { fn: Object.assign(() => 1, { toJSON: () => 'serialized' }) }],
3343
['escapes, multi-byte text, and lone surrogates', { 'k"\\': 'a\n\u0001é漢😀\ud800' }],
3444
])('matches JSON.stringify for %s', (_name, payload) => {

‎apps/sim/lib/logs/execution/json-byte-size.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export function getJsonByteSize(value: unknown, maxBytes: number): number | unde
3737
const value = typeof toJSON === 'function' ? toJSON.call(raw, key) : raw
3838
if (value instanceof Number) return Number(value)
3939
if (value instanceof String) return String(value)
40-
if (value instanceof Boolean || value instanceof BigInt) return value.valueOf()
40+
if (value instanceof Boolean) return Boolean.prototype.valueOf.call(value)
41+
if (value instanceof BigInt) return BigInt.prototype.valueOf.call(value)
4142
return value
4243
}
4344

0 commit comments

Comments
 (0)