/** * Runs XSLT transforms for johnmcm.com's InfoPath Form Viewer and File Opener in a module * worker, so a stylesheet that loops can be stopped by ending the worker. * * Message in: { id, xml, xsl, maxOut?, options? } (options: see run.mjs) * Message out: { id, ok: true, output } or { id, ok: false, error, code, missing } * * After a WebAssembly trap (out of memory, too deep) the instance is thrown * away and a fresh one made for the next request. * * Written for johnmcm.com (2026); part of the module published at /source/xslt/. */ import createXslt from './xslt.mjs'; import { transform } from './run.mjs'; let instance = null; function module() { instance ??= createXslt({ print() {}, printErr() {}, locateFile: (f) => new URL(f, import.meta.url).href }).catch((err) => { instance = null; throw err; }); return instance; } self.onmessage = async (e) => { const { id, xml, xsl, maxOut, options } = e.data ?? {}; try { const m = await module(); self.postMessage({ id, ...transform(m, xml, xsl, maxOut, options) }); } catch (err) { instance = null; self.postMessage({ id, ok: false, error: String(err?.message ?? err), code: 'crash' }); } };