Repository navigation
[FS] Only generate FS_<symbol> library aliases for functions - #28101
Merged
Merged
Conversation
In emscripten-core#24116, a loop was added at the end of `src/lib/libfs.js` to generate `$FS_<symbol>` wrapper functions (`(...args) => FS.foo(...)`) for `FS` API methods. While the comment noted that non-functions should be skipped, the condition only checked `key[0] !== key[0].toLowerCase()` (which filters out uppercase classes like `ErrnoError`, `FSStream`, and `FSNode`), assuming all lowercase properties on `LibraryFS.$FS` were functions. In practice, `LibraryFS.$FS` also contains lowercase state and object properties (`root`, `mounts`, `devices`, `streams`, `nextInode`, `nameTable`, `currentPath`, `initialized`, `ignorePermissions`, `syncFSRequests`, and `chrdev_stream_ops`). Wrapping these in `(...args) => FS.<key>(...args)` is broken: - Calling any of these generated aliases at runtime would unconditionally throw `TypeError: FS.<key> is not a function`. - When compiling with `-sINCLUDE_FULL_LIBRARY` and `--closure=1` (such as with `-sEXPORT_ES6`), Closure Compiler rejects calls to these non-callable properties on `FS`. - In unoptimized (`-O0` / `ASSERTIONS`) builds, these bogus symbols pollute `missingLibrarySymbols`, unnecessarily increasing JS code size. Check `typeof LibraryFS.$FS[key] !== 'function'` alongside the existing lowercase check so that only actual methods on `FS` receive function aliases. See: emscripten-core#27747
There was a problem hiding this comment.
Code Review
This pull request updates src/lib/libfs.js to prevent creating aliases for non-function properties of LibraryFS.$FS by verifying that the property is a function. This optimization reduces the overall code size, which is reflected in the updated code size test files and expectations. There are no review comments, so I have no feedback to provide.
kripken
approved these changes
Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In #24116, a loop was added at the end of
src/lib/libfs.jsto generate$FS_<symbol>wrapper functions ((...args) => FS.foo(...)) forFSAPI methods. While the comment noted that non-functions should be skipped, the condition only checkedkey[0] !== key[0].toLowerCase()(which filters out uppercase classes likeErrnoError,FSStream, andFSNode), assuming all lowercase properties onLibraryFS.$FSwere functions.In practice,
LibraryFS.$FSalso contains lowercase state and object properties (root,mounts,devices,streams,nextInode,nameTable,currentPath,initialized,ignorePermissions,syncFSRequests, andchrdev_stream_ops). Wrapping these in(...args) => FS.<key>(...args)is broken:TypeError: FS.<key> is not a function.-sINCLUDE_FULL_LIBRARYand--closure=1(such as with-sEXPORT_ES6), Closure Compiler rejects calls to these non-callable properties onFS.-O0/ASSERTIONS) builds, these bogus symbols pollutemissingLibrarySymbols, unnecessarily increasing JS code size.Check
typeof LibraryFS.$FS[key] !== 'function'alongside the existing lowercase check so that only actual methods onFSreceive function aliases.Split out from #27747