Skip to content

Commit e191834

Browse files
authored
Use quoted access for Module['ctx']. NFC (#22882)
This was the last property explicitly listed in the closure type annotate for the `Module` object. This means that it was previously being preserved by closure via this mechanism, but now we preserve it via the normal quoting mechanism. I've been looking at removing `ctx` and `canvas` from the `Module` object, but this change is just about consistency. See #22876
1 parent 1de8124 commit e191834

15 files changed

+32
-33
lines changed

src/cpuprofiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ var emscriptenCpuProfiler = {
593593
detectWebGLContext() {
594594
if (Module['canvas']?.GLctxObject?.GLctx) return Module['canvas'].GLctxObject.GLctx;
595595
else if (typeof GLctx != 'undefined') return GLctx;
596-
else if (Module.ctx) return Module.ctx;
596+
else if (Module['ctx']) return Module['ctx'];
597597
return null;
598598
},
599599

src/library_browser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ var LibraryBrowser = {
192192
},
193193

194194
createContext(/** @type {HTMLCanvasElement} */ canvas, useWebGL, setInModule, webGLContextAttributes) {
195-
if (useWebGL && Module.ctx && canvas == Module['canvas']) return Module.ctx; // no need to recreate GL context if it's already been created for this canvas.
195+
if (useWebGL && Module['ctx'] && canvas == Module['canvas']) return Module['ctx']; // no need to recreate GL context if it's already been created for this canvas.
196196

197197
var ctx;
198198
var contextHandle;
@@ -235,7 +235,7 @@ var LibraryBrowser = {
235235
#if ASSERTIONS
236236
if (!useWebGL) assert(typeof GLctx == 'undefined', 'cannot set in module if GLctx is used, but we are a non-GL context that would replace it');
237237
#endif
238-
Module.ctx = ctx;
238+
Module['ctx'] = ctx;
239239
if (useWebGL) GL.makeContextCurrent(contextHandle);
240240
Browser.useWebGL = useWebGL;
241241
Browser.moduleContextCreatedCallbacks.forEach((callback) => callback());

src/library_eventloop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ LibraryJSEventLoop = {
472472
}
473473

474474
#if ASSERTIONS
475-
if (MainLoop.method === 'timeout' && Module.ctx) {
475+
if (MainLoop.method === 'timeout' && Module['ctx']) {
476476
warnOnce('Looks like you are rendering without using requestAnimationFrame for the main loop. You should use 0 for the frame rate in emscripten_set_main_loop in order to use requestAnimationFrame, as that can greatly improve your frame rates!');
477477
MainLoop.method = ''; // just warn once per call to set main loop
478478
}

src/library_glfw.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ var LibraryGLFW = {
11081108
}
11091109

11101110
// If context creation failed, do not return a valid window
1111-
if (!Module.ctx && useWebGL) return 0;
1111+
if (!Module['ctx'] && useWebGL) return 0;
11121112

11131113
// Initializes the framebuffer size from the canvas
11141114
const canvas = Module['canvas'];
@@ -1144,7 +1144,7 @@ var LibraryGLFW = {
11441144
for (var i = 0; i < GLFW.windows.length; i++)
11451145
if (GLFW.windows[i] !== null) return;
11461146

1147-
delete Module.ctx;
1147+
delete Module['ctx'];
11481148
},
11491149

11501150
swapBuffers: (winid) => {

src/library_glut.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ var LibraryGLUT = {
575575
glutDestroyWindow__proxy: 'sync',
576576
glutDestroyWindow__deps: ['$Browser'],
577577
glutDestroyWindow: (name) => {
578-
delete Module.ctx;
578+
delete Module['ctx'];
579579
return 1;
580580
},
581581

src/library_html5_webgl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ var LibraryHtml5WebGL = {
223223
});`,
224224
#endif
225225
_emscripten_proxied_gl_context_activated_from_main_browser_thread: (contextHandle) => {
226-
GLctx = Module.ctx = GL.currentContext = contextHandle;
226+
GLctx = Module['ctx'] = GL.currentContext = contextHandle;
227227
GL.currentContextIsProxied = true;
228228
},
229229
#else

src/library_webgl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
11701170
// Active Emscripten GL layer context object.
11711171
GL.currentContext = GL.contexts[contextHandle];
11721172
// Active WebGL context object.
1173-
Module.ctx = GLctx = GL.currentContext?.GLctx;
1173+
Module['ctx'] = GLctx = GL.currentContext?.GLctx;
11741174
return !(contextHandle && !GLctx);
11751175
},
11761176

src/proxyClient.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function renderFrame() {
103103
dst[i] = renderFrameData[i];
104104
}
105105
}
106-
Module.ctx.putImageData(Module.canvasData, 0, 0);
106+
Module['ctx'].putImageData(Module.canvasData, 0, 0);
107107
renderFrameData = null;
108108
}
109109

@@ -190,17 +190,17 @@ worker.onmessage = (event) => {
190190
case 'canvas': {
191191
switch (data.op) {
192192
case 'getContext': {
193-
Module.ctx = Module['canvas'].getContext(data.type, data.attributes);
193+
Module['ctx'] = Module['canvas'].getContext(data.type, data.attributes);
194194
if (data.type !== '2d') {
195-
// possible GL_DEBUG entry point: Module.ctx = wrapDebugGL(Module.ctx);
195+
// possible GL_DEBUG entry point: Module['ctx'] = wrapDebugGL(Module['ctx']);
196196
Module.glClient = new WebGLClient();
197197
}
198198
break;
199199
}
200200
case 'resize': {
201201
Module['canvas'].width = data.width;
202202
Module['canvas'].height = data.height;
203-
if (Module.ctx?.getImageData) Module.canvasData = Module.ctx.getImageData(0, 0, data.width, data.height);
203+
if (Module['ctx']?.getImageData) Module.canvasData = Module['ctx'].getImageData(0, 0, data.width, data.height);
204204
worker.postMessage({ target: 'canvas', boundingClientRect: cloneObject(Module['canvas'].getBoundingClientRect()) });
205205
break;
206206
}

src/shell.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
#if MODULARIZE
2424
var Module = moduleArg;
2525
#elif USE_CLOSURE_COMPILER
26+
/** @type{Object} */
27+
var Module;
2628
// if (!Module)` is crucial for Closure Compiler here as it will otherwise replace every `Module` occurrence with a string
27-
var /** @type {{
28-
ctx: Object,
29-
}}
30-
*/ Module;
3129
if (!Module) /** @suppress{checkTypes}*/Module = {"__EMSCRIPTEN_PRIVATE_MODULE_EXPORT_NAME_SUBSTITUTION__":1};
3230
#elif AUDIO_WORKLET
3331
var Module = globalThis.Module || (typeof {{{ EXPORT_NAME }}} != 'undefined' ? {{{ EXPORT_NAME }}} : {});

src/shell_minimal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
#if MODULARIZE
88
var Module = moduleArg;
99
#elif USE_CLOSURE_COMPILER
10+
/** @type{Object} */
11+
var Module;
1012
// if (!Module)` is crucial for Closure Compiler here as it will
1113
// otherwise replace every `Module` occurrence with the object below
12-
var /** @type{Object} */ Module;
1314
if (!Module) /** @suppress{checkTypes}*/Module =
1415
#if AUDIO_WORKLET
1516
globalThis.{{{ EXPORT_NAME }}} ||

src/webGLClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ function WebGLClient() {
272272
};
273273

274274
function renderCommands(buf) {
275-
ctx = Module.ctx;
275+
ctx = Module['ctx'];
276276
i = 0;
277277
buffer = buf;
278278
var len = buffer.length;

test/code_size/hello_webgl2_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 454,
33
"a.html.gz": 328,
4-
"a.js": 4531,
5-
"a.js.gz": 2312,
4+
"a.js": 4532,
5+
"a.js.gz": 2315,
66
"a.wasm": 10402,
77
"a.wasm.gz": 6704,
8-
"total": 15387,
9-
"total_gz": 9344
8+
"total": 15388,
9+
"total_gz": 9347
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"a.html": 346,
33
"a.html.gz": 262,
4-
"a.js": 22199,
5-
"a.js.gz": 11579,
6-
"total": 22545,
7-
"total_gz": 11841
4+
"a.js": 22200,
5+
"a.js.gz": 11582,
6+
"total": 22546,
7+
"total_gz": 11844
88
}

test/code_size/hello_webgl_wasm.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 454,
33
"a.html.gz": 328,
4-
"a.js": 4069,
4+
"a.js": 4070,
55
"a.js.gz": 2158,
66
"a.wasm": 10402,
77
"a.wasm.gz": 6704,
8-
"total": 14925,
8+
"total": 14926,
99
"total_gz": 9190
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"a.html": 346,
33
"a.html.gz": 262,
4-
"a.js": 21725,
5-
"a.js.gz": 11413,
6-
"total": 22071,
7-
"total_gz": 11675
4+
"a.js": 21726,
5+
"a.js.gz": 11415,
6+
"total": 22072,
7+
"total_gz": 11677
88
}

0 commit comments

Comments
 (0)