Skip to content

Commit 0788c7c

Browse files
committed
fixup! lib: avoid mutating Error.stackTraceLimit when Error is frozen
1 parent ca2f28b commit 0788c7c

5 files changed

+138
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
require('../common');
4+
const assert = require('assert');
5+
const { E, SystemError, codes } = require('internal/errors');
6+
7+
let stackTraceLimit;
8+
Reflect.defineProperty(Error, 'stackTraceLimit', {
9+
get() { return stackTraceLimit; },
10+
set(value) { stackTraceLimit = value; },
11+
});
12+
13+
E('ERR_TEST', 'custom message', SystemError);
14+
const { ERR_TEST } = codes;
15+
16+
const ctx = {
17+
code: 'ETEST',
18+
message: 'code message',
19+
syscall: 'syscall_test',
20+
path: '/str',
21+
dest: '/str2'
22+
};
23+
assert.throws(
24+
() => { throw new ERR_TEST(ctx); },
25+
{
26+
code: 'ERR_TEST',
27+
name: 'SystemError',
28+
info: ctx,
29+
}
30+
);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
require('../common');
4+
const assert = require('assert');
5+
const { E, SystemError, codes } = require('internal/errors');
6+
7+
delete Error.stackTraceLimit;
8+
Object.seal(Error);
9+
10+
E('ERR_TEST', 'custom message', SystemError);
11+
const { ERR_TEST } = codes;
12+
13+
const ctx = {
14+
code: 'ETEST',
15+
message: 'code message',
16+
syscall: 'syscall_test',
17+
path: '/str',
18+
dest: '/str2'
19+
};
20+
assert.throws(
21+
() => { throw new ERR_TEST(ctx); },
22+
{
23+
code: 'ERR_TEST',
24+
name: 'SystemError',
25+
info: ctx,
26+
}
27+
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
require('../common');
4+
const assert = require('assert');
5+
const { E, SystemError, codes } = require('internal/errors');
6+
7+
delete Error.stackTraceLimit;
8+
9+
E('ERR_TEST', 'custom message', SystemError);
10+
const { ERR_TEST } = codes;
11+
12+
const ctx = {
13+
code: 'ETEST',
14+
message: 'code message',
15+
syscall: 'syscall_test',
16+
path: '/str',
17+
dest: '/str2'
18+
};
19+
assert.throws(
20+
() => { throw new ERR_TEST(ctx); },
21+
{
22+
code: 'ERR_TEST',
23+
name: 'SystemError',
24+
info: ctx,
25+
}
26+
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
require('../common');
4+
const assert = require('assert');
5+
const { E, SystemError, codes } = require('internal/errors');
6+
7+
Reflect.defineProperty(Error, 'stackTraceLimit', { get() { return 0; } });
8+
9+
E('ERR_TEST', 'custom message', SystemError);
10+
const { ERR_TEST } = codes;
11+
12+
const ctx = {
13+
code: 'ETEST',
14+
message: 'code message',
15+
syscall: 'syscall_test',
16+
path: '/str',
17+
dest: '/str2'
18+
};
19+
assert.throws(
20+
() => { throw new ERR_TEST(ctx); },
21+
{
22+
code: 'ERR_TEST',
23+
name: 'SystemError',
24+
info: ctx,
25+
}
26+
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
require('../common');
4+
const assert = require('assert');
5+
const { E, SystemError, codes } = require('internal/errors');
6+
7+
Reflect.defineProperty(Error, 'stackTraceLimit', {
8+
writable: false,
9+
value: Error.stackTraceLimit,
10+
});
11+
12+
E('ERR_TEST', 'custom message', SystemError);
13+
const { ERR_TEST } = codes;
14+
15+
const ctx = {
16+
code: 'ETEST',
17+
message: 'code message',
18+
syscall: 'syscall_test',
19+
path: '/str',
20+
dest: '/str2'
21+
};
22+
assert.throws(
23+
() => { throw new ERR_TEST(ctx); },
24+
{
25+
code: 'ERR_TEST',
26+
name: 'SystemError',
27+
info: ctx,
28+
}
29+
);

0 commit comments

Comments
 (0)