3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-12 11:48:29 +01:00

Answer stability round 1: the docs name V8's array limit in one text node, a test pins Invalid array length, and item 106 takes the readers' RangeError and JavaScriptCore's Out of memory

This commit is contained in:
2026-10-11 20:51:21 +02:00
committed by Lillem4n
parent edacef410f
commit 80b4e0a9b7
7 changed files with 29 additions and 13 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ test('refuses a document whose markdown runs past the engine\'s longest string',
let value: JsonValue = new Array<JsonValue>(2_200_000).fill(0)
for (let level = 0; level < 495; level += 1) value = [value]
const result = adfToLosslessMarkdown(document({ attrs: { value }, type: 'unknownBlock' }))
assert.match(markdown(result), /^unsupported-node-shape: the output runs past what this JavaScript engine holds: /)
assert.match(markdown(result), /^unsupported-node-shape: the output would be longer than the longest string or array this JavaScript engine builds \(/)
assert.deepEqual(path(result), [])
})
+14 -2
View File
@@ -4,7 +4,11 @@ import { fileURLToPath } from 'node:url'
import { readFileSync, readdirSync } from 'node:fs'
import test from 'node:test'
import { success, withinEngineLimits } from './result.ts'
import { success, withinEngineLimits, type Result } from './result.ts'
function code(result: Result<string>): string {
return result.ok ? `converted ${result.value}` : result.error.code
}
const sourceRoot = dirname(fileURLToPath(import.meta.url))
const union = /export type ConvertErrorCode =\n((?:\s+\| '[a-z-]+'\n)+)/
@@ -39,7 +43,15 @@ test('refuses where SpiderMonkey runs out of string, and lets a stack overflow o
withinEngineLimits(() => {
throw overflow
}),
{ error: { code: 'unsupported-node-shape', message: 'the output runs past what this JavaScript engine holds: allocation size overflow', path: [] }, ok: false },
{ error: { code: 'unsupported-node-shape', message: 'the output would be longer than the longest string or array this JavaScript engine builds (allocation size overflow)', path: [] }, ok: false },
)
assert.equal(
code(
withinEngineLimits(() => {
throw new RangeError('Invalid array length')
}),
),
'unsupported-node-shape',
)
assert.throws(() =>
withinEngineLimits(() => {
+1 -1
View File
@@ -52,6 +52,6 @@ export function withinEngineLimits<T>(convert: () => Result<T>): Result<T> {
} catch (error) {
// A stack overflow is a bug (docs/decisions.md §Nothing recurses unbounded), so it stays a throw.
if (!(error instanceof Error) || !engineLimitThrows.includes(`${error.name}: ${error.message}`)) throw error
return failure('unsupported-node-shape', `the output runs past what this JavaScript engine holds: ${error.message}`, [])
return failure('unsupported-node-shape', `the output would be longer than the longest string or array this JavaScript engine builds (${error.message})`, [])
}
}