Skip to content

Commit

Permalink
Use quotes when accessing noWasmDecoding/noAudioDecoding/etc on Modul…
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Aug 6, 2024
1 parent 6a41b30 commit 03fca01
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/library_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var LibraryBrowser = {

var imagePlugin = {};
imagePlugin['canHandle'] = function imagePlugin_canHandle(name) {
return !Module.noImageDecoding && /\.(jpg|jpeg|png|bmp|webp)$/i.test(name);
return !Module['noImageDecoding'] && /\.(jpg|jpeg|png|bmp|webp)$/i.test(name);
};
imagePlugin['handle'] = function imagePlugin_handle(byteArray, name, onload, onerror) {
var b = new Blob([byteArray], { type: Browser.getMimetype(name) });
Expand Down Expand Up @@ -160,7 +160,7 @@ var LibraryBrowser = {

var audioPlugin = {};
audioPlugin['canHandle'] = function audioPlugin_canHandle(name) {
return !Module.noAudioDecoding && name.substr(-4) in { '.ogg': 1, '.wav': 1, '.mp3': 1 };
return !Module['noAudioDecoding'] && name.substr(-4) in { '.ogg': 1, '.wav': 1, '.mp3': 1 };
};
audioPlugin['handle'] = function audioPlugin_handle(byteArray, name, onload, onerror) {
var done = false;
Expand Down
2 changes: 1 addition & 1 deletion src/library_dylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var LibraryDylink = {
var wasmPlugin = {
'promiseChainEnd': Promise.resolve(),
'canHandle': (name) => {
return !Module.noWasmDecoding && name.endsWith('.so')
return !Module['noWasmDecoding'] && name.endsWith('.so')
},
'handle': (byteArray, name, onload, onerror) => {
// loadWebAssemblyModule can not load modules out-of-order, so rather
Expand Down
2 changes: 1 addition & 1 deletion src/library_sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2701,7 +2701,7 @@ var LibrarySDL = {
var raw = preloadedAudios[filename];
if (!raw) {
if (raw === null) err('Trying to reuse preloaded audio, but freePreloadedMediaOnUse is set!');
if (!Module.noAudioDecoding) warnOnce('Cannot find preloaded audio ' + filename);
if (!Module['noAudioDecoding']) warnOnce('Cannot find preloaded audio ' + filename);

// see if we can read the file-contents from the in-memory FS
try {
Expand Down
6 changes: 0 additions & 6 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ var Module = moduleArg;
#elif USE_CLOSURE_COMPILER
// if (!Module)` is crucial for Closure Compiler here as it will otherwise replace every `Module` occurrence with a string
var /** @type {{
noImageDecoding: boolean,
noAudioDecoding: boolean,
noWasmDecoding: boolean,
canvas: HTMLCanvasElement,
ctx: Object,
dataFileDownloads: Object,
preloadResults: Object,
useWebGL: boolean,
expectedDataFileDownloads: number,
}}
*/ Module;
if (!Module) /** @suppress{checkTypes}*/Module = {"__EMSCRIPTEN_PRIVATE_MODULE_EXPORT_NAME_SUBSTITUTION__":1};
Expand Down
26 changes: 13 additions & 13 deletions tools/file_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,11 @@ def generate_js(data_target, data_files, metadata):
var Module = typeof %(EXPORT_NAME)s != 'undefined' ? %(EXPORT_NAME)s : {};\n''' % {"EXPORT_NAME": options.export_name}

ret += '''
if (!Module.expectedDataFileDownloads) {
Module.expectedDataFileDownloads = 0;
if (!Module['expectedDataFileDownloads']) {
Module['expectedDataFileDownloads'] = 0;
}
Module.expectedDataFileDownloads++;
Module['expectedDataFileDownloads']++;
(() => {
// Do not attempt to redownload the virtual filesystem data when in a pthread or a Wasm Worker context.
var isPthread = typeof ENVIRONMENT_IS_PTHREAD != 'undefined' && ENVIRONMENT_IS_PTHREAD;
Expand Down Expand Up @@ -978,26 +978,26 @@ def generate_js(data_target, data_files, metadata):
if (event.loaded) {
if (!xhr.addedTotal) {
xhr.addedTotal = true;
if (!Module.dataFileDownloads) Module.dataFileDownloads = {};
Module.dataFileDownloads[url] = {
if (!Module['dataFileDownloads']) Module['dataFileDownloads'] = {};
Module['dataFileDownloads'][url] = {
loaded: event.loaded,
total: size
};
} else {
Module.dataFileDownloads[url].loaded = event.loaded;
Module['dataFileDownloads'][url].loaded = event.loaded;
}
var total = 0;
var loaded = 0;
var num = 0;
for (var download in Module.dataFileDownloads) {
var data = Module.dataFileDownloads[download];
for (var download in Module['dataFileDownloads']) {
var data = Module['dataFileDownloads'][download];
total += data.total;
loaded += data.loaded;
num++;
}
total = Math.ceil(total * Module.expectedDataFileDownloads/num);
total = Math.ceil(total * Module['expectedDataFileDownloads']/num);
Module['setStatus']?.(`Downloading data... (${loaded}/${total})`);
} else if (!Module.dataFileDownloads) {
} else if (!Module['dataFileDownloads']) {
Module['setStatus']?.('Downloading data...');
}
};
Expand Down Expand Up @@ -1032,7 +1032,7 @@ def generate_js(data_target, data_files, metadata):
# we need to find the datafile in the same dir as the html file

code += '''
if (!Module.preloadResults) Module.preloadResults = {};\n'''
if (!Module['preloadResults']) Module['preloadResults'] = {};\n'''

if options.use_preload_cache:
code += '''
Expand All @@ -1046,7 +1046,7 @@ def generate_js(data_target, data_files, metadata):
function(db) {
checkCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME,
function(useCached, metadata) {
Module.preloadResults[PACKAGE_NAME] = {fromCache: useCached};
Module['preloadResults'][PACKAGE_NAME] = {fromCache: useCached};
if (useCached) {
fetchCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME, metadata, processPackageData, preloadFallback);
} else {
Expand Down Expand Up @@ -1085,7 +1085,7 @@ def generate_js(data_target, data_files, metadata):
}, handleError);\n'''

code += '''
Module.preloadResults[PACKAGE_NAME] = {fromCache: false};
Module['preloadResults'][PACKAGE_NAME] = {fromCache: false};
if (fetched) {
processPackageData(fetched);
fetched = null;
Expand Down

0 comments on commit 03fca01

Please sign in to comment.