From a8fac76294083b38cb1ff42792fd8472566b0c5c Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 22 Jan 2024 21:48:20 +0000 Subject: [PATCH] Use single quotes in JS code where possible. NFC --- src/jsifier.js | 3 +++ src/library.js | 6 +++--- src/library_fs.js | 2 +- src/preamble.js | 14 +++++++------- src/shell.js | 10 +++++----- test/test_other.py | 4 ++-- tools/emscripten.py | 2 +- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/jsifier.js b/src/jsifier.js index e323b03b174bc..aa3ce00e3685f 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -461,6 +461,9 @@ function(${args}) { } } } else if (typeof snippet == 'object') { + if (typeof snippet == 'object') { + console.error(snippet); + } snippet = stringifyWithFunctions(snippet); addImplicitDeps(snippet, deps); } else if (typeof snippet == 'function') { diff --git a/src/library.js b/src/library.js index 74038b30bfd78..b64cca2ef1a8e 100644 --- a/src/library.js +++ b/src/library.js @@ -2187,9 +2187,9 @@ addToLibrary({ #endif // ENVIRONMENT_MAY_BE_NODE // we couldn't find a proper implementation, as Math.random() is not suitable for /dev/random, see emscripten-core/emscripten/pull/7096 #if ASSERTIONS - abort("no cryptographic support found for randomDevice. consider polyfilling it if you want to use something insecure like Math.random(), e.g. put this in a --pre-js: var crypto = { getRandomValues: (array) => { for (var i = 0; i < array.length; i++) array[i] = (Math.random()*256)|0 } };"); + abort('no cryptographic support found for randomDevice. consider polyfilling it if you want to use something insecure like Math.random(), e.g. put this in a --pre-js: var crypto = { getRandomValues: (array) => { for (var i = 0; i < array.length; i++) array[i] = (Math.random()*256)|0 } };'); #else - abort("initRandomDevice"); + abort('initRandomDevice'); #endif }, @@ -3198,7 +3198,7 @@ addToLibrary({ #endif } #if ASSERTIONS && ASYNCIFY != 2 // With JSPI the function stored in the table will be a wrapper. - assert(wasmTable.get(funcPtr) == func, "JavaScript-side Wasm function table mirror is out of date!"); + assert(wasmTable.get(funcPtr) == func, 'JavaScript-side Wasm function table mirror is out of date!'); #endif return func; }, diff --git a/src/library_fs.js b/src/library_fs.js index 92880694e80f2..f14e01e5e0b34 100644 --- a/src/library_fs.js +++ b/src/library_fs.js @@ -37,7 +37,7 @@ addToLibrary({ $FS__postset: function() { // TODO: do we need noFSInit? addAtInit(` -if (!Module["noFSInit"] && !FS.init.initialized) +if (!Module['noFSInit'] && !FS.init.initialized) FS.init(); FS.ignorePermissions = false; `) diff --git a/src/preamble.js b/src/preamble.js index ee38da9aa4d99..032eff4b8eeb8 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -95,13 +95,13 @@ function assert(condition, text) { // builds with assertions. #if !hasExportedSymbol('malloc') function _malloc() { - abort("malloc() called but not included in the build - add '_malloc' to EXPORTED_FUNCTIONS"); + abort('malloc() called but not included in the build - add `_malloc` to EXPORTED_FUNCTIONS'); } #endif // malloc #if !hasExportedSymbol('free') function _free() { // Show a helpful error since we used to include free by default in the past. - abort("free() called but not included in the build - add '_free' to EXPORTED_FUNCTIONS"); + abort('free() called but not included in the build - add `_free` to EXPORTED_FUNCTIONS'); } #endif // free #endif // ASSERTIONS @@ -641,9 +641,9 @@ function getBinarySync(file) { return readBinary(file); } #if WASM_ASYNC_COMPILATION - throw "both async and sync fetching of the wasm failed"; + throw 'both async and sync fetching of the wasm failed'; #else - throw "sync fetching of the wasm failed: you can preload it to Module['wasmBinary'] manually, or emcc.py will do that for you when generating HTML (but not JS)"; + throw 'sync fetching of the wasm failed: you can preload it to Module["wasmBinary"] manually, or emcc.py will do that for you when generating HTML (but not JS)'; #endif } @@ -666,7 +666,7 @@ function getBinaryPromise(binaryFile) { ) { return fetch(binaryFile, {{{ makeModuleReceiveExpr('fetchSettings', "{ credentials: 'same-origin' }") }}}).then((response) => { if (!response['ok']) { - throw "failed to load wasm binary file at '" + binaryFile + "'"; + throw `failed to load wasm binary file at '${binaryFile}'`; } return response['arrayBuffer'](); }).catch(() => getBinarySync(binaryFile)); @@ -982,7 +982,7 @@ function createWasm() { wasmMemory = wasmExports['memory']; {{{ receivedSymbol('wasmMemory') }}} #if ASSERTIONS - assert(wasmMemory, "memory not found in wasm exports"); + assert(wasmMemory, 'memory not found in wasm exports'); // This assertion doesn't hold when emscripten is run in --post-link // mode. // TODO(sbc): Read INITIAL_MEMORY out of the wasm file in post-link mode. @@ -998,7 +998,7 @@ function createWasm() { wasmTable = wasmExports['__indirect_function_table']; {{{ receivedSymbol('wasmTable') }}} #if ASSERTIONS && !PURE_WASI - assert(wasmTable, "table not found in wasm exports"); + assert(wasmTable, 'table not found in wasm exports'); #endif #if AUDIO_WORKLET diff --git a/src/shell.js b/src/shell.js index f42ddc86fe97b..3526116fe065a 100644 --- a/src/shell.js +++ b/src/shell.js @@ -382,7 +382,7 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { if (scriptDirectory.startsWith('blob:')) { scriptDirectory = ''; } else { - scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf('/')+1); + scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, '').lastIndexOf('/')+1); } #if ENVIRONMENT && ASSERTIONS @@ -492,19 +492,19 @@ assert( #endif // PTHREADS #if !ENVIRONMENT_MAY_BE_WEB -assert(!ENVIRONMENT_IS_WEB, "web environment detected but not enabled at build time. Add 'web' to `-sENVIRONMENT` to enable."); +assert(!ENVIRONMENT_IS_WEB, 'web environment detected but not enabled at build time. Add `web` to `-sENVIRONMENT` to enable.'); #endif #if !ENVIRONMENT_MAY_BE_WORKER -assert(!ENVIRONMENT_IS_WORKER, "worker environment detected but not enabled at build time. Add 'worker' to `-sENVIRONMENT` to enable."); +assert(!ENVIRONMENT_IS_WORKER, 'worker environment detected but not enabled at build time. Add `worker` to `-sENVIRONMENT` to enable.'); #endif #if !ENVIRONMENT_MAY_BE_NODE -assert(!ENVIRONMENT_IS_NODE, "node environment detected but not enabled at build time. Add 'node' to `-sENVIRONMENT` to enable."); +assert(!ENVIRONMENT_IS_NODE, 'node environment detected but not enabled at build time. Add `node` to `-sENVIRONMENT` to enable.'); #endif #if !ENVIRONMENT_MAY_BE_SHELL -assert(!ENVIRONMENT_IS_SHELL, "shell environment detected but not enabled at build time. Add 'shell' to `-sENVIRONMENT` to enable."); +assert(!ENVIRONMENT_IS_SHELL, 'shell environment detected but not enabled at build time. Add `shell` to `-sENVIRONMENT` to enable.'); #endif #endif // ASSERTIONS diff --git a/test/test_other.py b/test/test_other.py index b5a60047b0b09..437c88a9d829e 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -12087,8 +12087,8 @@ def test_missing_malloc_export(self): } ''') self.do_runf('unincluded_malloc.c', ( - "malloc() called but not included in the build - add '_malloc' to EXPORTED_FUNCTIONS", - "free() called but not included in the build - add '_free' to EXPORTED_FUNCTIONS")) + 'malloc() called but not included in the build - add `_malloc` to EXPORTED_FUNCTIONS', + 'free() called but not included in the build - add `_free` to EXPORTED_FUNCTIONS'), assert_all=True) def test_getrusage(self): self.do_runf('other/test_getrusage.c') diff --git a/tools/emscripten.py b/tools/emscripten.py index 37b9be8d2c86e..dd65254797943 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -801,7 +801,7 @@ def install_wrapper(sym): args = ', '.join(args) wrapper += f"({args}) => ({mangled} = {exported}wasmExports['{name}'])({args});" else: - wrapper += 'wasmExports["%s"]' % name + wrapper += f"wasmExports['{name}']" wrappers.append(wrapper) return wrappers