Skip to content
Open
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
5 changes: 5 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export default [{
'arrow-body-style': ['error', 'as-needed'],
'space-infix-ops': 'error',
'prefer-object-has-own': 'error',
'prefer-exponentiation-operator': 'error',
'prefer-object-spread': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'logical-assignment-operators': ['error', 'always'],

quotes: ['error', 'single', {
avoidEscape: true,
Expand Down
2 changes: 1 addition & 1 deletion src/deterministic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

let MAGIC = 0;
Math.random = () => {
MAGIC = Math.pow(MAGIC + 1.8912, 3) % 1;
MAGIC = ((MAGIC + 1.8912) ** 3) % 1;
return MAGIC;
};

Expand Down
4 changes: 2 additions & 2 deletions src/jsifier.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ export async function runJSify(outputFile, symbolsOnly) {
}
return `\
function(${args}) {
dbg("[library call:${mangled}: " + Array.prototype.slice.call(arguments).map(prettyPrint) + "]");
dbg("[library call:${mangled}: " + Array.from(arguments, prettyPrint) + "]");
${run_func}
dbg(" [ return:" + prettyPrint(ret));
return ret;
Expand Down Expand Up @@ -1023,7 +1023,7 @@ function(${args}) {
// emits
// 'var foo;[code here verbatim];'
contentText = 'var ' + mangled + snippet;
if (snippet[snippet.length - 1] != ';' && snippet[snippet.length - 1] != '}') {
if (snippet.at(-1) != ';' && snippet.at(-1) != '}') {
contentText += ';';
}
} else if (typeof snippet === 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ var LibraryBrowser = {

#if MIN_SAFARI_VERSION < 160400
var CFS = document.exitFullscreen ?? document['webkitCancelFullScreen'];
CFS.apply(document, []);
CFS.call(document);
#else
document.exitFullscreen();
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2525,7 +2525,7 @@ function wrapSyscallFunction(x, library, isWasi) {
post += 'SYSCALLS.varargs = undefined;\n';
}
}
pre += `dbg('syscall! ${x}: [' + Array.prototype.slice.call(arguments) + ']');\n`;
pre += `dbg('syscall! ${x}: [' + Array.from(arguments) + ']');\n`;
pre += 'var canWarn = true;\n';
pre += 'var ret = (() => {';
post += '})();\n';
Expand Down
8 changes: 3 additions & 5 deletions src/lib/libdylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ var LibraryDylink = {
}

#if ASSERTIONS
var tableAlign = Math.pow(2, customSection.tableAlign);
var tableAlign = 2 ** customSection.tableAlign;
assert(tableAlign === 1, `invalid tableAlign ${tableAlign}`);
assert(offset == end);
#endif
Expand All @@ -554,9 +554,7 @@ var LibraryDylink = {
for (var [sym, exp] of Object.entries(exports)) {
if (sym.startsWith('dynCall_')) {
var sig = sym.substring(8);
if (!hasOwn(dynCalls, sig)) {
dynCalls[sig] = exp;
}
dynCalls[sig] ??= exp;
}
}
},
Expand Down Expand Up @@ -719,7 +717,7 @@ var LibraryDylink = {
if (firstLoad) {
#endif
// alignments are powers of 2
var memAlign = Math.pow(2, metadata.memoryAlign);
var memAlign = 2 ** metadata.memoryAlign;
// prepare memory
var memoryBase = metadata.memorySize ? alignMemory(getMemory(metadata.memorySize + memAlign), memAlign) : 0; // TODO: add to cleanups
var tableBase = metadata.tableSize ? {{{ from64Expr('wasmTable.length') }}} : 0;
Expand Down
14 changes: 6 additions & 8 deletions src/lib/libembind.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var LibraryEmbind = {
// Inject an overload resolver function that routes to the appropriate overload based on the number of arguments.
proto[methodName] = function(...args) {
// TODO This check can be removed in -O3 level "unsafe" optimizations.
if (!hasOwn(proto[methodName].overloadTable, args.length)) {
if (!proto[methodName].overloadTable[args.length]) {
throwBindingError(`Function '${humanName}' called with an invalid number of arguments (${args.length}) - expects one of (${proto[methodName].overloadTable})!`);
}
return proto[methodName].overloadTable[args.length].apply(this, args);
Expand Down Expand Up @@ -91,7 +91,7 @@ var LibraryEmbind = {
// We are exposing a function with the same name as an existing function. Create an overload table and a function selector
// that routes between the two.
ensureOverloadTable(Module, name, name);
if (hasOwn(Module[name].overloadTable, numArguments)) {
if (Module[name].overloadTable[numArguments]) {
throwBindingError(`Cannot register multiple overloads of a function with the same number of arguments (${numArguments})!`);
}
// Add the new function into the overload table.
Expand Down Expand Up @@ -144,7 +144,7 @@ var LibraryEmbind = {

$registerInheritedInstance: (class_, ptr, instance) => {
ptr = getBasestPointer(class_, ptr);
if (hasOwn(registeredInstances, ptr)) {
if (registeredInstances[ptr]) {
throwBindingError(`Tried to register registered instance: ${ptr}`);
} else {
registeredInstances[ptr] = instance;
Expand All @@ -153,7 +153,7 @@ var LibraryEmbind = {

$unregisterInheritedInstance: (class_, ptr) => {
ptr = getBasestPointer(class_, ptr);
if (hasOwn(registeredInstances, ptr)) {
if (registeredInstances[ptr]) {
delete registeredInstances[ptr];
} else {
throwBindingError(`Tried to unregister unregistered instance: ${ptr}`);
Expand Down Expand Up @@ -1972,10 +1972,8 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence

if (classType.registeredClass.__derivedClasses) {
for (const derivedClass of classType.registeredClass.__derivedClasses) {
if (!hasOwn(derivedClass.constructor, methodName)) {
// TODO: Add support for overloads
derivedClass.constructor[methodName] = func;
}
// TODO: Add support for overloads
derivedClass.constructor[methodName] ??= func;
Comment thread
sbc100 marked this conversation as resolved.
Resolved
}
}

Expand Down
11 changes: 4 additions & 7 deletions src/lib/libembind_shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var LibraryEmbindShared = {
if (!rawType) {
throwBindingError(`type "${name}" must have a positive integer typeid pointer`);
}
if (hasOwn(registeredTypes, rawType)) {
if (registeredTypes[rawType]) {
if (options.ignoreDuplicateRegistrations) {
return;
} else {
Expand All @@ -50,7 +50,7 @@ var LibraryEmbindShared = {
registeredTypes[rawType] = registeredInstance;
delete typeDependencies[rawType];

if (hasOwn(awaitingDependencies, rawType)) {
if (awaitingDependencies[rawType]) {
var callbacks = awaitingDependencies[rawType];
delete awaitingDependencies[rawType];
callbacks.forEach((cb) => cb());
Expand All @@ -74,14 +74,11 @@ var LibraryEmbindShared = {
var unregisteredTypes = [];
var registered = 0;
for (let [i, dt] of dependentTypes.entries()) {
if (hasOwn(registeredTypes, dt)) {
if (registeredTypes[dt]) {
typeConverters[i] = registeredTypes[dt];
} else {
unregisteredTypes.push(dt);
if (!hasOwn(awaitingDependencies, dt)) {
awaitingDependencies[dt] = [];
}
awaitingDependencies[dt].push(() => {
(awaitingDependencies[dt] ??= []).push(() => {
typeConverters[i] = registeredTypes[dt];
++registered;
if (registered === unregisteredTypes.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libemval.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ ${functionBody}
var rv;
switch (kind) {
case {{{ cDefs['internal::EM_INVOKER_KIND::FUNCTION'] }}}:
rv = Emval.toValue(handle).apply(null, argN);
rv = Emval.toValue(handle)(...argN);
break;
case {{{ cDefs['internal::EM_INVOKER_KIND::CONSTRUCTOR'] }}}:
rv = Reflect.construct(Emval.toValue(handle), argN);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libglemu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3542,7 +3542,7 @@ var LibraryGLEmulation = {
GLImmediate.matricesModified = true;
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
GLImmediate.matrixStack[GLImmediate.currentMatrix].push(
Array.prototype.slice.call(GLImmediate.matrix[GLImmediate.currentMatrix]));
GLImmediate.matrix[GLImmediate.currentMatrix].slice());
},

glPopMatrix: () => {
Expand Down Expand Up @@ -3570,7 +3570,7 @@ var LibraryGLEmulation = {

glLoadMatrixf: (matrix) => {
#if GL_DEBUG
if (GL.debug) dbg('glLoadMatrixf receiving: ' + Array.prototype.slice.call(HEAPF32.subarray(matrix >> 2, (matrix >> 2) + 16)));
if (GL.debug) dbg('glLoadMatrixf receiving: ' + HEAPF32.subarray(matrix >> 2, (matrix >> 2) + 16));
#endif
GLImmediate.matricesModified = true;
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
Expand Down
20 changes: 10 additions & 10 deletions src/lib/libglfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,28 +884,28 @@ var LibraryGLFW = {
}

if (DataTransferItem.prototype.webkitGetAsEntry) {
let entriesTree = {};
let entriesTree = new Map();
function markDone(fullpath, recursive) {
if (entriesTree[fullpath].subpaths.length != 0) return;
delete entriesTree[fullpath];
if (entriesTree.get(fullpath).subpaths.length != 0) return;
entriesTree.delete(fullpath);
let parentpath = fullpath.substring(0, fullpath.lastIndexOf('/'));
if (!hasOwn(entriesTree, parentpath)) {
if (Object.keys(entriesTree).length == 0) finalize();
if (!entriesTree.has(parentpath)) {
if (entriesTree.size == 0) finalize();
return;
}
const fpIndex = entriesTree[parentpath].subpaths.indexOf(fullpath);
if (fpIndex > -1) entriesTree[parentpath].subpaths.splice(fpIndex, 1);
const fpIndex = entriesTree.get(parentpath).subpaths.indexOf(fullpath);
if (fpIndex > -1) entriesTree.get(parentpath).subpaths.splice(fpIndex, 1);
if (recursive) markDone(parentpath, true);
if (Object.keys(entriesTree).length == 0) finalize();
if (entriesTree.size == 0) finalize();
}
function processEntry(entry) {
let fp = entry.fullPath;
let pp = fp.substring(0, fp.lastIndexOf('/'));
entriesTree[fp] = { subpaths: [] };
entriesTree.set(fp, { subpaths: [] });
if (entry.isFile) {
entry.file((f) => { filesQ.push({ file: f, path: pp }); markDone(fp, false); })
} else if (entry.isDirectory) {
if (hasOwn(entriesTree, pp)) entriesTree[pp].subpaths.push(fp);
if (entriesTree.has(pp)) entriesTree.get(pp).subpaths.push(fp);
FS.createPath('/' + drop_dir + pp, entry.name);
var reader = entry.createReader();
var rRead = function (dirEntries) {
Expand Down
10 changes: 1 addition & 9 deletions src/lib/liblegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,7 @@ legacyFuncs = {
#if EMBIND
$getInheritedInstanceCount: () => Object.keys(registeredInstances).length,

$getLiveInheritedInstances: () => {
var rv = [];
for (var k in registeredInstances) {
if (hasOwn(registeredInstances, k)) {
rv.push(registeredInstances[k]);
}
}
return rv;
},
$getLiveInheritedInstances: () => Object.values(registeredInstances),
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib/libmemfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ addToLibrary({
if (contents.subarray) {
contents = contents.subarray(position, position + length);
} else {
contents = Array.prototype.slice.call(contents, position, position + length);
contents = contents.slice(position, position + length);
}
}
HEAP8.set(contents, ptr);
Expand Down
7 changes: 2 additions & 5 deletions src/lib/libsdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ var LibrarySDL = {
var srcData = SDL.surfaces[src];
var w = srcData.width * zoom;
var h = srcData.height * zoom;
var diagonal = Math.ceil(Math.sqrt(Math.pow(w, 2) + Math.pow(h, 2)));
var diagonal = Math.ceil(Math.hypot(w, h));
var ret = SDL.makeSurface(diagonal, diagonal, srcData.flags, false, 'rotozoomSurface');
var dstData = SDL.surfaces[ret];
dstData.ctx.translate(diagonal / 2, diagonal / 2);
Expand Down Expand Up @@ -3354,10 +3354,7 @@ var LibrarySDL = {
var gamepad = SDL.getGamepad(deviceIndex);
if (gamepad) {
var name = gamepad.id;
if (hasOwn(SDL.joystickNamePool, name)) {
return SDL.joystickNamePool[name];
}
return SDL.joystickNamePool[name] = stringToNewUTF8(name);
return SDL.joystickNamePool[name] ??= stringToNewUTF8(name);
Comment thread
sbc100 marked this conversation as resolved.
Resolved
}
return 0;
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libwasmfs_fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ addToLibrary({
var url = '';
var fileUrl_p = __wasmfs_fetch_get_file_url(file);
var fileUrl = UTF8ToString(fileUrl_p);
var isAbs = fileUrl.indexOf('://') !== -1;
var isAbs = fileUrl.includes('://');
if (isAbs) {
url = fileUrl;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libwebgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3149,7 +3149,7 @@ for (let i = 0; i <= GL_POOL_TEMP_BUFFERS_SIZE; ++i) {
#if GL_TRACK_ERRORS
var bindingsType = 0x8872/*GL_MAX_TEXTURE_IMAGE_UNITS*/;
#endif
if (bindingMatch[3] && bindingMatch[2].indexOf('sampler') != -1) {
if (bindingMatch[3] && bindingMatch[2].includes('sampler')) {
samplerBindings[bindingMatch[3]] = [binding, arrayLength];
} else {
#if GL_TRACK_ERRORS
Expand Down
2 changes: 1 addition & 1 deletion src/parseTools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function preprocess(filename) {
let inStyle = false;
const lines = text.split('\n');
// text.split yields an extra empty element at the end if text itself ends with a newline.
if (!lines[lines.length - 1]) {
if (!lines.at(-1)) {
lines.pop();
}

Expand Down
2 changes: 1 addition & 1 deletion src/postamble_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ null;
#endif
// WebAssembly compilation failed, try running the JS fallback instead.
var search = location.search;
if (search.indexOf('_rwasm=0') < 0) {
if (!search.includes('_rwasm=0')) {
location.href += (search ? search + '&' : '?') + '_rwasm=0';
}
#if ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
Expand Down
2 changes: 1 addition & 1 deletion src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ async function instantiateArrayBuffer(binaryFile, imports) {
#endif
// WebAssembly compilation failed, try running the JS fallback instead.
var search = location.search;
if (search.indexOf('_rwasm=0') < 0) {
if (!search.includes('_rwasm=0')) {
// Reload the page with the `_rwasm=0` argument
location.href += (search ? search + '&' : '?') + '_rwasm=0';
// Return a promise that never resolves. We don't want to
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ function prettyPrint(arg) {
if (arg.toString() == '[object HTMLImageElement]') {
return arg + '\n\n';
}
if (arg.byteLength) {
return '{' + Array.prototype.slice.call(arg, 0, Math.min(arg.length, 400)) + '}';
if (arg.subarray) {
return '{' + arg.subarray(0, 400) + '}';
}
if (typeof arg === 'function') {
return '<function>';
Expand Down
4 changes: 2 additions & 2 deletions src/utility.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function popCurrentFile() {

function errorPrefix(lineNo) {
if (!currentFile.length) return '';
const filename = currentFile[currentFile.length - 1];
const filename = currentFile.at(-1);
if (lineNo) {
return `${filename}:${lineNo}: `;
} else {
Expand Down Expand Up @@ -313,7 +313,7 @@ class Profiler {

terminate() {
while (this.ids.length) {
const lastID = this.ids[this.ids.length - 1][0];
const lastID = this.ids.at(-1)[0];
this.stop(lastID);
}
// const overall = performance.now() - this.startTime
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_ctors1.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19093,
"a.out.js.gz": 8090,
"a.out.js": 19070,
"a.out.js.gz": 8074,
"a.out.nodebug.wasm": 133990,
"a.out.nodebug.wasm.gz": 51234,
"total": 153083,
"total_gz": 59324,
"total": 153060,
"total_gz": 59308,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_ctors2.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19070,
"a.out.js.gz": 8074,
"a.out.js": 19047,
"a.out.js.gz": 8058,
"a.out.nodebug.wasm": 133418,
"a.out.nodebug.wasm.gz": 50931,
"total": 152488,
"total_gz": 59005,
"total": 152465,
"total_gz": 58989,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
Loading
Loading