| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ const uv = process.binding('uv'); | |||
| 25 | 25 | const Buffer = require('buffer').Buffer; | |
| 26 | 26 | const internalUtil = require('internal/util'); | |
| 27 | 27 | const binding = process.binding('util'); | |
| 28 | + const errors = require('internal/errors'); | ||
| 28 | 29 | ||
| 29 | 30 | const isError = internalUtil.isError; | |
| 30 | 31 | ||
@@ -194,7 +195,7 @@ Object.defineProperty(inspect, 'defaultOptions', { | |||
| 194 | 195 | }, | |
| 195 | 196 | set: function(options) { | |
| 196 | 197 | if (options === null || typeof options !== 'object') { | |
| 197 | - throw new TypeError('"options" must be an object'); | ||
| 198 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object'); | ||
| 198 | 199 | } | |
| 199 | 200 | Object.assign(inspectDefaultOptions, options); | |
| 200 | 201 | return inspectDefaultOptions; | |
@@ -946,17 +947,14 @@ exports.log = function() { | |||
| 946 | 947 | exports.inherits = function(ctor, superCtor) { | |
| 947 | 948 | ||
| 948 | 949 | if (ctor === undefined || ctor === null) | |
| 949 | - throw new TypeError('The constructor to "inherits" must not be ' + | ||
| 950 | - 'null or undefined'); | ||
| 950 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'ctor', 'function'); | ||
| 951 | 951 | ||
| 952 | 952 | if (superCtor === undefined || superCtor === null) | |
| 953 | - throw new TypeError('The super constructor to "inherits" must not ' + | ||
| 954 | - 'be null or undefined'); | ||
| 953 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor', 'function'); | ||
| 955 | 954 | ||
| 956 | 955 | if (superCtor.prototype === undefined) | |
| 957 | - throw new TypeError('The super constructor to "inherits" must ' + | ||
| 958 | - 'have a prototype'); | ||
| 959 | - | ||
| 956 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor.prototype', | ||
| 957 | + 'function'); | ||
| 960 | 958 | ctor.super_ = superCtor; | |
| 961 | 959 | Object.setPrototypeOf(ctor.prototype, superCtor.prototype); | |
| 962 | 960 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,13 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - require('../common'); | ||
| 3 | + const common = require('../common'); | ||
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | const inherits = require('util').inherits; | |
| 6 | - const errCheck = | ||
| 7 | - /^TypeError: The super constructor to "inherits" must not be null or undefined$/; | ||
| 8 | - | ||
| 6 | + const errCheck = common.expectsError({ | ||
| 7 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 8 | + type: TypeError, | ||
| 9 | + message: 'The "superCtor" argument must be of type function' | ||
| 10 | + }); | ||
| 9 | 11 | ||
| 10 | 12 | // super constructor | |
| 11 | 13 | function A() { | |
@@ -80,10 +82,20 @@ assert.strictEqual(e.constructor, E); | |||
| 80 | 82 | // should throw with invalid arguments | |
| 81 | 83 | assert.throws(function() { | |
| 82 | 84 | inherits(A, {}); | |
| 83 | - }, /^TypeError: The super constructor to "inherits" must have a prototype$/); | ||
| 85 | + }, common.expectsError({ | ||
| 86 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 87 | + type: TypeError, | ||
| 88 | + message: 'The "superCtor.prototype" argument must be of type function' | ||
| 89 | + }) | ||
| 90 | + ); | ||
| 84 | 91 | assert.throws(function() { | |
| 85 | 92 | inherits(A, null); | |
| 86 | 93 | }, errCheck); | |
| 87 | 94 | assert.throws(function() { | |
| 88 | 95 | inherits(null, A); | |
| 89 | - }, /^TypeError: The constructor to "inherits" must not be null or undefined$/); | ||
| 96 | + }, common.expectsError({ | ||
| 97 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 98 | + type: TypeError, | ||
| 99 | + message: 'The "ctor" argument must be of type function' | ||
| 100 | + }) | ||
| 101 | + ); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1028,11 +1028,21 @@ if (typeof Symbol !== 'undefined') { | |||
| 1028 | 1028 | ||
| 1029 | 1029 | assert.throws(() => { | |
| 1030 | 1030 | util.inspect.defaultOptions = null; | |
| 1031 | - }, /"options" must be an object/); | ||
| 1031 | + }, common.expectsError({ | ||
| 1032 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 1033 | + type: TypeError, | ||
| 1034 | + message: 'The "options" argument must be of type object' | ||
| 1035 | + }) | ||
| 1036 | + ); | ||
| 1032 | 1037 | ||
| 1033 | 1038 | assert.throws(() => { | |
| 1034 | 1039 | util.inspect.defaultOptions = 'bad'; | |
| 1035 | - }, /"options" must be an object/); | ||
| 1040 | + }, common.expectsError({ | ||
| 1041 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 1042 | + type: TypeError, | ||
| 1043 | + message: 'The "options" argument must be of type object' | ||
| 1044 | + }) | ||
| 1045 | + ); | ||
| 1036 | 1046 | } | |
| 1037 | 1047 | ||
| 1038 | 1048 | assert.doesNotThrow(() => util.inspect(process)); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments