Skip to content

Commit 8aaeb00

Browse files
committed
[libhtm5.js] Replace typeof operators with globalThis. NFC
1 parent fb4a23b commit 8aaeb00

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/lib/libhtml5.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ var LibraryHTML5 = {
323323
// (that will let !canvas map to the canvas held in Module.canvas).
324324
$specialHTMLTargets__docs: '/** @type {Object} */',
325325
#if ENVIRONMENT_MAY_BE_WORKER || ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL || PTHREADS
326-
$specialHTMLTargets: "[0, typeof document != 'undefined' ? document : 0, typeof window != 'undefined' ? window : 0]",
326+
$specialHTMLTargets: "[0, globalThis.document ?? 0, globalThis.window ?? 0]",
327327
#else
328328
$specialHTMLTargets: "[0, document, window]",
329329
#endif
@@ -342,7 +342,7 @@ var LibraryHTML5 = {
342342
$findEventTarget: (target) => {
343343
target = maybeCStringToJsString(target);
344344
#if ENVIRONMENT_MAY_BE_WORKER || ENVIRONMENT_MAY_BE_NODE
345-
var domElement = specialHTMLTargets[target] || (typeof document != 'undefined' ? document.querySelector(target) : null);
345+
var domElement = specialHTMLTargets[target] || globalThis.document?.querySelector(target);
346346
#else
347347
var domElement = specialHTMLTargets[target] || document.querySelector(target);
348348
#endif
@@ -373,7 +373,7 @@ var LibraryHTML5 = {
373373
|| specialHTMLTargets[target]
374374
// If that is not found either, query via the regular DOM selector.
375375
#if PTHREADS
376-
|| (typeof document != 'undefined' && document.querySelector(target));
376+
|| globalThis.document?.querySelector(target));
377377
#else
378378
|| document.querySelector(target);
379379
#endif
@@ -400,7 +400,7 @@ var LibraryHTML5 = {
400400
else if (target === '#canvas') return Module['canvas'];
401401
else if (typeof target == 'string')
402402
#if ENVIRONMENT_MAY_BE_WORKER || ENVIRONMENT_MAY_BE_NODE
403-
return (typeof document != 'undefined') ? document.getElementById(target) : null;
403+
return globalThis.document?.getElementById(target);
404404
#else
405405
return document.getElementById(target);
406406
#endif
@@ -412,10 +412,10 @@ var LibraryHTML5 = {
412412
$findCanvasEventTarget: (target) => {
413413
if (typeof target == 'number') target = UTF8ToString(target);
414414
if (!target || target === '#canvas') {
415-
if (typeof GL != 'undefined' && GL.offscreenCanvases['canvas']) return GL.offscreenCanvases['canvas']; // TODO: Remove this line, target '#canvas' should refer only to Module['canvas'], not to GL.offscreenCanvases['canvas'] - but need stricter tests to be able to remove this line.
415+
if (globalThis.GL?.offscreenCanvases['canvas']) return GL.offscreenCanvases['canvas']; // TODO: Remove this line, target '#canvas' should refer only to Module['canvas'], not to GL.offscreenCanvases['canvas'] - but need stricter tests to be able to remove this line.
416416
return Module['canvas'];
417417
}
418-
if (typeof GL != 'undefined' && GL.offscreenCanvases[target]) return GL.offscreenCanvases[target];
418+
if (globalThis.GL?.offscreenCanvases[target]) return GL.offscreenCanvases[target];
419419
return findEventTarget(target);
420420
},
421421
#endif
@@ -2069,8 +2069,8 @@ var LibraryHTML5 = {
20692069
{{{ makeSetValue('eventStruct', C_STRUCTS.EmscriptenBatteryEvent.charging, 'battery.charging', 'i8') }}};
20702070
},
20712071

2072-
$hasBatteryAPI: () => typeof navigator != 'undefined' && navigator.getBattery,
20732072
$hasBatteryAPI__internal: true,
2073+
$hasBatteryAPI: () => globalThis.navigator?.getBattery,
20742074

20752075
$registerBatteryEventCallback__noleakcheck: true,
20762076
$registerBatteryEventCallback__deps: ['$JSEvents', '$fillBatteryEventData', 'malloc'],
@@ -2385,7 +2385,7 @@ var LibraryHTML5 = {
23852385
emscripten_get_device_pixel_ratio__proxy: 'sync',
23862386
emscripten_get_device_pixel_ratio: () => {
23872387
#if ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
2388-
return (typeof devicePixelRatio == 'number' && devicePixelRatio) || 1.0;
2388+
return globalThis.devicePixelRatio ?? 1.0;
23892389
#else // otherwise, on the web and in workers, things are simpler
23902390
return devicePixelRatio;
23912391
#endif

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 245720,
2+
"a.out.js": 245665,
33
"a.out.nodebug.wasm": 574007,
4-
"total": 819727,
4+
"total": 819672,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

0 commit comments

Comments
 (0)