diff --git a/test/parallel/test-errors-systemerror-stackTraceLimit-custom-setter.js b/test/parallel/test-errors-systemerror-stackTraceLimit-custom-setter.js new file mode 100644 index 00000000000000..d89ec22fc4656a --- /dev/null +++ b/test/parallel/test-errors-systemerror-stackTraceLimit-custom-setter.js @@ -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, + } +); diff --git a/test/parallel/test-errors-systemerror-stackTraceLimit-deleted-and-Error-sealed.js b/test/parallel/test-errors-systemerror-stackTraceLimit-deleted-and-Error-sealed.js new file mode 100644 index 00000000000000..ef6a9d16f48140 --- /dev/null +++ b/test/parallel/test-errors-systemerror-stackTraceLimit-deleted-and-Error-sealed.js @@ -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, + } +); diff --git a/test/parallel/test-errors-systemerror-stackTraceLimit-deleted.js b/test/parallel/test-errors-systemerror-stackTraceLimit-deleted.js new file mode 100644 index 00000000000000..2967ff84ed7c5c --- /dev/null +++ b/test/parallel/test-errors-systemerror-stackTraceLimit-deleted.js @@ -0,0 +1,26 @@ +// Flags: --expose-internals +'use strict'; +require('../common'); +const assert = require('assert'); +const { E, SystemError, codes } = require('internal/errors'); + +delete Error.stackTraceLimit; + +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, + } +); diff --git a/test/parallel/test-errors-systemerror-stackTraceLimit-has-only-a-getter.js b/test/parallel/test-errors-systemerror-stackTraceLimit-has-only-a-getter.js new file mode 100644 index 00000000000000..49c39e1576220c --- /dev/null +++ b/test/parallel/test-errors-systemerror-stackTraceLimit-has-only-a-getter.js @@ -0,0 +1,26 @@ +// Flags: --expose-internals +'use strict'; +require('../common'); +const assert = require('assert'); +const { E, SystemError, codes } = require('internal/errors'); + +Reflect.defineProperty(Error, 'stackTraceLimit', { get() { return 0; } }); + +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, + } +); diff --git a/test/parallel/test-errors-systemerror-stackTraceLimit-not-writable.js b/test/parallel/test-errors-systemerror-stackTraceLimit-not-writable.js new file mode 100644 index 00000000000000..8650c5f88738dd --- /dev/null +++ b/test/parallel/test-errors-systemerror-stackTraceLimit-not-writable.js @@ -0,0 +1,29 @@ +// Flags: --expose-internals +'use strict'; +require('../common'); +const assert = require('assert'); +const { E, SystemError, codes } = require('internal/errors'); + +Reflect.defineProperty(Error, 'stackTraceLimit', { + writable: false, + value: Error.stackTraceLimit, +}); + +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, + } +);