Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
lib: avoid mutating
Error.stackTraceLimit when it is not writable
PR-URL: #38215 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
- Loading branch information
Showing
with
221 additions
and 31 deletions.
- +6 −4 lib/assert.js
- +3 −2 lib/internal/assert/assertion_error.js
- +35 −17 lib/internal/errors.js
- +3 −2 lib/internal/process/promises.js
- +8 −3 lib/internal/process/warning.js
- +1 −1 lib/internal/util.js
- +3 −2 lib/repl.js
- +24 −0 test/parallel/test-errors-systemerror-frozen-intrinsics.js
- +30 −0 test/parallel/test-errors-systemerror-stackTraceLimit-custom-setter.js
- +27 −0 test/parallel/test-errors-systemerror-stackTraceLimit-deleted-and-Error-sealed.js
- +26 −0 test/parallel/test-errors-systemerror-stackTraceLimit-deleted.js
- +26 −0 test/parallel/test-errors-systemerror-stackTraceLimit-has-only-a-getter.js
- +29 −0 test/parallel/test-errors-systemerror-stackTraceLimit-not-writable.js
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @@ -0,0 +1,24 @@ | ||
| // Flags: --expose-internals --frozen-intrinsics | ||
| 'use strict'; | ||
| require('../common'); | ||
| const assert = require('assert'); | ||
| const { E, SystemError, codes } = require('internal/errors'); | ||
|
|
||
| E('ERR_TEST', 'custom message', SystemError); | ||
| const { ERR_TEST } = codes; | ||
|
|
||
| const ctx = { | ||
| code: 'ETEST', | ||
| message: 'code message', | ||
| syscall: 'syscall_test', | ||
| path: '/str', | ||
| dest: '/str2' | ||
| }; | ||
| assert.throws( | ||
| () => { throw new ERR_TEST(ctx); }, | ||
| { | ||
| code: 'ERR_TEST', | ||
| name: 'SystemError', | ||
| info: ctx, | ||
| } | ||
| ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @@ -0,0 +1,30 @@ | ||
| // Flags: --expose-internals | ||
| 'use strict'; | ||
| require('../common'); | ||
| const assert = require('assert'); | ||
| const { E, SystemError, codes } = require('internal/errors'); | ||
|
|
||
| let stackTraceLimit; | ||
| Reflect.defineProperty(Error, 'stackTraceLimit', { | ||
| get() { return stackTraceLimit; }, | ||
| set(value) { stackTraceLimit = value; }, | ||
| }); | ||
|
|
||
| E('ERR_TEST', 'custom message', SystemError); | ||
| const { ERR_TEST } = codes; | ||
|
|
||
| const ctx = { | ||
| code: 'ETEST', | ||
| message: 'code message', | ||
| syscall: 'syscall_test', | ||
| path: '/str', | ||
| dest: '/str2' | ||
| }; | ||
| assert.throws( | ||
| () => { throw new ERR_TEST(ctx); }, | ||
| { | ||
| code: 'ERR_TEST', | ||
| name: 'SystemError', | ||
| info: ctx, | ||
| } | ||
| ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @@ -0,0 +1,27 @@ | ||
| // Flags: --expose-internals | ||
| 'use strict'; | ||
| require('../common'); | ||
| const assert = require('assert'); | ||
| const { E, SystemError, codes } = require('internal/errors'); | ||
|
|
||
| delete Error.stackTraceLimit; | ||
| Object.seal(Error); | ||
|
|
||
| E('ERR_TEST', 'custom message', SystemError); | ||
| const { ERR_TEST } = codes; | ||
|
|
||
| const ctx = { | ||
| code: 'ETEST', | ||
| message: 'code message', | ||
| syscall: 'syscall_test', | ||
| path: '/str', | ||
| dest: '/str2' | ||
| }; | ||
| assert.throws( | ||
| () => { throw new ERR_TEST(ctx); }, | ||
| { | ||
| code: 'ERR_TEST', | ||
| name: 'SystemError', | ||
| info: ctx, | ||
| } | ||
| ); |
Oops, something went wrong.

