From 5d6751b61f23deafb03e625e3a5bbf6ce1f00279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 28 Sep 2020 16:35:42 +0200 Subject: [PATCH] lib: use global Error constructors from primordials --- lib/.eslintrc.yaml | 12 ++++++++++++ lib/internal/bootstrap/loaders.js | 1 + lib/internal/error_serdes.js | 6 ++++++ lib/internal/errors.js | 4 ++++ lib/internal/per_context/domexception.js | 1 + lib/internal/per_context/primordials.js | 6 ++++++ lib/internal/vm/module.js | 1 + lib/repl.js | 4 +++- 8 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 0f34afff0814a6..e82897d076748a 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -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 @@ -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 @@ -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 diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 127ef67c36eb64..d5715aa9f8c666 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -53,6 +53,7 @@ const { ReflectGet, SafeSet, String, + TypeError, } = primordials; // Set up process.moduleLoadList. diff --git a/lib/internal/error_serdes.js b/lib/internal/error_serdes.js index 5e18448da7046c..47392752df6318 100644 --- a/lib/internal/error_serdes.js +++ b/lib/internal/error_serdes.js @@ -4,6 +4,7 @@ const Buffer = require('buffer').Buffer; const { ArrayPrototypeForEach, Error, + EvalError, FunctionPrototypeCall, ObjectAssign, ObjectCreate, @@ -13,8 +14,13 @@ const { ObjectGetPrototypeOf, ObjectKeys, ObjectPrototypeToString, + RangeError, + ReferenceError, SafeSet, SymbolToStringTag, + SyntaxError, + TypeError, + URIError, } = primordials; const kSerializedError = 0; diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 9c5087cf1d2fe0..373bf11858ae07 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -21,10 +21,14 @@ const { NumberIsInteger, ObjectDefineProperty, ObjectKeys, + RangeError, String, StringPrototypeStartsWith, Symbol, SymbolFor, + SyntaxError, + TypeError, + URIError, WeakMap, } = primordials; diff --git a/lib/internal/per_context/domexception.js b/lib/internal/per_context/domexception.js index c6d6370c5547cd..06bb3fa3053cd5 100644 --- a/lib/internal/per_context/domexception.js +++ b/lib/internal/per_context/domexception.js @@ -7,6 +7,7 @@ const { SafeWeakMap, SafeMap, SymbolToStringTag, + TypeError, } = primordials; class ERR_INVALID_THIS extends TypeError { diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 09bea0fc7fc523..8b1b8841c25379 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -125,6 +125,7 @@ primordials.SafePromise = makeSafe( 'Boolean', 'Date', 'Error', + 'EvalError', 'Float32Array', 'Float64Array', 'Function', @@ -134,10 +135,15 @@ primordials.SafePromise = makeSafe( 'Map', 'Number', 'Object', + 'RangeError', + 'ReferenceError', 'RegExp', 'Set', 'String', 'Symbol', + 'SyntaxError', + 'TypeError', + 'URIError', 'Uint16Array', 'Uint32Array', 'Uint8Array', diff --git a/lib/internal/vm/module.js b/lib/internal/vm/module.js index d9892d520e78fe..c10433a36f6dcb 100644 --- a/lib/internal/vm/module.js +++ b/lib/internal/vm/module.js @@ -9,6 +9,7 @@ const { ObjectSetPrototypeOf, SafePromise, Symbol, + TypeError, WeakMap, } = primordials; diff --git a/lib/repl.js b/lib/repl.js index f60a49b3f49d43..6d8b98b94825c5 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -60,6 +60,8 @@ const { Set, StringPrototypeIncludes, Symbol, + SyntaxError, + SyntaxErrorPrototype, WeakSet, } = primordials; @@ -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 = {