@@ -1836,42 +1836,36 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) {
1836
1836
// Simplified versions from Node, changed for Buffer-only usage
1837
1837
const errors = { }
1838
1838
function E ( sym , getMessage , Base ) {
1839
- errors [ sym ] = class NodeError extends Base {
1840
- constructor ( ) {
1841
- super ( )
1842
-
1843
- Object . defineProperty ( this , 'message' , {
1844
- value : getMessage . apply ( this , arguments ) ,
1845
- writable : true ,
1846
- configurable : true
1847
- } )
1848
-
1849
- // Add the error code to the name to include it in the stack trace.
1850
- this . name = `${ this . name } [${ sym } ]`
1851
- // Access the stack to generate the error message including the error code
1852
- // from the name.
1853
- this . stack // eslint-disable-line no-unused-expressions
1854
- // Reset the name to the actual name.
1855
- delete this . name
1839
+ function NodeError ( ) {
1840
+ const err = new Base ( getMessage . apply ( null , arguments ) )
1841
+
1842
+ Object . setPrototypeOf ( err , NodeError . prototype )
1843
+
1844
+ // Node.js `err.code` properties are own/enumerable properties.
1845
+ err . code = sym
1846
+ // Add the error code to the name to include it in the stack trace.
1847
+ err . name = `${ err . name } [${ sym } ]`
1848
+ // Remove NodeError from the stack trace.
1849
+ if ( Error . captureStackTrace ) {
1850
+ Error . captureStackTrace ( err , NodeError )
1856
1851
}
1852
+ // Access the stack to generate the error message including the error code
1853
+ // from the name.
1854
+ err . stack // eslint-disable-line no-unused-expressions
1855
+ // Reset the name to the actual name.
1856
+ delete err . name
1857
1857
1858
- get code ( ) {
1859
- return sym
1860
- }
1858
+ return err
1859
+ }
1861
1860
1862
- set code ( value ) {
1863
- Object . defineProperty ( this , 'code' , {
1864
- configurable : true ,
1865
- enumerable : true ,
1866
- value,
1867
- writable : true
1868
- } )
1869
- }
1861
+ Object . setPrototypeOf ( NodeError . prototype , Base . prototype )
1862
+ Object . setPrototypeOf ( NodeError , Base )
1870
1863
1871
- toString ( ) {
1872
- return `${ this . name } [${ sym } ]: ${ this . message } `
1873
- }
1864
+ NodeError . prototype . toString = function toString ( ) {
1865
+ return `${ this . name } [${ sym } ]: ${ this . message } `
1874
1866
}
1867
+
1868
+ errors [ sym ] = NodeError
1875
1869
}
1876
1870
1877
1871
E ( 'ERR_BUFFER_OUT_OF_BOUNDS' ,
0 commit comments