@@ -115,6 +115,36 @@ FS.staticInit();` +
115115 filesystems : null ,
116116 syncFSRequests : 0 , // we warn if there are multiple in flight at once
117117
118+ #if ASSERTIONS
119+ ErrnoError : class extends Error {
120+ #else
121+ ErrnoError : class {
122+ #endif
123+ // We set the `name` property to be able to identify `FS.ErrnoError`
124+ // - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
125+ // - when using PROXYFS, an error can come from an underlying FS
126+ // as different FS objects have their own FS.ErrnoError each,
127+ // the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
128+ // we'll use the reliable test `err.name == "ErrnoError"` instead
129+ constructor ( errno ) {
130+ #if ASSERTIONS
131+ super ( ERRNO_MESSAGES [ errno ] ) ;
132+ #endif
133+ // TODO(sbc): Use the inline member delclaration syntax once we
134+ // support it in acorn and closure.
135+ this . name = 'ErrnoError' ;
136+ this . errno = errno ;
137+ #if ASSERTIONS
138+ for ( var key in ERRNO_CODES ) {
139+ if ( ERRNO_CODES [ key ] === errno ) {
140+ this . code = key ;
141+ break ;
142+ }
143+ }
144+ #endif
145+ }
146+ } ,
147+
118148 //
119149 // paths
120150 //
@@ -1404,53 +1434,12 @@ FS.staticInit();` +
14041434 assert ( stderr . fd === 2 , `invalid handle for stderr (${ stderr . fd } )` ) ;
14051435#endif
14061436 } ,
1407- ensureErrnoError ( ) {
1408- if ( FS . ErrnoError ) return ;
1409- FS . ErrnoError = /** @this {Object} */ function ErrnoError ( errno ) {
1410- // We set the `name` property to be able to identify `FS.ErrnoError`
1411- // - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
1412- // - when using PROXYFS, an error can come from an underlying FS
1413- // as different FS objects have their own FS.ErrnoError each,
1414- // the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
1415- // we'll use the reliable test `err.name == "ErrnoError"` instead
1416- this . name = 'ErrnoError' ;
1417- this . setErrno = /** @this {Object} */ function ( errno ) {
1418- this . errno = errno ;
1419- #if ASSERTIONS
1420- for ( var key in ERRNO_CODES ) {
1421- if ( ERRNO_CODES [ key ] === errno ) {
1422- this . code = key ;
1423- break ;
1424- }
1425- }
1426- #endif
1427- } ;
1428- this . setErrno ( errno ) ;
1429- #if ASSERTIONS
1430- this . message = ERRNO_MESSAGES [ errno ] ;
1431- #else
1432- this . message = 'FS error' ;
1433- #endif
1434-
1435- #if ASSERTIONS && ! MINIMAL_RUNTIME
1436- // Try to get a maximally helpful stack trace. On Node.js, getting Error.stack
1437- // now ensures it shows what we want.
1438- if ( this . stack ) {
1439- // Define the stack property for Node.js 4, which otherwise errors on the next line.
1440- Object . defineProperty ( this , "stack" , { value : ( new Error ) . stack , writable : true } ) ;
1441- }
1442- #endif // ASSERTIONS
1443- } ;
1444- FS . ErrnoError . prototype = new Error ( ) ;
1445- FS . ErrnoError . prototype . constructor = FS . ErrnoError ;
1437+ staticInit ( ) {
14461438 // Some errors may happen quite a bit, to avoid overhead we reuse them (and suffer a lack of stack info)
14471439 [ { { { cDefs . ENOENT } } } ] . forEach ( ( code ) => {
14481440 FS . genericErrors [ code ] = new FS . ErrnoError ( code ) ;
14491441 FS . genericErrors [ code ] . stack = '<generic error, no stack>' ;
14501442 } ) ;
1451- } ,
1452- staticInit ( ) {
1453- FS . ensureErrnoError ( ) ;
14541443
14551444 FS . nameTable = new Array ( 4096 ) ;
14561445
@@ -1482,8 +1471,6 @@ FS.staticInit();` +
14821471#endif
14831472 FS . init . initialized = true ;
14841473
1485- FS . ensureErrnoError ( ) ;
1486-
14871474 // Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
14881475 Module [ 'stdin' ] = input || Module [ 'stdin' ] ;
14891476 Module [ 'stdout' ] = output || Module [ 'stdout' ] ;
0 commit comments