Skip to content

Commit 4b3bace

Browse files
authored
Consistent quoting for Module['canvas']. NFC (#22876)
127 or the 150 references to Module['canvas'] were already quoted. In general this is how we handle properties of the Module object that we don't want closure to minify. Once I do the same for the ctx object we can remove the closure type annotation completely from shell.js.
1 parent 585924b commit 4b3bace

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

src/library_browser.js

Lines changed: 1 addition & 1 deletion
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;

src/proxyClient.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ WebGLClient.prefetch();
153153
setTimeout(() => {
154154
worker.postMessage({
155155
target: 'worker-init',
156-
width: Module.canvas.width,
157-
height: Module.canvas.height,
158-
boundingClientRect: cloneObject(Module.canvas.getBoundingClientRect()),
156+
width: Module['canvas'].width,
157+
height: Module['canvas'].height,
158+
boundingClientRect: cloneObject(Module['canvas'].getBoundingClientRect()),
159159
URL: document.URL,
160160
currentScriptUrl: filename,
161161
preMain: true });
@@ -190,18 +190,18 @@ 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') {
195195
// possible GL_DEBUG entry point: Module.ctx = wrapDebugGL(Module.ctx);
196196
Module.glClient = new WebGLClient();
197197
}
198198
break;
199199
}
200200
case 'resize': {
201-
Module.canvas.width = data.width;
202-
Module.canvas.height = data.height;
201+
Module['canvas'].width = data.width;
202+
Module['canvas'].height = data.height;
203203
if (Module.ctx?.getImageData) Module.canvasData = Module.ctx.getImageData(0, 0, data.width, data.height);
204-
worker.postMessage({ target: 'canvas', boundingClientRect: cloneObject(Module.canvas.getBoundingClientRect()) });
204+
worker.postMessage({ target: 'canvas', boundingClientRect: cloneObject(Module['canvas'].getBoundingClientRect()) });
205205
break;
206206
}
207207
case 'render': {
@@ -216,7 +216,7 @@ worker.onmessage = (event) => {
216216
break;
217217
}
218218
case 'setObjectProperty': {
219-
Module.canvas[data.object][data.property] = data.value;
219+
Module['canvas'][data.object][data.property] = data.value;
220220
break;
221221
}
222222
default: throw 'eh?';
@@ -338,7 +338,7 @@ function shouldPreventDefault(event) {
338338
});
339339

340340
['mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll', 'mousewheel', 'mouseout'].forEach((event) => {
341-
Module.canvas.addEventListener(event, (event) => {
341+
Module['canvas'].addEventListener(event, (event) => {
342342
worker.postMessage({ target: 'canvas', event: cloneObject(event) });
343343
event.preventDefault();
344344
}, true);

src/proxyWorker.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ document.createElement = (what) => {
261261

262262
document.getElementById = (id) => {
263263
if (id === 'canvas' || id === 'application-canvas') {
264-
return Module.canvas;
264+
return Module['canvas'];
265265
}
266266
throw 'document.getElementById failed on ' + id;
267267
};
268268

269269
document.querySelector = (id) => {
270270
if (id === '#canvas' || id === '#application-canvas' || id === 'canvas' || id === 'application-canvas') {
271-
return Module.canvas;
271+
return Module['canvas'];
272272
}
273273
throw 'document.querySelector failed on ' + id;
274274
};
@@ -324,7 +324,7 @@ var screen = {
324324
height: 0
325325
};
326326

327-
Module.canvas = document.createElement('canvas');
327+
Module['canvas'] = document.createElement('canvas');
328328

329329
Module.setStatus = () => {};
330330

@@ -412,9 +412,9 @@ function onMessageFromMainEmscriptenThread(message) {
412412
}
413413
case 'canvas': {
414414
if (message.data.event) {
415-
Module.canvas.fireEvent(message.data.event);
415+
Module['canvas'].fireEvent(message.data.event);
416416
} else if (message.data.boundingClientRect) {
417-
Module.canvas.boundingClientRect = message.data.boundingClientRect;
417+
Module['canvas'].boundingClientRect = message.data.boundingClientRect;
418418
} else throw 'ey?';
419419
break;
420420
}
@@ -451,10 +451,10 @@ function onMessageFromMainEmscriptenThread(message) {
451451
break;
452452
}
453453
case 'worker-init': {
454-
Module.canvas = document.createElement('canvas');
455-
screen.width = Module.canvas.width_ = message.data.width;
456-
screen.height = Module.canvas.height_ = message.data.height;
457-
Module.canvas.boundingClientRect = message.data.boundingClientRect;
454+
Module['canvas'] = document.createElement('canvas');
455+
screen.width = Module['canvas'].width_ = message.data.width;
456+
screen.height = Module['canvas'].height_ = message.data.height;
457+
Module['canvas'].boundingClientRect = message.data.boundingClientRect;
458458
#if ENVIRONMENT_MAY_BE_NODE
459459
if (ENVIRONMENT_IS_NODE)
460460
#endif

src/shell.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ var Module = moduleArg;
2525
#elif USE_CLOSURE_COMPILER
2626
// if (!Module)` is crucial for Closure Compiler here as it will otherwise replace every `Module` occurrence with a string
2727
var /** @type {{
28-
canvas: HTMLCanvasElement,
2928
ctx: Object,
3029
}}
3130
*/ Module;

test/reftest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ function doReftest() {
2626
doReftest.done = true;
2727
var img = new Image();
2828
img.onload = () => {
29-
assert(img.width == Module.canvas.width, `Invalid width: ${Module.canvas.width}, should be ${img.width}`);
30-
assert(img.height == Module.canvas.height, `Invalid height: ${Module.canvas.height}, should be ${img.height}`);
29+
assert(img.width == Module['canvas'].width, `Invalid width: ${Module['canvas'].width}, should be ${img.width}`);
30+
assert(img.height == Module['canvas'].height, `Invalid height: ${Module['canvas'].height}, should be ${img.height}`);
3131

3232
var canvas = document.createElement('canvas');
3333
canvas.width = img.width;
@@ -36,7 +36,7 @@ function doReftest() {
3636
ctx.drawImage(img, 0, 0);
3737
var expected = ctx.getImageData(0, 0, img.width, img.height).data;
3838

39-
var actualUrl = Module.canvas.toDataURL();
39+
var actualUrl = Module['canvas'].toDataURL();
4040
var actualImage = new Image();
4141
actualImage.onload = () => {
4242
/*
@@ -69,7 +69,7 @@ function doReftest() {
6969
if (wrong || reftestRebaseline) {
7070
// Generate a png of the actual rendered image and send it back
7171
// to the server.
72-
Module.canvas.toBlob((blob) => {
72+
Module['canvas'].toBlob((blob) => {
7373
sendFileToServer('actual.png', blob);
7474
reportResultToServer(wrong);
7575
})

0 commit comments

Comments
 (0)