"""Replace two Emscripten dynamic invokers with equivalent static closures. Adapted from Emscripten's DYNAMIC_EXECUTION=0 path (MIT/University of Illinois). Input is npm @matbee/libreoffice-converter 2.7.2 wasm/soffice.js. No CSP relaxation is required. LibreOffice wasm/data bytes are unchanged. """ from pathlib import Path import argparse parser=argparse.ArgumentParser() parser.add_argument('input',type=Path,help='Original converter 2.7.2 wasm/soffice.js') parser.add_argument('output',type=Path,help='Destination modified soffice.js') args=parser.parse_args() s=args.input.read_text() start=s.index('function craftInvokerFunction(');end=s.index('var heap32VectorToArray=',start) s=s[:start]+'''function craftInvokerFunction(humanName,argTypes,classType,cppInvokerFunc,cppTargetFunc,isAsync){ if(isAsync)throwBindingError('Async bindings unavailable'); const method=argTypes[1]!==null&&classType!==null,stack=usesDestructorStack(argTypes),expected=argTypes.length-2,min=getRequiredArgCount(argTypes); return createNamedFunction(humanName,function(...args){ checkArgCount(args.length,min,expected,humanName,throwBindingError); const destructors=stack?[]:null,wired=[],params=[cppTargetFunc];let receiver,result; try{ if(method){receiver=argTypes[1].toWireType(destructors,this);params.push(receiver)} for(let i=0;i