mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-18 22:25:44 +01:00
Return the new code engine-limit where the engine runs short of memory or passes its longest array, so unsupported-node-shape stays deterministic
This commit is contained in:
@@ -23,15 +23,19 @@ test('passes a text within the bound', () => {
|
||||
assert.deepEqual(withinLongest('x'), success('x'))
|
||||
})
|
||||
|
||||
test('refuses a string past the bound as too long on every engine, and names any other engine limit', () => {
|
||||
test('refuses a string past the bound as too long on every engine, and any other engine limit as engine-limit', () => {
|
||||
assert.deepEqual(withinEngineLimits(thrown('RangeError', 'Invalid string length')), tooLong())
|
||||
assert.deepEqual(withinEngineLimits(thrown('InternalError', 'allocation size overflow')), tooLong())
|
||||
assert.deepEqual(withinEngineLimits(thrown('RangeError', 'Out of memory')), {
|
||||
error: { code: 'unsupported-node-shape', message: 'the conversion passed this JavaScript engine\'s longest string or array, or ran it out of memory (Out of memory)', path: [] },
|
||||
error: { code: 'engine-limit', message: 'the conversion passed this JavaScript engine\'s longest string or array, or ran it out of memory (Out of memory)', path: [] },
|
||||
ok: false,
|
||||
})
|
||||
assert.equal(withinEngineLimits(thrown('RangeError', 'Invalid array length')).ok, false)
|
||||
assert.equal(withinEngineLimits(thrown('RangeError', 'Array buffer allocation failed')).ok, false)
|
||||
const code = (message: string): string | undefined => {
|
||||
const refused = withinEngineLimits(thrown('RangeError', message))
|
||||
return refused.ok ? undefined : refused.error.code
|
||||
}
|
||||
assert.equal(code('Invalid array length'), 'engine-limit')
|
||||
assert.equal(code('Array buffer allocation failed'), 'engine-limit')
|
||||
assert.deepEqual(
|
||||
withinEngineLimits(() => success('x')),
|
||||
{ ok: true, value: 'x' },
|
||||
|
||||
@@ -36,6 +36,6 @@ export function withinEngineLimits<T>(convert: () => Result<T>): Result<T> {
|
||||
if (pastLongestString.includes(thrown)) return tooLong()
|
||||
// A stack overflow is a bug (docs/decisions.md §Nothing recurses unbounded), so it stays a throw.
|
||||
if (!pastEngineLimit.includes(thrown)) throw error
|
||||
return failure('unsupported-node-shape', `the conversion passed this JavaScript engine's longest string or array, or ran it out of memory (${error.message})`, [])
|
||||
return failure('engine-limit', `the conversion passed this JavaScript engine's longest string or array, or ran it out of memory (${error.message})`, [])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export type ConvertErrorCode =
|
||||
| 'engine-limit'
|
||||
| 'malformed-directive'
|
||||
| 'malformed-pipe-table'
|
||||
| 'not-a-string'
|
||||
|
||||
Reference in New Issue
Block a user