@@ -1836,42 +1836,36 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) {
18361836// Simplified versions from Node, changed for Buffer-only usage
18371837const errors = { }
18381838function 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 )
18561851 }
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
18571857
1858- get code ( ) {
1859- return sym
1860- }
1858+ return err
1859+ }
18611860
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 )
18701863
1871- toString ( ) {
1872- return `${ this . name } [${ sym } ]: ${ this . message } `
1873- }
1864+ NodeError . prototype . toString = function toString ( ) {
1865+ return `${ this . name } [${ sym } ]: ${ this . message } `
18741866 }
1867+
1868+ errors [ sym ] = NodeError
18751869}
18761870
18771871E ( 'ERR_BUFFER_OUT_OF_BOUNDS' ,
0 commit comments