@@ -118,6 +118,45 @@ FS.staticInit();` +
118
118
filesystems : null ,
119
119
syncFSRequests : 0 , // we warn if there are multiple in flight at once
120
120
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
+
121
160
//
122
161
// paths
123
162
//
@@ -1407,54 +1446,12 @@ FS.staticInit();` +
1407
1446
assert ( stderr . fd === 2 , `invalid handle for stderr (${ stderr . fd } )` ) ;
1408
1447
#endif
1409
1448
} ,
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 ( ) {
1450
1450
// Some errors may happen quite a bit, to avoid overhead we reuse them (and suffer a lack of stack info)
1451
1451
[ { { { cDefs . ENOENT } } } ] . forEach ( ( code ) => {
1452
1452
FS . genericErrors [ code ] = new FS . ErrnoError ( code ) ;
1453
1453
FS . genericErrors [ code ] . stack = '<generic error, no stack>' ;
1454
1454
} ) ;
1455
- } ,
1456
- staticInit ( ) {
1457
- FS . ensureErrnoError ( ) ;
1458
1455
1459
1456
FS . nameTable = new Array ( 4096 ) ;
1460
1457
@@ -1486,8 +1483,6 @@ FS.staticInit();` +
1486
1483
#endif
1487
1484
FS . init . initialized = true ;
1488
1485
1489
- FS . ensureErrnoError ( ) ;
1490
-
1491
1486
// Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
1492
1487
Module [ 'stdin' ] = input || Module [ 'stdin' ] ;
1493
1488
Module [ 'stdout' ] = output || Module [ 'stdout' ] ;
0 commit comments