-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
13 changed files
with
221 additions
and
31 deletions.
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
24 changes: 24 additions & 0 deletions
24
test/parallel/test-errors-systemerror-frozen-intrinsics.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
); |
30 changes: 30 additions & 0 deletions
30
test/parallel/test-errors-systemerror-stackTraceLimit-custom-setter.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
); |
27 changes: 27 additions & 0 deletions
27
test/parallel/test-errors-systemerror-stackTraceLimit-deleted-and-Error-sealed.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.