From 9c1d3092d3061074d2676ad54b533f86f91c78d9 Mon Sep 17 00:00:00 2001 From: Sebastien Ahkrin Date: Thu, 2 Jan 2020 19:19:02 +0100 Subject: [PATCH] lib: enhance use of Error from primordials --- lib/.eslintrc.yaml | 2 ++ lib/_http_client.js | 1 + lib/_http_server.js | 1 + lib/assert.js | 1 + lib/buffer.js | 1 + lib/child_process.js | 1 + lib/domain.js | 1 + lib/events.js | 1 + lib/internal/assert/assertion_error.js | 1 + lib/internal/async_hooks.js | 1 + lib/internal/bootstrap/loaders.js | 1 + lib/internal/console/constructor.js | 1 + lib/internal/error-serdes.js | 1 + lib/internal/errors.js | 1 + lib/internal/fs/utils.js | 1 + lib/internal/http2/util.js | 1 + lib/internal/modules/cjs/loader.js | 1 + lib/internal/per_context/domexception.js | 1 + lib/internal/process/promises.js | 1 + lib/internal/process/warning.js | 1 + lib/internal/source_map/prepare_stack_trace.js | 4 ++++ lib/internal/util.js | 1 + lib/internal/util/comparisons.js | 1 + lib/internal/v8_prof_polyfill.js | 2 ++ lib/net.js | 1 + lib/repl.js | 1 + lib/util.js | 1 + lib/v8.js | 1 + lib/zlib.js | 1 + 29 files changed, 34 insertions(+) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 8299e79a00eba0..d75bf3e7232ee9 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -29,6 +29,8 @@ rules: message: "Use `const { Reflect } = primordials;` instead of the global." - name: Symbol message: "Use `const { Symbol } = primordials;` instead of the global." + - name: Error + message: "Use `const { Error } = primordials;` instead of the global." no-restricted-syntax: # Config copied from .eslintrc.js - error diff --git a/lib/_http_client.js b/lib/_http_client.js index 7ad01889e3bcb8..a0d96a8d4d4f88 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -24,6 +24,7 @@ const { ArrayIsArray, Boolean, + Error, NumberIsFinite, ObjectAssign, ObjectKeys, diff --git a/lib/_http_server.js b/lib/_http_server.js index b31762b4c1eddb..64190969e5f402 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -22,6 +22,7 @@ 'use strict'; const { + Error, ObjectKeys, ObjectSetPrototypeOf, Symbol, diff --git a/lib/assert.js b/lib/assert.js index e937fb159ea448..2447566719ff90 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -21,6 +21,7 @@ 'use strict'; const { + Error, ObjectAssign, ObjectIs, ObjectKeys, diff --git a/lib/buffer.js b/lib/buffer.js index 2bed199f5744dc..01b9ea97f95a68 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -24,6 +24,7 @@ const { Array, ArrayIsArray, + Error, MathFloor, MathMin, MathTrunc, diff --git a/lib/child_process.js b/lib/child_process.js index 0549e5daf7d10a..9664af7719ee51 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -23,6 +23,7 @@ const { ArrayIsArray, + Error, NumberIsInteger, ObjectAssign, ObjectDefineProperty, diff --git a/lib/domain.js b/lib/domain.js index 4f340f20ec34c3..9a07f22e66712b 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -28,6 +28,7 @@ const { Array, + Error, ObjectDefineProperty, ReflectApply, Symbol, diff --git a/lib/events.js b/lib/events.js index 7889f62d9094f3..76b376e789115f 100644 --- a/lib/events.js +++ b/lib/events.js @@ -24,6 +24,7 @@ const { Array, Boolean, + Error, MathMin, NumberIsNaN, ObjectCreate, diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index 69a6d8afac52c4..a77414834d1e32 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -1,6 +1,7 @@ 'use strict'; const { + Error, MathMax, ObjectCreate, ObjectDefineProperty, diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index bf5456a858870f..f6fb19c996f30b 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -1,6 +1,7 @@ 'use strict'; const { + Error, FunctionPrototypeBind, NumberIsSafeInteger, ObjectDefineProperty, diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 1029d52de9f9b4..3308957e4a152e 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -44,6 +44,7 @@ /* global process, getLinkedBinding, getInternalBinding, primordials */ const { + Error, ReflectGet, ObjectCreate, ObjectDefineProperty, diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index aff24f93455c8b..f5b34de8ce8e74 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -7,6 +7,7 @@ const { ArrayFrom, ArrayIsArray, Boolean, + Error, MathFloor, Number, ObjectDefineProperties, diff --git a/lib/internal/error-serdes.js b/lib/internal/error-serdes.js index 1216c56bffe5c2..72e8c12e9a7358 100644 --- a/lib/internal/error-serdes.js +++ b/lib/internal/error-serdes.js @@ -3,6 +3,7 @@ const Buffer = require('buffer').Buffer; const { ArrayPrototypeForEach, + Error, FunctionPrototypeCall, ObjectAssign, ObjectCreate, diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 8b0a7a0d7aab66..76a441801429e2 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -12,6 +12,7 @@ const { ArrayIsArray, + Error, MathAbs, NumberIsInteger, ObjectDefineProperty, diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index f75e71a914c217..bca8c618dab60c 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -4,6 +4,7 @@ const { ArrayIsArray, BigInt, DateNow, + Error, Number, NumberIsFinite, ObjectSetPrototypeOf, diff --git a/lib/internal/http2/util.js b/lib/internal/http2/util.js index 3bf3a8fdd56df9..ea85864723f7bc 100644 --- a/lib/internal/http2/util.js +++ b/lib/internal/http2/util.js @@ -2,6 +2,7 @@ const { ArrayIsArray, + Error, MathMax, Number, ObjectCreate, diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 19cbc7ab54d653..d788f9e58a3a60 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -23,6 +23,7 @@ const { ArrayIsArray, + Error, JSONParse, ObjectCreate, ObjectDefineProperty, diff --git a/lib/internal/per_context/domexception.js b/lib/internal/per_context/domexception.js index 9b26631904284a..c6d6370c5547cd 100644 --- a/lib/internal/per_context/domexception.js +++ b/lib/internal/per_context/domexception.js @@ -1,6 +1,7 @@ 'use strict'; const { + Error, ObjectDefineProperties, ObjectDefineProperty, SafeWeakMap, diff --git a/lib/internal/process/promises.js b/lib/internal/process/promises.js index e2a589a802682d..95c3a15830e7ef 100644 --- a/lib/internal/process/promises.js +++ b/lib/internal/process/promises.js @@ -1,6 +1,7 @@ 'use strict'; const { + Error, ObjectDefineProperty, } = primordials; diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index cf744cf0d591b1..0068451020c8e3 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -2,6 +2,7 @@ const { ArrayIsArray, + Error, } = primordials; const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes; diff --git a/lib/internal/source_map/prepare_stack_trace.js b/lib/internal/source_map/prepare_stack_trace.js index d6c5fce60a29e3..e8e179178b6116 100644 --- a/lib/internal/source_map/prepare_stack_trace.js +++ b/lib/internal/source_map/prepare_stack_trace.js @@ -1,5 +1,9 @@ 'use strict'; +const { + Error, +} = primordials; + const debug = require('internal/util/debuglog').debuglog('source_map'); const { findSourceMap } = require('internal/source_map/source_map_cache'); const { overrideStackTrace } = require('internal/errors'); diff --git a/lib/internal/util.js b/lib/internal/util.js index 8d4f66a0be26ff..1866d61607768d 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -3,6 +3,7 @@ const { ArrayFrom, ArrayIsArray, + Error, ObjectCreate, ObjectDefineProperties, ObjectDefineProperty, diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index 0d59f37ad846e5..a0e4e3b13107c5 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -5,6 +5,7 @@ const { BigIntPrototypeValueOf, BooleanPrototypeValueOf, DatePrototypeGetTime, + Error, NumberIsNaN, NumberPrototypeValueOf, ObjectGetOwnPropertySymbols, diff --git a/lib/internal/v8_prof_polyfill.js b/lib/internal/v8_prof_polyfill.js index 0b94496fff86b8..5f5922c5386543 100644 --- a/lib/internal/v8_prof_polyfill.js +++ b/lib/internal/v8_prof_polyfill.js @@ -25,6 +25,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* eslint-disable no-restricted-globals */ + module.exports = { versionCheck }; // Don't execute when required directly instead of being eval'd from diff --git a/lib/net.js b/lib/net.js index 751980d6e352ef..b32937f224b873 100644 --- a/lib/net.js +++ b/lib/net.js @@ -24,6 +24,7 @@ const { ArrayIsArray, Boolean, + Error, Number, NumberIsNaN, ObjectDefineProperty, diff --git a/lib/repl.js b/lib/repl.js index d9efb8c5ece523..e74697e92a61e8 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -43,6 +43,7 @@ 'use strict'; const { + Error, MathMax, NumberIsNaN, ObjectAssign, diff --git a/lib/util.js b/lib/util.js index e2b738052daa4d..f9337598e69dc2 100644 --- a/lib/util.js +++ b/lib/util.js @@ -23,6 +23,7 @@ const { ArrayIsArray, + Error, NumberIsSafeInteger, ObjectDefineProperties, ObjectDefineProperty, diff --git a/lib/v8.js b/lib/v8.js index c328a3c573275c..ea99e14792114b 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -17,6 +17,7 @@ const { Array, ArrayBuffer, + Error, Float32Array, Float64Array, Int16Array, diff --git a/lib/zlib.js b/lib/zlib.js index 32bdee0336c42e..19405263c92896 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -22,6 +22,7 @@ 'use strict'; const { + Error, MathMax, NumberIsFinite, NumberIsNaN,