Skip to content

Commit 14193a0

Browse files
authored
Allow undefined to be returned from {{{ }}} blocks (#24019)
This means we don't need to inject artificial `null` statements.
1 parent 7787d7a commit 14193a0

File tree

10 files changed

+7
-17
lines changed

10 files changed

+7
-17
lines changed

src/lib/libegl.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const eglDefaultDisplay = 62000;
2222
const eglDefaultConfig = 62002;
2323
// Magic ID for Emscripten EGLContext
2424
const eglDefaultContext = 62004;
25-
null;
2625
}}}
2726

2827
var LibraryEGL = {

src/lib/libemval.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
{{{
2020
const EMVAL_RESERVED_HANDLES = 5;
2121
const EMVAL_LAST_RESERVED_HANDLE = EMVAL_RESERVED_HANDLES * 2 - 1;
22-
null;
2322
}}}
2423
var LibraryEmVal = {
2524
// Stack of handles available for reuse.

src/lib/libglemu.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ assert(!FULL_ES3, 'cannot emulate both ES3 and legacy GL');
2121
}
2222
return '';
2323
};
24-
null;
2524
}}}
2625

2726
var LibraryGLEmulation = {

src/lib/libhtml5_webgpu.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{{{
22
// Helper functions for code generation
3-
globalThis.html5_gpu = {
4-
makeImportExport: (snake_case, CamelCase) => {
5-
return `
3+
const html5_gpu = {
4+
makeImportExport: (snake_case, CamelCase) => {
5+
return `
66
LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
77
LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case} = (handle) =>
88
WebGPU.mgr${CamelCase}.create(JsValStore.get(handle));
99
1010
LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
1111
LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case} = (handle) =>
1212
JsValStore.add(WebGPU.mgr${CamelCase}.get(handle));`
13-
},
14-
};
15-
null;
13+
},
14+
};
1615
}}}
1716

1817

src/lib/libpthread.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const pthreadWorkerOptions = `{
5252
#endif
5353
#endif
5454
}`;
55-
null
5655
}}}
5756

5857
var LibraryPThread = {

src/lib/libwasm_worker.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
const captureModuleArg = () => MODULARIZE ? '' : 'self.Module=d;';
1111
const instantiateModule = () => MODULARIZE ? `${EXPORT_NAME}(d);` : '';
1212
const instantiateWasm = () => MINIMAL_RUNTIME ? '' : 'd[`instantiateWasm`]=(i,r)=>{var n=new WebAssembly.Instance(d[`wasm`],i);return r(n,d[`wasm`]);};';
13-
null;
1413
}}}
1514
#endif
1615

@@ -43,7 +42,6 @@
4342
locateFile('${WASM_WORKER_FILE}')
4443
#endif
4544
`;
46-
null;
4745
}}}
4846

4947
#endif // ~WASM_WORKERS

src/lib/libwebgl.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
if (MIN_WEBGL_VERSION >= 2) return 'true';
1616
return 'GL.currentContext.version >= 2';
1717
}
18-
null;
1918
}}}
2019

2120
var LibraryGL = {

src/lib/libwebgpu.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ wgpu${type}Release: (id) => WebGPU.mgr${type}.release(id),`;
185185
Instance: 3,
186186
},
187187
};
188-
null;
189188
}}}
190189

191190
var LibraryWebGPU = {

src/parseTools.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function processMacros(text, filename) {
4040
try {
4141
return text.replace(/{{{([\s\S]+?)}}}/g, (_, str) => {
4242
const ret = runInMacroContext(str, {filename: filename});
43-
return ret !== null ? ret.toString() : '';
43+
return ret?.toString() ?? '';
4444
});
4545
} finally {
4646
popCurrentFile();

src/runtime_shared.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var wasmOffsetConverter;
3838
{{{
3939
// Helper function to export a heap symbol on the module object,
4040
// if requested.
41-
globalThis.maybeExportHeap = (x) => {
41+
const maybeExportHeap = (x) => {
4242
// For now, we export all heap object when not building with MINIMAL_RUNTIME
4343
let shouldExport = !MINIMAL_RUNTIME && !STRICT;
4444
if (!shouldExport) {
@@ -61,7 +61,6 @@ var wasmOffsetConverter;
6161
}
6262
return '';
6363
};
64-
null;
6564
}}}
6665

6766
function updateMemoryViews() {

0 commit comments

Comments
 (0)