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 BethGriggs committed Oct 13, 2020
1 parent 3c90b1a commit 77f1e1e
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
ObjectSetPrototypeOf,
SafePromise,
Symbol,
TypeError,
WeakMap,
} = primordials;

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

Expand Down Expand Up @@ -1600,7 +1602,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 77f1e1e

Please sign in to comment.