mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-20 23:25:43 +01:00
Answer stability round 1: the guard's comment holds at both its call sites, and a giving-way list's items keep the list's path
This commit is contained in:
@@ -8,14 +8,13 @@ const pastLongestString = ['InternalError: allocation size overflow', 'RangeErro
|
||||
const pastEngineLimit = ['RangeError: Invalid array length', 'RangeError: Out of memory']
|
||||
|
||||
export function tooLong<T>(): Result<T> {
|
||||
return failure('unsupported-node-shape', `spelled as markdown, this would be longer than ${longestMarkdown} characters, the longest string V8 holds`, [])
|
||||
return failure('unsupported-node-shape', `spelled as markdown, this would be longer than ${longestMarkdown} characters, the longest markdown this library writes`, [])
|
||||
}
|
||||
|
||||
export function withinLongest(text: string): Result<string> {
|
||||
return text.length > longestMarkdown ? tooLong() : success(text)
|
||||
}
|
||||
|
||||
// Joins the pieces as they come, so a spelling that grows far past its input stops at the bound unbuilt.
|
||||
export function joinedWithin(pieces: Iterable<string>): Result<string> {
|
||||
const kept: string[] = []
|
||||
let length = 0
|
||||
@@ -27,7 +26,7 @@ export function joinedWithin(pieces: Iterable<string>): Result<string> {
|
||||
return success(kept.join(''))
|
||||
}
|
||||
|
||||
// Any concatenation can pass an engine's longest string or array, so this wraps a whole conversion.
|
||||
// Any concatenation can pass an engine's longest string or array; wrap every call that builds one.
|
||||
export function withinEngineLimits<T>(convert: () => Result<T>): Result<T> {
|
||||
try {
|
||||
return convert()
|
||||
|
||||
Reference in New Issue
Block a user