@@ -118,6 +118,36 @@ FS.staticInit();` +
118118 filesystems : null ,
119119 syncFSRequests : 0 , // we warn if there are multiple in flight at once
120120
121+ #if ASSERTIONS && ! MINIMAL_RUNTIME
122+ ErrnoError : class extends Error {
123+ #else
124+ ErrnoError : class {
125+ #endif
126+ // We set the `name` property to be able to identify `FS.ErrnoError`
127+ // - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
128+ // - when using PROXYFS, an error can come from an underlying FS
129+ // as different FS objects have their own FS.ErrnoError each,
130+ // the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
131+ // we'll use the reliable test `err.name == "ErrnoError"` instead
132+ constructor ( errno ) {
133+ #if ASSERTIONS && ! MINIMAL_RUNTIME
134+ super ( ERRNO_MESSAGES [ errno ] ) ;
135+ #endif
136+ // TODO(sbc): Use the inline member delclaration syntax once we
137+ // support it in acorn and closure.
138+ this . name = 'ErrnoError' ;
139+ this . errno = errno ;
140+ #if ASSERTIONS
141+ for ( var key in ERRNO_CODES ) {
142+ if ( ERRNO_CODES [ key ] === errno ) {
143+ this . code = key ;
144+ break ;
145+ }
146+ }
147+ #endif
148+ }
149+ } ,
150+
121151 //
122152 // paths
123153 //
@@ -1407,54 +1437,12 @@ FS.staticInit();` +
14071437 assert ( stderr . fd === 2 , `invalid handle for stderr (${ stderr . fd } )` ) ;
14081438#endif
14091439 } ,
1410- ensureErrnoError ( ) {
1411- if ( FS . ErrnoError ) return ;
1412- FS . ErrnoError = /** @this {Object} */ function ErrnoError ( errno ) {
1413- // We set the `name` property to be able to identify `FS.ErrnoError`
1414- // - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
1415- // - when using PROXYFS, an error can come from an underlying FS
1416- // as different FS objects have their own FS.ErrnoError each,
1417- // the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
1418- // we'll use the reliable test `err.name == "ErrnoError"` instead
1419- this . name = 'ErrnoError' ;
1420- this . setErrno = /** @this {Object} */ function ( errno ) {
1421- this . errno = errno ;
1422- #if ASSERTIONS
1423- for ( var key in ERRNO_CODES ) {
1424- if ( ERRNO_CODES [ key ] === errno ) {
1425- this . code = key ;
1426- break ;
1427- }
1428- }
1429- #endif
1430- } ;
1431- this . setErrno ( errno ) ;
1432- #if ASSERTIONS
1433- this . message = ERRNO_MESSAGES [ errno ] ;
1434- #else
1435- this . message = 'FS error' ;
1436- #endif
1437-
1438- #if ASSERTIONS && ! MINIMAL_RUNTIME
1439- // Try to get a maximally helpful stack trace. On Node.js, getting Error.stack
1440- // now ensures it shows what we want.
1441- if ( this . stack ) {
1442- // Define the stack property for Node.js 4, which otherwise errors on the next line.
1443- Object . defineProperty ( this , "stack" , { value : ( new Error ) . stack , writable : true } ) ;
1444- this . stack = demangleAll ( this . stack ) ;
1445- }
1446- #endif // ASSERTIONS
1447- } ;
1448- FS . ErrnoError . prototype = new Error ( ) ;
1449- FS . ErrnoError . prototype . constructor = FS . ErrnoError ;
1440+ staticInit ( ) {
14501441 // Some errors may happen quite a bit, to avoid overhead we reuse them (and suffer a lack of stack info)
14511442 [ { { { cDefs . ENOENT } } } ] . forEach ( ( code ) => {
14521443 FS . genericErrors [ code ] = new FS . ErrnoError ( code ) ;
14531444 FS . genericErrors [ code ] . stack = '<generic error, no stack>' ;
14541445 } ) ;
1455- } ,
1456- staticInit ( ) {
1457- FS . ensureErrnoError ( ) ;
14581446
14591447 FS . nameTable = new Array ( 4096 ) ;
14601448
@@ -1486,8 +1474,6 @@ FS.staticInit();` +
14861474#endif
14871475 FS . init . initialized = true ;
14881476
1489- FS . ensureErrnoError ( ) ;
1490-
14911477 // Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
14921478 Module [ 'stdin' ] = input || Module [ 'stdin' ] ;
14931479 Module [ 'stdout' ] = output || Module [ 'stdout' ] ;
0 commit comments