feat(anatomy): text and output caps, hostile corpus through the shipped wasm within budgets; SheetSession poisons on non-closed throws
This commit is contained in:
1 parent
842797b440
commit
43a370aed1
8 files changed
+227
-6
No files matched your search
@@ -172,6 +172,18 @@ export class CoreRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The detail of a refusal the module's `SheetHandle` constructor threw (crates/wasm: a
|
||||
* `JsError` worded `<kind>: <detail>`), without its `invalid_sheet: ` kind; `null` when the
|
||||
* error is anything else.
|
||||
*/
|
||||
function closedRefusal(error: unknown): string | null {
|
||||
if (!(error instanceof Error) || error.name !== 'Error') return null
|
||||
const match = /^([a-z_]+): /.exec(error.message)
|
||||
if (!match) return null
|
||||
return match[1] === 'invalid_sheet' ? error.message.slice(match[0].length) : error.message
|
||||
}
|
||||
|
||||
/** The calls that need the session's sheet (`SheetHandle` in the module's memory). */
|
||||
export class SheetSession {
|
||||
private handle: GlueSheetHandle | null = null
|
||||
@@ -209,9 +221,12 @@ export class SheetSession {
|
||||
try {
|
||||
this.handle = new glue.SheetHandle(this.bundleText)
|
||||
} catch (error) {
|
||||
if (error instanceof WebAssembly.RuntimeError) throw error
|
||||
const message = error instanceof Error ? error.message : ''
|
||||
return failure('invalid_sheet', message.replace(/^invalid_sheet: /, ''))
|
||||
// Only the module's closed refusal (a plain Error worded `<kind>: <detail>`) is a
|
||||
// refused sheet; anything else (a trap, an engine stack overflow surfacing as
|
||||
// RangeError or InternalError) poisons the instance.
|
||||
const refusal = closedRefusal(error)
|
||||
if (refusal === null) throw error
|
||||
return failure('invalid_sheet', refusal)
|
||||
}
|
||||
this.handleGeneration = this.runtime.generation
|
||||
return { ok: true, value: this.handle }
|
||||
|
||||
Reference in new issue
Block a user