diff options
author | Rich Trott <rtrott@gmail.com> | 2017-09-29 17:06:28 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2017-10-04 15:49:17 -0700 |
commit | 6e172beaf0390b037549c8484f4513bb79ccc84e (patch) | |
tree | b25bba28ec32f3838961babdc08317aae08cee91 /lib | |
parent | 806857712f76398a786874d77aa65e2f3cbf7dab (diff) | |
download | android-node-v8-6e172beaf0390b037549c8484f4513bb79ccc84e.tar.gz android-node-v8-6e172beaf0390b037549c8484f4513bb79ccc84e.tar.bz2 android-node-v8-6e172beaf0390b037549c8484f4513bb79ccc84e.zip |
errors: make properties mutable
Userland code can break if it depends on a mutable `code` property for
errors. Allow users to change the `code` property but do not propagate
changes to the error `name`.
Additionally, make `message` and `name` consistent with `Error` object
(non-enumerable). Test that `console.log()` and `.toString()` calls on
internal `Error` objects with mutated properties have analogous results
with the standard ECMAScript `Error` objects.
PR-URL: https://github.com/nodejs/node/pull/15694
Fixes: https://github.com/nodejs/node/issues/15658
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/internal/errors.js | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 48ef2dcc3d..e3c18b48c7 100755 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -22,15 +22,13 @@ function makeNodeError(Base) { return class NodeError extends Base { constructor(key, ...args) { super(message(key, args)); - this[kCode] = key; - } - - get name() { - return `${super.name} [${this[kCode]}]`; - } - - get code() { - return this[kCode]; + this[kCode] = this.code = key; + Object.defineProperty(this, 'name', { + configurable: true, + enumerable: false, + value: `${super.name} [${this[kCode]}]`, + writable: true + }); } }; } |