From 347dd8f5344b860fb883fb0fc38607a44ccadb61 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sat, 14 Mar 2026 18:36:21 +0000 Subject: [PATCH] Make all sections optional --- asm.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/asm.js b/asm.js index a59e16c..103f493 100644 --- a/asm.js +++ b/asm.js @@ -884,6 +884,7 @@ export class Assembler { wasm_section_type() { const funcs = Object.values(this.funcs); + if (funcs.length == 0) return null; const contents = funcs.map(({ params, results }) => { const param_types = Object.values(params); return [ @@ -917,6 +918,7 @@ export class Assembler { wasm_section_func() { const func_count = Object.entries(this.funcs).length; + if (func_count == 0) return null; return [ func_count, ...Array(func_count).keys() ]; } @@ -940,6 +942,7 @@ export class Assembler { wasm_section_export() { const exports = Object.entries(this.exports); + if (exports.length == 0) return null; const contents = exports.map(([ name, { kind, index }]) => { const name_utf8 = this.encoder.encode(name); return [ @@ -954,6 +957,7 @@ export class Assembler { wasm_section_code() { const funcs = Object.values(this.funcs); + if (funcs.length == 0) return null; const contents = funcs.map(({ body, locals }) => { const local_types = Object.values(locals); const local_count = local_types.length;