Skip to main content

WASM_MAX_DEPTH

Constant WASM_MAX_DEPTH 

Source
pub const WASM_MAX_DEPTH: u32 = 400;
Expand description

The largest ValidateOptions::max_depth on WebAssembly: 400.

A WebAssembly engine runs the module’s functions on a native stack of its own, beside the module’s stack in linear memory, which is the only one the library measures (ValidateOptions::max_stack). When the native stack runs out first, the engine throws (a RangeError in V8, an InternalError in Firefox) and leaves the module’s memory inconsistent, so that every later call fails. What keeps the native stack from running out is WASM_MAX_STACK; this maximum bounds the depth, and the nesting of template and function invocations that comes with it (max_nesting_for_depth: 864), to what that stack serves. Measured with the npm package (opt-level 3, wasm-opt -O3) and 256 KiB of stack, on documents nested inside a UBL or a CII invoice: the stylesheets of the built-in rule sets (and of Peppol BIS Billing 3.0.22) validate a document up to 487 levels deep when no rule fires on the nested elements, and up to 243 levels deep when a rule fires and reports on every one of them; deeper, the validation fails with Error::Limit (LimitExceeded::Stack), the same in Chrome and Firefox (main thread and Web Worker) and in Node.js. 400 keeps a margin below 487.