Skip to content

Commit

Permalink
lib: use global Error constructors from primordials
Browse files Browse the repository at this point in the history
PR-URL: #35499
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
  • Loading branch information
targos authored and nodejs-github-bot committed Oct 7, 2020
1 parent 46526d6 commit 4bc4f88
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/.eslintrc.yaml
Expand Up @@ -21,6 +21,8 @@ rules:
message: "Use `const { Boolean } = primordials;` instead of the global."
- name: Error
message: "Use `const { Error } = primordials;` instead of the global."
- name: EvalError
message: "Use `const { EvalError } = primordials;` instead of the global."
- name: Float32Array
message: "Use `const { Float32Array } = primordials;` instead of the global."
- name: Float64Array
Expand All @@ -43,6 +45,10 @@ rules:
message: "Use `const { Object } = primordials;` instead of the global."
- name: Promise
message: "Use `const { Promise } = primordials;` instead of the global."
- name: RangeError
message: "Use `const { RangeError } = primordials;` instead of the global."
- name: ReferenceError
message: "Use `const { ReferenceError } = primordials;` instead of the global."
- name: Reflect
message: "Use `const { Reflect } = primordials;` instead of the global."
- name: RegExp
Expand All @@ -53,6 +59,12 @@ rules:
message: "Use `const { String } = primordials;` instead of the global."
- name: Symbol
message: "Use `const { Symbol } = primordials;` instead of the global."
- name: SyntaxError
message: "Use `const { SyntaxError } = primordials;` instead of the global."
- name: TypeError
message: "Use `const { TypeError } = primordials;` instead of the global."
- name: URIError
message: "Use `const { URIError } = primordials;` instead of the global."
- name: Uint16Array
message: "Use `const { Uint16Array } = primordials;` instead of the global."
- name: WeakMap
Expand Down
1 change: 1 addition & 0 deletions lib/internal/bootstrap/loaders.js
Expand Up @@ -53,6 +53,7 @@ const {
ReflectGet,
SafeSet,
String,
TypeError,
} = primordials;

// Set up process.moduleLoadList.
Expand Down
6 changes: 6 additions & 0 deletions lib/internal/error_serdes.js
Expand Up @@ -4,6 +4,7 @@ const Buffer = require('buffer').Buffer;
const {
ArrayPrototypeForEach,
Error,
EvalError,
FunctionPrototypeCall,
ObjectAssign,
ObjectCreate,
Expand All @@ -13,8 +14,13 @@ const {
ObjectGetPrototypeOf,
ObjectKeys,
ObjectPrototypeToString,
RangeError,
ReferenceError,
SafeSet,
SymbolToStringTag,
SyntaxError,
TypeError,
URIError,
} = primordials;

const kSerializedError = 0;
Expand Down
4 changes: 4 additions & 0 deletions lib/internal/errors.js
Expand Up @@ -21,10 +21,14 @@ const {
NumberIsInteger,
ObjectDefineProperty,
ObjectKeys,
RangeError,
String,
StringPrototypeStartsWith,
Symbol,
SymbolFor,
SyntaxError,
TypeError,
URIError,
WeakMap,
} = primordials;

Expand Down
1 change: 1 addition & 0 deletions lib/internal/per_context/domexception.js
Expand Up @@ -7,6 +7,7 @@ const {
SafeWeakMap,
SafeMap,
SymbolToStringTag,
TypeError,
} = primordials;

class ERR_INVALID_THIS extends TypeError {
Expand Down
6 changes: 6 additions & 0 deletions lib/internal/per_context/primordials.js
Expand Up @@ -125,6 +125,7 @@ primordials.SafePromise = makeSafe(
'Boolean',
'Date',
'Error',
'EvalError',
'Float32Array',
'Float64Array',
'Function',
Expand All @@ -134,10 +135,15 @@ primordials.SafePromise = makeSafe(
'Map',
'Number',
'Object',
'RangeError',
'ReferenceError',
'RegExp',
'Set',
'String',
'Symbol',
'SyntaxError',
'TypeError',
'URIError',
'Uint16Array',
'Uint32Array',
'Uint8Array',
Expand Down
1 change: 1 addition & 0 deletions lib/internal/vm/module.js
Expand Up @@ -9,6 +9,7 @@ const {
ObjectSetPrototypeOf,
SafePromise,
Symbol,
TypeError,
WeakMap,
} = primordials;

Expand Down
4 changes: 3 additions & 1 deletion lib/repl.js
Expand Up @@ -60,6 +60,8 @@ const {
Set,
StringPrototypeIncludes,
Symbol,
SyntaxError,
SyntaxErrorPrototype,
WeakSet,
} = primordials;

Expand Down Expand Up @@ -1566,7 +1568,7 @@ function defineDefaultCommands(repl) {
function Recoverable(err) {
this.err = err;
}
ObjectSetPrototypeOf(Recoverable.prototype, SyntaxError.prototype);
ObjectSetPrototypeOf(Recoverable.prototype, SyntaxErrorPrototype);
ObjectSetPrototypeOf(Recoverable, SyntaxError);

module.exports = {
Expand Down

0 comments on commit 4bc4f88

Please sign in to comment.