Skip to content

Commit 77f1e1e

Browse files
targosBethGriggs
authored andcommitted
lib: use global Error constructors from primordials
PR-URL: #35499 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Shingo Inoue <[email protected]>
1 parent 3c90b1a commit 77f1e1e

File tree

8 files changed

+34
-1
lines changed

8 files changed

+34
-1
lines changed

lib/.eslintrc.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ rules:
2121
message: "Use `const { Boolean } = primordials;` instead of the global."
2222
- name: Error
2323
message: "Use `const { Error } = primordials;` instead of the global."
24+
- name: EvalError
25+
message: "Use `const { EvalError } = primordials;` instead of the global."
2426
- name: Float32Array
2527
message: "Use `const { Float32Array } = primordials;` instead of the global."
2628
- name: Float64Array
@@ -43,6 +45,10 @@ rules:
4345
message: "Use `const { Object } = primordials;` instead of the global."
4446
- name: Promise
4547
message: "Use `const { Promise } = primordials;` instead of the global."
48+
- name: RangeError
49+
message: "Use `const { RangeError } = primordials;` instead of the global."
50+
- name: ReferenceError
51+
message: "Use `const { ReferenceError } = primordials;` instead of the global."
4652
- name: Reflect
4753
message: "Use `const { Reflect } = primordials;` instead of the global."
4854
- name: RegExp
@@ -53,6 +59,12 @@ rules:
5359
message: "Use `const { String } = primordials;` instead of the global."
5460
- name: Symbol
5561
message: "Use `const { Symbol } = primordials;` instead of the global."
62+
- name: SyntaxError
63+
message: "Use `const { SyntaxError } = primordials;` instead of the global."
64+
- name: TypeError
65+
message: "Use `const { TypeError } = primordials;` instead of the global."
66+
- name: URIError
67+
message: "Use `const { URIError } = primordials;` instead of the global."
5668
- name: Uint16Array
5769
message: "Use `const { Uint16Array } = primordials;` instead of the global."
5870
- name: WeakMap

lib/internal/bootstrap/loaders.js

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const {
5353
ReflectGet,
5454
SafeSet,
5555
String,
56+
TypeError,
5657
} = primordials;
5758

5859
// Set up process.moduleLoadList.

lib/internal/error_serdes.js

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const Buffer = require('buffer').Buffer;
44
const {
55
ArrayPrototypeForEach,
66
Error,
7+
EvalError,
78
FunctionPrototypeCall,
89
ObjectAssign,
910
ObjectCreate,
@@ -13,8 +14,13 @@ const {
1314
ObjectGetPrototypeOf,
1415
ObjectKeys,
1516
ObjectPrototypeToString,
17+
RangeError,
18+
ReferenceError,
1619
SafeSet,
1720
SymbolToStringTag,
21+
SyntaxError,
22+
TypeError,
23+
URIError,
1824
} = primordials;
1925

2026
const kSerializedError = 0;

lib/internal/errors.js

+4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ const {
2121
NumberIsInteger,
2222
ObjectDefineProperty,
2323
ObjectKeys,
24+
RangeError,
2425
String,
2526
StringPrototypeStartsWith,
2627
Symbol,
2728
SymbolFor,
29+
SyntaxError,
30+
TypeError,
31+
URIError,
2832
WeakMap,
2933
} = primordials;
3034

lib/internal/per_context/domexception.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
SafeWeakMap,
88
SafeMap,
99
SymbolToStringTag,
10+
TypeError,
1011
} = primordials;
1112

1213
class ERR_INVALID_THIS extends TypeError {

lib/internal/per_context/primordials.js

+6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ primordials.SafePromise = makeSafe(
125125
'Boolean',
126126
'Date',
127127
'Error',
128+
'EvalError',
128129
'Float32Array',
129130
'Float64Array',
130131
'Function',
@@ -134,10 +135,15 @@ primordials.SafePromise = makeSafe(
134135
'Map',
135136
'Number',
136137
'Object',
138+
'RangeError',
139+
'ReferenceError',
137140
'RegExp',
138141
'Set',
139142
'String',
140143
'Symbol',
144+
'SyntaxError',
145+
'TypeError',
146+
'URIError',
141147
'Uint16Array',
142148
'Uint32Array',
143149
'Uint8Array',

lib/internal/vm/module.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
ObjectSetPrototypeOf,
1010
SafePromise,
1111
Symbol,
12+
TypeError,
1213
WeakMap,
1314
} = primordials;
1415

lib/repl.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ const {
6060
Set,
6161
StringPrototypeIncludes,
6262
Symbol,
63+
SyntaxError,
64+
SyntaxErrorPrototype,
6365
WeakSet,
6466
} = primordials;
6567

@@ -1600,7 +1602,7 @@ function defineDefaultCommands(repl) {
16001602
function Recoverable(err) {
16011603
this.err = err;
16021604
}
1603-
ObjectSetPrototypeOf(Recoverable.prototype, SyntaxError.prototype);
1605+
ObjectSetPrototypeOf(Recoverable.prototype, SyntaxErrorPrototype);
16041606
ObjectSetPrototypeOf(Recoverable, SyntaxError);
16051607

16061608
module.exports = {

0 commit comments

Comments
 (0)