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
42 changes: 21 additions & 21 deletions src/lib/libfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ FS.staticInit();`;
devices: {},
streams: [],
nextInode: 1,
nameTable: null,
nameTable: [],
currentPath: '/',
initialized: false,
// Whether we are currently ignoring permissions. Useful when preparing the
Expand Down Expand Up @@ -373,7 +373,7 @@ FS.staticInit();`;
// if we failed to find it in the cache, call into the VFS
return FS.lookup(parent, name);
},
createNode(parent, name, mode, rdev) {
createNode(parent, name, mode, rdev = undefined) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This increases code size, doesn't it? Or does it get optimized out somehow?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think overall this change is a slight codesize win. I think because closure can eliminate these

#if ASSERTIONS
assert(typeof parent == 'object')
#endif
Expand Down Expand Up @@ -815,7 +815,7 @@ FS.staticInit();`;
return FS.mknod(path, mode, 0);
},
// Creates a whole directory tree chain if it doesn't yet exist
mkdirTree(path, mode) {
mkdirTree(path, mode = 0o777) {
var dirs = path.split('/');
var d = '';
for (var dir of dirs) {
Expand All @@ -829,7 +829,7 @@ FS.staticInit();`;
}
}
},
mkdev(path, mode, dev) {
mkdev(path, mode, dev = undefined) {
if (typeof dev == 'undefined') {
dev = mode;
mode = 0o666;
Expand Down Expand Up @@ -1040,7 +1040,7 @@ FS.staticInit();`;
}
return link.node_ops.readlink(link);
},
stat(path, dontFollow) {
stat(path, dontFollow = false) {
var lookup = FS.lookupPath(path, { follow: !dontFollow });
var node = lookup.node;
var getattr = FS.checkOpExists(node.node_ops.getattr, {{{ cDefs.EPERM }}});
Expand All @@ -1058,14 +1058,14 @@ FS.staticInit();`;
lstat(path) {
return FS.stat(path, true);
},
doChmod(stream, node, mode, dontFollow) {
doChmod(stream, node, mode, dontFollow = false) {
FS.doSetAttr(stream, node, {
mode: (mode & {{{ cDefs.S_IALLUGO }}}) | (node.mode & ~{{{ cDefs.S_IALLUGO }}}),
ctime: Date.now(),
dontFollow
});
},
chmod(path, mode, dontFollow) {
chmod(path, mode, dontFollow = false) {
var node;
if (typeof path == 'string') {
var lookup = FS.lookupPath(path, { follow: !dontFollow });
Expand All @@ -1082,14 +1082,14 @@ FS.staticInit();`;
var stream = FS.getStreamChecked(fd);
FS.doChmod(stream, stream.node, mode, false);
},
doChown(stream, node, dontFollow) {
doChown(stream, node, dontFollow = false) {
FS.doSetAttr(stream, node, {
timestamp: Date.now(),
dontFollow
// we ignore the uid / gid for now
});
},
chown(path, uid, gid, dontFollow) {
chown(path, uid, gid, dontFollow = false) {
var node;
if (typeof path == 'string') {
var lookup = FS.lookupPath(path, { follow: !dontFollow });
Expand Down Expand Up @@ -1142,7 +1142,7 @@ FS.staticInit();`;
}
FS.doTruncate(stream, stream.node, len);
},
utime(path, atime, mtime, dontFollow) {
utime(path, atime, mtime, dontFollow = false) {
var lookup = FS.lookupPath(path, { follow: !dontFollow });
FS.doSetAttr(null, lookup.node, {
atime: atime,
Expand Down Expand Up @@ -1305,7 +1305,7 @@ FS.staticInit();`;
#endif
return stream.position;
},
read(stream, buffer, offset, length, position) {
read(stream, buffer, offset, length, position = undefined) {
#if ASSERTIONS
assert(offset >= 0);
#endif
Expand Down Expand Up @@ -1342,7 +1342,7 @@ FS.staticInit();`;
/**
* @param {TypedArray} buffer
*/
write(stream, buffer, offset, length, position, canOwn) {
write(stream, buffer, offset, length, position = undefined, canOwn = undefined) {
#if ASSERTIONS
assert(offset >= 0);
assert(buffer.subarray, 'FS.write expects a TypedArray');
Expand Down Expand Up @@ -1575,7 +1575,7 @@ FS.staticInit();`;
#endif
},
staticInit() {
FS.nameTable = new Array(4096);
FS.nameTable.length = 4096;

FS.mount(MEMFS, {}, '/');

Expand All @@ -1599,7 +1599,7 @@ FS.staticInit();`;
#endif
};
},
init(input, output, error) {
init(input = undefined, output = undefined, error = undefined) {
#if ASSERTIONS
assert(!FS.initialized, 'FS.init was previously called. If you want to initialize later with custom parameters, remove any earlier calls (note that one is automatically added to the generated code)');
#endif
Expand Down Expand Up @@ -1635,14 +1635,14 @@ FS.staticInit();`;
//
// old v1 compatibility functions
//
findObject(path, dontResolveLastLink) {
findObject(path, dontResolveLastLink = false) {
var ret = FS.analyzePath(path, dontResolveLastLink);
if (!ret.exists) {
return null;
}
return ret.object;
},
analyzePath(path, dontResolveLastLink) {
analyzePath(path, dontResolveLastLink = false) {
// operate from within the context of the symlink's target
try {
var lookup = FS.lookupPath(path, { follow: !dontResolveLastLink });
Expand Down Expand Up @@ -1670,7 +1670,7 @@ FS.staticInit();`;
};
return ret;
},
createPath(parent, path, canRead, canWrite) {
createPath(parent, path, canRead = undefined, canWrite = undefined) {
parent = typeof parent == 'string' ? parent : FS.getPath(parent);
var parts = path.split('/').reverse();
while (parts.length) {
Expand All @@ -1686,15 +1686,15 @@ FS.staticInit();`;
}
return current;
},
createFile(parent, name, properties, canRead, canWrite) {
createFile(parent, name, properties, canRead = undefined, canWrite = undefined) {
var path = PATH.join2(typeof parent == 'string' ? parent : FS.getPath(parent), name);
var mode = FS_getMode(canRead, canWrite);
return FS.create(path, mode);
},
/**
* @param {TypedArray|Array|string=} data
*/
createDataFile(parent, name, data, canRead, canWrite, canOwn) {
createDataFile(parent, name, data = undefined, canRead = undefined, canWrite = undefined, canOwn = undefined) {
var path = name;
if (parent) {
parent = typeof parent == 'string' ? parent : FS.getPath(parent);
Expand All @@ -1712,7 +1712,7 @@ FS.staticInit();`;
FS.chmod(node, mode);
}
},
createDevice(parent, name, input, output) {
createDevice(parent, name, input = undefined, output = undefined) {
var path = PATH.join2(typeof parent == 'string' ? parent : FS.getPath(parent), name);
var mode = FS_getMode(!!input, !!output);
FS.createDevice.major ??= 64;
Expand Down Expand Up @@ -1789,7 +1789,7 @@ FS.staticInit();`;
// Creates a file record for lazy-loading from a URL. XXX This requires a synchronous
// XHR, which is not possible in browsers except in a web worker! Use preloading,
// either --preload-file in emcc or FS.createPreloadedFile
createLazyFile(parent, name, url, canRead, canWrite) {
createLazyFile(parent, name, url, canRead = undefined, canWrite = undefined) {
// Lazy chunked Uint8Array (implements get and length from Uint8Array).
// Actual getting is abstracted away for eventual reuse.
class LazyUint8Array {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libmemfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ addToLibrary({
mount(mount) {
return MEMFS.createNode(null, '/', {{{ cDefs.S_IFDIR | 0o777 }}}, 0);
},
createNode(parent, name, mode, dev) {
createNode(parent, name, mode, dev = undefined) {
if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
// not supported
throw new FS.ErrnoError({{{ cDefs.EPERM }}});
Expand Down Expand Up @@ -186,7 +186,7 @@ addToLibrary({
throw MEMFS.doesNotExistError;
#endif
},
mknod(parent, name, mode, dev) {
mknod(parent, name, mode, dev = undefined) {
return MEMFS.createNode(parent, name, mode, dev);
},
rename(old_node, new_dir, new_name) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/libnodefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ addToLibrary({
#endif
return NODEFS.createNode(null, '/', NODEFS.getMode(mount.opts.root), 0);
},
createNode(parent, name, mode, dev) {
createNode(parent, name, mode, dev = undefined) {
if (!FS.isDir(mode) && !FS.isFile(mode) && !FS.isLink(mode)) {
throw new FS.ErrnoError({{{ cDefs.EINVAL }}});
}
Expand Down Expand Up @@ -200,7 +200,7 @@ addToLibrary({
var mode = NODEFS.getMode(path);
return NODEFS.createNode(parent, name, mode);
},
mknod(parent, name, mode, dev) {
mknod(parent, name, mode, dev = undefined) {
var node = NODEFS.createNode(parent, name, mode, dev);
// create the backing node for this in the fs root as well
var path = NODEFS.realPath(node);
Expand Down Expand Up @@ -314,7 +314,7 @@ addToLibrary({
return { ptr, allocated: true };
},
msync(stream, buffer, offset, length, mmapFlags) {
NODEFS.stream_ops.write(stream, buffer, 0, length, offset, false);
NODEFS.stream_ops.write(stream, buffer, 0, length, offset);
// should we check if bytesWritten and length are the same?
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/libnoderawfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ addToLibrary({
readdir(...args) { return ['.', '..'].concat(fs.readdirSync(...args)); },
unlink(...args) { fs.unlinkSync(...args); },
readlink(...args) { return fs.readlinkSync(...args); },
stat(path, dontFollow) {
stat(path, dontFollow = false) {
var stat = dontFollow ? fs.lstatSync(path) : fs.statSync(path);
if (NODEFS.isWindows) {
// Windows does not report the 'x' permission bit, so propagate read
Expand Down Expand Up @@ -133,7 +133,7 @@ addToLibrary({
statfsStream(stream) {
return FS.statfs(stream.path);
},
chmod(path, mode, dontFollow) {
chmod(path, mode, dontFollow = false) {
mode &= {{{ cDefs.S_IALLUGO }}};
if (NODEFS.isWindows) {
// Windows only supports S_IREAD / S_IWRITE (S_IRUSR / S_IWUSR)
Expand Down Expand Up @@ -171,7 +171,7 @@ addToLibrary({
var stream = FS.getStreamChecked(fd);
fs.ftruncateSync(stream.nfd, len);
},
utime(path, atime, mtime, dontFollow) {
utime(path, atime, mtime, dontFollow = false) {
// null here for atime or mtime means UTIME_OMIT was passed. Since node
// doesn't support this concept we need to first find the existing
// timestamps in order to preserve them.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libsockfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ addToLibrary({
// these functions aren't actually sock_ops members, but we're
// abusing the namespace to organize them
//
createPeer(sock, addr, port) {
createPeer(sock, addr, port = undefined) {
var ws;

if (typeof addr == 'object') {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libsyscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var SyscallsLibrary = {
// global constants

// shared utilities
calculateAt(dirfd, path, allowEmpty) {
calculateAt(dirfd, path, allowEmpty = false) {
if (PATH.isAbs(path)) {
return path;
}
Expand Down Expand Up @@ -947,7 +947,7 @@ var SyscallsLibrary = {
path = SYSCALLS.getStr(path);
path = SYSCALLS.calculateAt(dirfd, path);
mode &= ~SYSCALLS.currentUmask;
FS.mkdir(path, mode, 0);
FS.mkdir(path, mode);
return 0;
},
__syscall_mknodat: (dirfd, path, mode, dev) => {
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": 19224,
"a.out.js.gz": 8124,
"a.out.js": 19218,
"a.out.js.gz": 8121,
"a.out.nodebug.wasm": 133971,
"a.out.nodebug.wasm.gz": 51271,
"total": 153195,
"total_gz": 59395,
"total": 153189,
"total_gz": 59392,
"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": 19201,
"a.out.js.gz": 8107,
"a.out.js": 19195,
"a.out.js.gz": 8105,
"a.out.nodebug.wasm": 133403,
"a.out.nodebug.wasm.gz": 50959,
"total": 152604,
"total_gz": 59066,
"total": 152598,
"total_gz": 59064,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 22917,
"a.out.js.gz": 9082,
"a.out.js": 22911,
"a.out.js.gz": 9079,
"a.out.nodebug.wasm": 176383,
"a.out.nodebug.wasm.gz": 58776,
"total": 199300,
"total_gz": 67858,
"total": 199294,
"total_gz": 67855,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19023,
"a.out.js.gz": 8039,
"a.out.js": 19017,
"a.out.js.gz": 8038,
"a.out.nodebug.wasm": 149640,
"a.out.nodebug.wasm.gz": 56311,
"total": 168663,
"total_gz": 64350,
"total": 168657,
"total_gz": 64349,
"sent": [
"_abort_js",
"_tzset_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except_wasm_legacy.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19101,
"a.out.js.gz": 8065,
"a.out.js": 19095,
"a.out.js.gz": 8063,
"a.out.nodebug.wasm": 147422,
"a.out.nodebug.wasm.gz": 55982,
"total": 166523,
"total_gz": 64047,
"total": 166517,
"total_gz": 64045,
"sent": [
"_abort_js",
"_tzset_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_lto.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 18568,
"a.out.js.gz": 7818,
"a.out.js": 18562,
"a.out.js.gz": 7814,
"a.out.nodebug.wasm": 101064,
"a.out.nodebug.wasm.gz": 38292,
"total": 119632,
"total_gz": 46110,
"total": 119626,
"total_gz": 46106,
"sent": [
"a (emscripten_resize_heap)",
"b (_setitimer_js)",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_mangle.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 22967,
"a.out.js.gz": 9103,
"a.out.js": 22961,
"a.out.js.gz": 9100,
"a.out.nodebug.wasm": 242663,
"a.out.nodebug.wasm.gz": 81001,
"total": 265630,
"total_gz": 90104,
"total": 265624,
"total_gz": 90101,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
Loading
Loading