@@ -118,6 +118,45 @@ FS.staticInit();` +
118118 filesystems : null ,
119119 syncFSRequests : 0 , // we warn if there are multiple in flight at once
120120
121+ ErrnoError : class extends Error {
122+ // We set the `name` property to be able to identify `FS.ErrnoError`
123+ // - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
124+ // - when using PROXYFS, an error can come from an underlying FS
125+ // as different FS objects have their own FS.ErrnoError each,
126+ // the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
127+ // we'll use the reliable test `err.name == "ErrnoError"` instead
128+ constructor ( errno ) {
129+ #if ASSERTIONS
130+ var message = ERRNO_MESSAGES [ errno ] ;
131+ #else
132+ var message = 'FS error' ;
133+ #endif
134+ super ( message ) ;
135+ // TODO(sbc): Use the inline member delclaration syntax once we
136+ // support it in acorn and closure.
137+ this . name = 'ErrnoError' ;
138+ this . errno = errno ;
139+ #if ASSERTIONS
140+ for ( var key in ERRNO_CODES ) {
141+ if ( ERRNO_CODES [ key ] === errno ) {
142+ this . code = key ;
143+ break ;
144+ }
145+ }
146+ #endif
147+
148+ #if ASSERTIONS && ! MINIMAL_RUNTIME
149+ // Try to get a maximally helpful stack trace. On Node.js, getting Error.stack
150+ // now ensures it shows what we want.
151+ if ( this . stack ) {
152+ // Define the stack property for Node.js 4, which otherwise errors on the next line.
153+ Object . defineProperty ( this , "stack" , { value : ( new Error ) . stack , writable : true } ) ;
154+ this . stack = demangleAll ( this . stack ) ;
155+ }
156+ #endif // ASSERTIONS && !MINIMAL_RUNTIME
157+ }
158+ } ,
159+
121160 //
122161 // paths
123162 //
@@ -1407,54 +1446,12 @@ FS.staticInit();` +
14071446 assert ( stderr . fd === 2 , `invalid handle for stderr (${ stderr . fd } )` ) ;
14081447#endif
14091448 } ,
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 ;
1449+ staticInit ( ) {
14501450 // Some errors may happen quite a bit, to avoid overhead we reuse them (and suffer a lack of stack info)
14511451 [ { { { cDefs . ENOENT } } } ] . forEach ( ( code ) => {
14521452 FS . genericErrors [ code ] = new FS . ErrnoError ( code ) ;
14531453 FS . genericErrors [ code ] . stack = '<generic error, no stack>' ;
14541454 } ) ;
1455- } ,
1456- staticInit ( ) {
1457- FS . ensureErrnoError ( ) ;
14581455
14591456 FS . nameTable = new Array ( 4096 ) ;
14601457
@@ -1486,8 +1483,6 @@ FS.staticInit();` +
14861483#endif
14871484 FS . init . initialized = true ;
14881485
1489- FS . ensureErrnoError ( ) ;
1490-
14911486 // Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
14921487 Module [ 'stdin' ] = input || Module [ 'stdin' ] ;
14931488 Module [ 'stdout' ] = output || Module [ 'stdout' ] ;
0 commit comments