Skip to content

Commit b9dbeac

Browse files
authored
Avoid unnecessary globalThis usage when defining JS library macros (#23723)
When the macro only need to be available to other library files this is not needed.
1 parent 4ae3f6e commit b9dbeac

File tree

7 files changed

+21
-20
lines changed

7 files changed

+21
-20
lines changed

src/lib/libegl.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
{{{
1919
// Magic ID for Emscripten 'default display'
20-
globalThis.eglDefaultDisplay = 62000;
20+
const eglDefaultDisplay = 62000;
2121
// Magic ID for the only EGLConfig supported by Emscripten
22-
globalThis.eglDefaultConfig = 62002;
22+
const eglDefaultConfig = 62002;
2323
// Magic ID for Emscripten EGLContext
24-
globalThis.eglDefaultContext = 62004;
24+
const eglDefaultContext = 62004;
25+
null;
2526
}}}
2627

2728
var LibraryEGL = {

src/lib/libemval.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
/*global emval_get_global*/
1818

1919
// Number of handles reserved for non-use (0) or common values w/o refcount.
20-
{{{
21-
globalThis.EMVAL_RESERVED_HANDLES = 5;
22-
globalThis.EMVAL_LAST_RESERVED_HANDLE = globalThis.EMVAL_RESERVED_HANDLES * 2 - 1;
20+
{{{
21+
const EMVAL_RESERVED_HANDLES = 5;
22+
const EMVAL_LAST_RESERVED_HANDLE = EMVAL_RESERVED_HANDLES * 2 - 1;
2323
null;
2424
}}}
2525
var LibraryEmVal = {

src/lib/libglemu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66

77
{{{
8-
globalThis.copySigs = (func) => {
8+
const copySigs = (func) => {
99
if (!RELOCATABLE) return '';
1010
return ` _${func}.sig = _emscripten_${func}.sig = orig_${func}.sig;`;
1111
};
12-
globalThis.fromPtr = (arg) => {
12+
const fromPtr = (arg) => {
1313
if (CAN_ADDRESS_2GB) {
1414
return `${arg} >>>= 0`;
1515
} else if (MEMORY64) {

src/lib/libpthread.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525

2626
{{{
2727
#if MEMORY64
28-
globalThis.MAX_PTR = Number((2n ** 64n) - 1n);
28+
const MAX_PTR = Number((2n ** 64n) - 1n);
2929
#else
30-
globalThis.MAX_PTR = (2 ** 32) - 1
30+
const MAX_PTR = (2 ** 32) - 1
3131
#endif
3232
// Use a macro to avoid duplicating pthread worker options.
3333
// We cannot use a normal JS variable since the vite bundler requires that worker
3434
// options be inline.
3535
// See https://github.com/emscripten-core/emscripten/issues/22394
36-
globalThis.pthreadWorkerOptions = `{
36+
const pthreadWorkerOptions = `{
3737
#if EXPORT_ES6
3838
'type': 'module',
3939
#endif

src/lib/libwasm_worker.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#if WASM_WORKERS == 2
88
// Helpers for _wasmWorkerBlobUrl used in WASM_WORKERS == 2 mode
99
{{{
10-
globalThis.captureModuleArg = () => MODULARIZE ? '' : 'self.Module=d;';
11-
globalThis.instantiateModule = () => MODULARIZE ? `${EXPORT_NAME}(d);` : '';
12-
globalThis.instantiateWasm = () => MINIMAL_RUNTIME ? '' : 'd[`instantiateWasm`]=(i,r)=>{var n=new WebAssembly.Instance(d[`wasm`],i);return r(n,d[`wasm`]);};';
10+
const captureModuleArg = () => MODULARIZE ? '' : 'self.Module=d;';
11+
const instantiateModule = () => MODULARIZE ? `${EXPORT_NAME}(d);` : '';
12+
const instantiateWasm = () => MINIMAL_RUNTIME ? '' : 'd[`instantiateWasm`]=(i,r)=>{var n=new WebAssembly.Instance(d[`wasm`],i);return r(n,d[`wasm`]);};';
1313
null;
1414
}}}
1515
#endif
@@ -33,7 +33,7 @@
3333
#endif
3434

3535
{{{
36-
globalThis.workerSupportsFutexWait = () => AUDIO_WORKLET ? "typeof AudioWorkletGlobalScope === 'undefined'" : '1';
36+
const workerSupportsFutexWait = () => AUDIO_WORKLET ? "typeof AudioWorkletGlobalScope === 'undefined'" : '1';
3737
null;
3838
}}}
3939

src/lib/libwebgl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
// Specifies the size of the GL temp buffer pool, in bytes. Must be a multiple
88
// of 9 and 16.
9-
{{{ GL_POOL_TEMP_BUFFERS_SIZE = 2*9*16 }}} // = 288
10-
119
{{{
12-
globalThis.isCurrentContextWebGL2 = () => {
10+
const GL_POOL_TEMP_BUFFERS_SIZE = 2*9*16 // = 288
11+
12+
const isCurrentContextWebGL2 = () => {
1313
// This function should only be called inside of `#if MAX_WEBGL_VERSION >= 2` blocks
1414
assert(MAX_WEBGL_VERSION >= 2, 'isCurrentContextWebGL2 called without webgl2 support');
1515
if (MIN_WEBGL_VERSION >= 2) return 'true';
1616
return 'GL.currentContext.version >= 2';
17-
};
17+
}
1818
null;
1919
}}}
2020

src/lib/libwebgpu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
{{{
3030
// Helper functions for code generation
31-
globalThis.gpu = {
31+
const gpu = {
3232
makeInitManager: function(type) {
3333
return `WebGPU.mgr${type} = new Manager();`;
3434
},

0 commit comments

Comments
 (0)