summaryrefslogtreecommitdiff
path: root/lib/assert.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-01-23 00:11:22 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-01-24 13:16:08 +0100
commit8e6e1c9dcc83843aa17225b14ef91b92f337aebb (patch)
treec568d59d2779fc46a83d7e44f7eb9af11accf73c /lib/assert.js
parent72bb4445c64af98f3e481c11320afbfb995f010c (diff)
downloadandroid-node-v8-8e6e1c9dcc83843aa17225b14ef91b92f337aebb.tar.gz
android-node-v8-8e6e1c9dcc83843aa17225b14ef91b92f337aebb.tar.bz2
android-node-v8-8e6e1c9dcc83843aa17225b14ef91b92f337aebb.zip
assert: use destructuring for errors
Destructure the necessary Error classes from internal/errors. This improves the readability of the error creation. PR-URL: https://github.com/nodejs/node/pull/18247 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/assert.js')
-rw-r--r--lib/assert.js26
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/assert.js b/lib/assert.js
index 6ac3cf38ea..20f9d0e477 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -25,7 +25,7 @@ const {
isDeepEqual,
isDeepStrictEqual
} = require('internal/util/comparisons');
-const errors = require('internal/errors');
+const { AssertionError, TypeError } = require('internal/errors');
const { openSync, closeSync, readSync } = require('fs');
const { parseExpressionAt } = require('internal/deps/acorn/dist/acorn');
const { inspect } = require('util');
@@ -69,7 +69,7 @@ const NO_EXCEPTION_SENTINEL = {};
function innerFail(obj) {
if (obj.message instanceof Error) throw obj.message;
- throw new errors.AssertionError(obj);
+ throw new AssertionError(obj);
}
function fail(actual, expected, message, operator, stackStartFn) {
@@ -99,7 +99,7 @@ assert.fail = fail;
// new assert.AssertionError({ message: message,
// actual: actual,
// expected: expected });
-assert.AssertionError = errors.AssertionError;
+assert.AssertionError = AssertionError;
function getBuffer(fd, assertLine) {
var lines = 0;
@@ -138,7 +138,7 @@ function innerOk(args, fn) {
var [value, message] = args;
if (args.length === 0)
- throw new errors.TypeError('ERR_MISSING_ARGS', 'value');
+ throw new TypeError('ERR_MISSING_ARGS', 'value');
if (!value) {
if (message == null) {
@@ -346,8 +346,8 @@ function expectedException(actual, expected, msg) {
return expected.test(actual);
// assert.doesNotThrow does not accept objects.
if (arguments.length === 2) {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'expected',
- ['Function', 'RegExp'], expected);
+ throw new TypeError('ERR_INVALID_ARG_TYPE', 'expected',
+ ['Function', 'RegExp'], expected);
}
// The name and message could be non enumerable. Therefore test them
// explicitly.
@@ -384,8 +384,8 @@ function expectedException(actual, expected, msg) {
function getActual(block) {
if (typeof block !== 'function') {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'Function',
- block);
+ throw new TypeError('ERR_INVALID_ARG_TYPE', 'block', 'Function',
+ block);
}
try {
block();
@@ -401,10 +401,10 @@ assert.throws = function throws(block, error, message) {
if (typeof error === 'string') {
if (arguments.length === 3)
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
- 'error',
- ['Function', 'RegExp'],
- error);
+ throw new TypeError('ERR_INVALID_ARG_TYPE',
+ 'error',
+ ['Function', 'RegExp'],
+ error);
message = error;
error = null;
@@ -465,7 +465,7 @@ assert.ifError = function ifError(err) {
message += inspect(err);
}
- const newErr = new assert.AssertionError({
+ const newErr = new AssertionError({
actual: err,
expected: null,
operator: 'ifError',