Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions src/cpuprofiler.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/emrun_postjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if (globalThis.window && globalThis.document && (typeof ENVIRONMENT_IS_PTHREAD =
http.onreadystatechange = () => {
if (http.readyState == 4 /*DONE*/) {
if (--emrun_num_post_messages_in_flight == 0 && emrun_should_close_itself) {
postExit('^exit^'+EXITSTATUS);
postExit(`^exit^${EXITSTATUS}`);
}
}
}
Expand All @@ -60,25 +60,25 @@ if (globalThis.window && globalThis.document && (typeof ENVIRONMENT_IS_PTHREAD =
var prevErr = err;
addOnExit(() => {
if (emrun_num_post_messages_in_flight == 0) {
postExit('^exit^'+EXITSTATUS);
postExit(`^exit^${EXITSTATUS}`);
} else {
emrun_should_close_itself = true;
}
});
out = (text) => {
post('stdio.html', '^out^'+(emrun_http_sequence_number++)+'^'+encodeURIComponent(text));
post('stdio.html', `^out^${emrun_http_sequence_number++}^${encodeURIComponent(text)}`);
prevPrint(text);
};
err = (text) => {
post('stdio.html', '^err^'+(emrun_http_sequence_number++)+'^'+encodeURIComponent(text));
post('stdio.html', `^err^${emrun_http_sequence_number++}^${encodeURIComponent(text)}`);
prevErr(text);
};
emrun_file_dump = (filename, data) => {
out(`Dumping out file "${filename}" with ${data.length} bytes of data.`);
if (ArrayBuffer.isView(data) && typeof SharedArrayBuffer !== "undefined" && data.buffer instanceof SharedArrayBuffer) {
data = new data.constructor(data); // Make a clone of the typed array of the same type, since http.send() does not allow SharedArrayBuffer backing.
}
post("stdio.html?file=" + filename, data);
post(`stdio.html?file=${filename}`, data);
};

// Notify emrun web server that this browser has successfully launched the
Expand Down
4 changes: 2 additions & 2 deletions src/gl-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ vec3.unproject = function (vec, view, proj, viewport, dest) {
* _returns {string} String representation of vec
*/
vec3.str = function (vec) {
return '[' + vec[0] + ', ' + vec[1] + ', ' + vec[2] + ']';
return `[${vec[0]}, ${vec[1]}, ${vec[2]}]`;
};

/*
Expand Down Expand Up @@ -1927,7 +1927,7 @@ quat4.slerp = function (quat, quat2, slerp, dest) {
* _returns {string} String representation of quat
*/
quat4.str = function (quat) {
return '[' + quat[0] + ', ' + quat[1] + ', ' + quat[2] + ', ' + quat[3] + ']';
return `[${quat[0]}, ${quat[1]}, ${quat[2]}, ${quat[3]}]`;
};


Expand Down
82 changes: 41 additions & 41 deletions src/jsifier.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function mangleCSymbolName(f) {
if (f === '__main_argc_argv') {
f = 'main';
}
return f[0] == '$' ? f.slice(1) : '_' + f;
return f[0] == '$' ? f.slice(1) : `_${f}`;
}

// Splits out items that pass filter. Returns also the original sans the filtered
Expand All @@ -73,8 +73,8 @@ function splitter(array, filter) {

function escapeJSONKey(x) {
if (/^[\d\w_]+$/.exec(x) || x[0] === '"' || x[0] === "'") return x;
assert(!x.includes("'"), 'cannot have internal single quotes in keys: ' + x);
return "'" + x + "'";
assert(!x.includes("'"), `cannot have internal single quotes in keys: ${x}`);
return `'${x}'`;
}

// JSON.stringify will completely omit function objects. This function is
Expand All @@ -83,7 +83,7 @@ function stringifyWithFunctions(obj) {
if (typeof obj == 'function') return obj.toString();
if (obj === null || typeof obj != 'object') return JSON.stringify(obj);
if (Array.isArray(obj)) {
return '[' + obj.map(stringifyWithFunctions).join(',') + ']';
return `[${obj.map(stringifyWithFunctions).join(',')}]`;
}

// preserve the type of the object if it is one of [Map, Set, WeakMap, WeakSet].
Expand All @@ -103,13 +103,13 @@ function stringifyWithFunctions(obj) {
var str = stringifyWithFunctions(value);
// Handle JS method syntax where the function property starts with its own
// name. e.g. `foo(a) {}` (or `async foo(a) {}`)
if (typeof value === 'function' && (str.startsWith(key) || str.startsWith('async ' + key))) {
rtn += str + ',\n';
if (typeof value === 'function' && (str.startsWith(key) || str.startsWith(`async ${key}`))) {
rtn += `${str},\n`;
} else {
rtn += `${escapeJSONKey(key)}:${str},\n`;
}
}
return rtn + '}';
return `${rtn}}`;
}

function isDefined(symName) {
Expand All @@ -135,7 +135,7 @@ function getTransitiveDeps(symbol) {
while (toVisit.length) {
const sym = toVisit.pop();
if (!seen.has(sym)) {
let directDeps = LibraryManager.library[sym + '__deps'] ?? [];
let directDeps = LibraryManager.library[`${sym}__deps`] ?? [];
directDeps = directDeps.filter((d) => typeof d === 'string');
for (const dep of directDeps) {
if (!transitiveDeps.has(dep)) {
Expand Down Expand Up @@ -251,8 +251,8 @@ function addImplicitDeps(snippet, deps) {
'setValue',
];
for (const dep of autoDeps) {
if (snippet.includes(dep + '(')) {
deps.push('$' + dep);
if (snippet.includes(`${dep}(`)) {
deps.push(`$${dep}`);
}
}
// If the snippet contains eval(), it may dynamically evaluate code loaded from memory at runtime
Expand All @@ -272,7 +272,7 @@ function addImplicitDeps(snippet, deps) {
];
for (const heap of heapDeps) {
if (snippet.includes(heap)) {
deps.push('$' + heap);
deps.push(`$${heap}`);
}
}
}
Expand Down Expand Up @@ -364,7 +364,7 @@ return ${makeReturn64(await_ + body)};
${async_}function(${args}) {
${argConversions}
var ret = (${orig_async_}() => { ${body} })();
return ${makeReturn64(await_ + 'ret')};
return ${makeReturn64(`${await_}ret`)};
}`;
}

Expand Down Expand Up @@ -432,7 +432,7 @@ export async function runJSify(outputFile, symbolsOnly) {
str = str.replaceAll('EMSCRIPTEN$IMPORT$META', 'import.meta');
}

await outputHandle.write(str + '\n');
await outputHandle.write(`${str}\n`);
}

const symbolsNeeded = DEFAULT_LIBRARY_FUNCS_TO_INCLUDE;
Expand All @@ -446,8 +446,8 @@ export async function runJSify(outputFile, symbolsOnly) {
addImplicitDeps(snippet, symbolsNeeded);
}
for (const sym of EXPORTED_RUNTIME_METHODS) {
if ('$' + sym in LibraryManager.library) {
symbolsNeeded.push('$' + sym);
if (`$${sym}` in LibraryManager.library) {
symbolsNeeded.push(`$${sym}`);
}
}

Expand All @@ -470,7 +470,7 @@ export async function runJSify(outputFile, symbolsOnly) {
// Is this a shorthand `foo() {}` method syntax?
// If so, prepend a function keyword so that it's valid syntax when extracted.
if (snippet.startsWith(symbol)) {
snippet = 'function ' + snippet;
snippet = `function ${snippet}`;
}

if (isStub) {
Expand All @@ -496,10 +496,10 @@ function(${args}) {
});
}

const sig = LibraryManager.library[symbol + '__sig'];
const isAsyncFunction = ASYNCIFY && LibraryManager.library[symbol + '__async'];
const sig = LibraryManager.library[`${symbol}__sig`];
const isAsyncFunction = ASYNCIFY && LibraryManager.library[`${symbol}__async`];

const i53abi = LibraryManager.library[symbol + '__i53abi'];
const i53abi = LibraryManager.library[`${symbol}__i53abi`];
if (i53abi) {
if (!sig) {
error(`JS library error: '__i53abi' decorator requires '__sig' decorator: '${symbol}'`);
Expand All @@ -516,7 +516,7 @@ function(${args}) {
compileTimeContext.i53ConversionDeps.forEach((d) => deps.push(d));
}

const proxyingMode = LibraryManager.library[symbol + '__proxy'];
const proxyingMode = LibraryManager.library[`${symbol}__proxy`];

if (ASYNCIFY && isAsyncFunction == 'auto') {
snippet = handleAsyncFunction(snippet, sig, proxyingMode == 'sync');
Expand All @@ -534,7 +534,7 @@ function(${args}) {
}
let proxyMode = PROXY_ASYNC;
if (proxyingMode === 'sync') {
const isAsyncFunction = LibraryManager.library[symbol + '__async'];
const isAsyncFunction = LibraryManager.library[`${symbol}__async`];
if (isAsyncFunction) {
proxyMode = PROXY_SYNC_ASYNC;
} else {
Expand All @@ -544,7 +544,7 @@ function(${args}) {
const rtnType = sig?.[0];
const proxyFunc =
MEMORY64 && rtnType == 'p' ? 'proxyToMainThreadPtr' : 'proxyToMainThread';
deps.push('$' + proxyFunc);
deps.push(`$${proxyFunc}`);
return `
${async_}function(${args}) {
if (ENVIRONMENT_IS_PTHREAD)
Expand Down Expand Up @@ -609,16 +609,16 @@ function(${args}) {
}
addedLibraryItems[symbol] = true;

const deps = LibraryManager.library[symbol + '__deps'] ??= [];
let sig = LibraryManager.library[symbol + '__sig'];
const deps = LibraryManager.library[`${symbol}__deps`] ??= [];
let sig = LibraryManager.library[`${symbol}__sig`];
if (!WASM_BIGINT && sig && sig[0] == 'j') {
// Without WASM_BIGINT functions that return i64 depend on setTempRet0
// to return the upper 32-bits of the result.
// See makeReturn64 in parseTools.py.
deps.push('setTempRet0');
}

const isAsyncFunction = LibraryManager.library[symbol + '__async'];
const isAsyncFunction = LibraryManager.library[`${symbol}__async`];
if (ASYNCIFY && isAsyncFunction) {
asyncFuncs.push(symbol);
}
Expand Down Expand Up @@ -652,7 +652,7 @@ function(${args}) {
if (symbol === '__main_argc_argv') {
undefinedSym = 'main/__main_argc_argv';
}
let msg = 'undefined symbol: ' + undefinedSym;
let msg = `undefined symbol: ${undefinedSym}`;
if (dependent) msg += ` (referenced by ${dependent})`;
if (ERROR_ON_UNDEFINED_SYMBOLS) {
error(msg);
Expand Down Expand Up @@ -689,40 +689,40 @@ function(${args}) {
if (ASSERTIONS) {
assertion += `if (!${target} || ${target}.stub) abort("external symbol '${symbol}' is missing. perhaps a side module was not linked in? if this function was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment");\n`;
}
stubFunctionBody = assertion + `return ${target}(...args);`;
stubFunctionBody = `${assertion}return ${target}(...args);`;
}
isStub = true;
LibraryManager.library[symbol] = new Function('...args', stubFunctionBody);
}

librarySymbols.push(mangled);

if (!isStub && LibraryManager.library[symbol + '__export']) {
if (!isStub && LibraryManager.library[`${symbol}__export`]) {
extraExports.add(mangled);
}

const original = LibraryManager.library[symbol];
let snippet = original;
const isUserSymbol = LibraryManager.library[symbol + '__user'];
const isUserSymbol = LibraryManager.library[`${symbol}__user`];
// Check for dependencies on `__internal` symbols from user libraries.
for (const dep of deps) {
if (isUserSymbol && LibraryManager.library[dep + '__internal']) {
if (isUserSymbol && LibraryManager.library[`${dep}__internal`]) {
warn(`user library symbol '${symbol}' depends on internal symbol '${dep}'`);
}
}

let isFunction = typeof snippet == 'function';
let isNativeAlias = false;

const postsetId = symbol + '__postset';
const postsetId = `${symbol}__postset`;
const postset = LibraryManager.library[postsetId];
if (postset) {
// A postset is either code to run right now, or some text we should emit.
// If it's code, it may return some text to emit as well.
const postsetString = typeof postset == 'function' ? postset() : postset;
if (postsetString && !addedLibraryItems[postsetId]) {
addedLibraryItems[postsetId] = true;
postSets.push(postsetString + ';');
postSets.push(`${postsetString};`);
}
}

Expand All @@ -745,7 +745,7 @@ function(${args}) {
// it's target) we need to construct a forwarding function from
// one to the other.
const isSigRelevant = MAIN_MODULE || MEMORY64 || CAN_ADDRESS_2GB || sig?.includes('j');
const targetSig = LibraryManager.library[aliasTarget + '__sig'];
const targetSig = LibraryManager.library[`${aliasTarget}__sig`];
if (isSigRelevant && sig && targetSig && sig != targetSig) {
debugLog(`${symbol}: Alias target (${aliasTarget}) has different signature (${sig} vs ${targetSig})`)
isFunction = true;
Expand Down Expand Up @@ -785,7 +785,7 @@ function(${args}) {
let contentText;
if (isFunction) {
// Emit the body of a JS library function.
if ((USE_ASAN || USE_LSAN) && LibraryManager.library[symbol + '__noleakcheck']) {
if ((USE_ASAN || USE_LSAN) && LibraryManager.library[`${symbol}__noleakcheck`]) {
contentText = modifyJSFunction(
snippet,
(args, body) => `(${args}) => noLeakCheck(() => {${body}})`,
Expand All @@ -799,7 +799,7 @@ function(${args}) {
// modifyJSFunction which could have changed or removed the name.
if (contentText.match(/^\s*([^}]*)\s*=>/s)) {
// Handle arrow functions
contentText = `var ${mangled} = ` + contentText + ';';
contentText = `var ${mangled} = ${contentText};`;
} else if (contentText.startsWith('class ')) {
// Handle class declarations (which also have typeof == 'function'.)
contentText = contentText.replace(/^class(?:\s+(?!extends\b)[^{\s]+)?/, `class ${mangled}`);
Expand All @@ -812,7 +812,7 @@ function(${args}) {
// foo: ';[code here verbatim]'
// emits
// 'var foo;[code here verbatim];'
contentText = 'var ' + mangled + snippet;
contentText = `var ${mangled}${snippet}`;
if (snippet[snippet.length - 1] != ';' && snippet[snippet.length - 1] != '}') {
contentText += ';';
}
Expand Down Expand Up @@ -840,7 +840,7 @@ function(${args}) {
if (contentText && MODULARIZE == 'instance' && (EXPORT_ALL || EXPORTED_FUNCTIONS.has(mangled) || extraExports.has(mangled)) && !isStub) {
// In MODULARIZE=instance mode mark JS library symbols are exported at
// the point of declaration.
contentText = 'export ' + contentText;
contentText = `export ${contentText}`;
}

// Dynamic linking needs signatures to create proper wrappers.
Expand All @@ -863,10 +863,10 @@ function(${args}) {

// Add the docs if they exist and if we are actually emitting a declaration.
// See the TODO about wasmTable above.
let docs = LibraryManager.library[symbol + '__docs'];
let docs = LibraryManager.library[`${symbol}__docs`];
let commentText = '';
if (contentText != '' && docs) {
commentText += docs + '\n';
commentText += `${docs}\n`;
}

if (EMIT_TSD) {
Expand All @@ -877,10 +877,10 @@ function(${args}) {
}

const depsText = deps
? deps
? `${deps
.map(addDependency)
.filter((x) => x != '')
.join('\n') + '\n'
.join('\n')}\n`
: '';
return depsText + commentText + contentText;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libaddfunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ addToLibrary({
throw err;
}
#if ASSERTIONS
assert(typeof sig != 'undefined', 'Missing signature argument to addFunction: ' + func);
assert(typeof sig != 'undefined', `Missing signature argument to addFunction: ${func}`);
#endif
var wrapped = convertJsFunctionToWasm(func, sig);
setWasmTableEntry(ret, wrapped);
Expand Down
Loading
Loading