| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0202ba4 commit 7f54ccc
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -509,9 +509,8 @@ function normalizeSpawnArguments(file, args, options) { | |||
| 509 | 509 | throw new ERR_INVALID_ARG_TYPE('options', 'object', options); | |
| 510 | 510 | ||
| 511 | 511 | // Validate the cwd, if present. | |
| 512 | - if (options.cwd != null && | ||
| 513 | - typeof options.cwd !== 'string') { | ||
| 514 | - throw new ERR_INVALID_ARG_TYPE('options.cwd', 'string', options.cwd); | ||
| 512 | + if (options.cwd != null) { | ||
| 513 | + validateString(options.cwd, 'options.cwd'); | ||
| 515 | 514 | } | |
| 516 | 515 | ||
| 517 | 516 | // Validate detached, if present. | |
@@ -538,9 +537,8 @@ function normalizeSpawnArguments(file, args, options) { | |||
| 538 | 537 | } | |
| 539 | 538 | ||
| 540 | 539 | // Validate argv0, if present. | |
| 541 | - if (options.argv0 != null && | ||
| 542 | - typeof options.argv0 !== 'string') { | ||
| 543 | - throw new ERR_INVALID_ARG_TYPE('options.argv0', 'string', options.argv0); | ||
| 540 | + if (options.argv0 != null) { | ||
| 541 | + validateString(options.argv0, 'options.argv0'); | ||
| 544 | 542 | } | |
| 545 | 543 | ||
| 546 | 544 | // Validate windowsHide, if present. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -872,13 +872,8 @@ Socket.prototype.addSourceSpecificMembership = function(sourceAddress, | |||
| 872 | 872 | interfaceAddress) { | |
| 873 | 873 | healthCheck(this); | |
| 874 | 874 | ||
| 875 | - if (typeof sourceAddress !== 'string') { | ||
| 876 | - throw new ERR_INVALID_ARG_TYPE('sourceAddress', 'string', sourceAddress); | ||
| 877 | - } | ||
| 878 | - | ||
| 879 | - if (typeof groupAddress !== 'string') { | ||
| 880 | - throw new ERR_INVALID_ARG_TYPE('groupAddress', 'string', groupAddress); | ||
| 881 | - } | ||
| 875 | + validateString(sourceAddress, 'sourceAddress'); | ||
| 876 | + validateString(groupAddress, 'groupAddress'); | ||
| 882 | 877 | ||
| 883 | 878 | const err = | |
| 884 | 879 | this[kStateSymbol].handle.addSourceSpecificMembership(sourceAddress, | |
@@ -895,13 +890,8 @@ Socket.prototype.dropSourceSpecificMembership = function(sourceAddress, | |||
| 895 | 890 | interfaceAddress) { | |
| 896 | 891 | healthCheck(this); | |
| 897 | 892 | ||
| 898 | - if (typeof sourceAddress !== 'string') { | ||
| 899 | - throw new ERR_INVALID_ARG_TYPE('sourceAddress', 'string', sourceAddress); | ||
| 900 | - } | ||
| 901 | - | ||
| 902 | - if (typeof groupAddress !== 'string') { | ||
| 903 | - throw new ERR_INVALID_ARG_TYPE('groupAddress', 'string', groupAddress); | ||
| 904 | - } | ||
| 893 | + validateString(sourceAddress, 'sourceAddress'); | ||
| 894 | + validateString(groupAddress, 'groupAddress'); | ||
| 905 | 895 | ||
| 906 | 896 | const err = | |
| 907 | 897 | this[kStateSymbol].handle.dropSourceSpecificMembership(sourceAddress, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,11 +28,10 @@ const kHandle = Symbol('kHandle'); | |||
| 28 | 28 | const { owner_symbol } = internalBinding('symbols'); | |
| 29 | 29 | ||
| 30 | 30 | const { | |
| 31 | - ERR_INVALID_ARG_TYPE, | ||
| 32 | 31 | ERR_INVALID_ARG_VALUE, | |
| 33 | 32 | } = require('internal/errors').codes; | |
| 34 | 33 | ||
| 35 | - const { validateInt32 } = require('internal/validators'); | ||
| 34 | + const { validateInt32, validateString } = require('internal/validators'); | ||
| 36 | 35 | ||
| 37 | 36 | class BlockList extends JSTransferable { | |
| 38 | 37 | constructor() { | |
@@ -56,10 +55,8 @@ class BlockList extends JSTransferable { | |||
| 56 | 55 | } | |
| 57 | 56 | ||
| 58 | 57 | addAddress(address, family = 'ipv4') { | |
| 59 | - if (typeof address !== 'string') | ||
| 60 | - throw new ERR_INVALID_ARG_TYPE('address', 'string', address); | ||
| 61 | - if (typeof family !== 'string') | ||
| 62 | - throw new ERR_INVALID_ARG_TYPE('family', 'string', family); | ||
| 58 | + validateString(address, 'address'); | ||
| 59 | + validateString(family, 'family'); | ||
| 63 | 60 | family = family.toLowerCase(); | |
| 64 | 61 | if (family !== 'ipv4' && family !== 'ipv6') | |
| 65 | 62 | throw new ERR_INVALID_ARG_VALUE('family', family); | |
@@ -68,12 +65,9 @@ class BlockList extends JSTransferable { | |||
| 68 | 65 | } | |
| 69 | 66 | ||
| 70 | 67 | addRange(start, end, family = 'ipv4') { | |
| 71 | - if (typeof start !== 'string') | ||
| 72 | - throw new ERR_INVALID_ARG_TYPE('start', 'string', start); | ||
| 73 | - if (typeof end !== 'string') | ||
| 74 | - throw new ERR_INVALID_ARG_TYPE('end', 'string', end); | ||
| 75 | - if (typeof family !== 'string') | ||
| 76 | - throw new ERR_INVALID_ARG_TYPE('family', 'string', family); | ||
| 68 | + validateString(start, 'start'); | ||
| 69 | + validateString(end, 'end'); | ||
| 70 | + validateString(family, 'family'); | ||
| 77 | 71 | family = family.toLowerCase(); | |
| 78 | 72 | if (family !== 'ipv4' && family !== 'ipv6') | |
| 79 | 73 | throw new ERR_INVALID_ARG_VALUE('family', family); | |
@@ -84,10 +78,8 @@ class BlockList extends JSTransferable { | |||
| 84 | 78 | } | |
| 85 | 79 | ||
| 86 | 80 | addSubnet(network, prefix, family = 'ipv4') { | |
| 87 | - if (typeof network !== 'string') | ||
| 88 | - throw new ERR_INVALID_ARG_TYPE('network', 'string', network); | ||
| 89 | - if (typeof family !== 'string') | ||
| 90 | - throw new ERR_INVALID_ARG_TYPE('family', 'string', family); | ||
| 81 | + validateString(network, 'network'); | ||
| 82 | + validateString(family, 'family'); | ||
| 91 | 83 | family = family.toLowerCase(); | |
| 92 | 84 | let type; | |
| 93 | 85 | switch (family) { | |
@@ -106,10 +98,8 @@ class BlockList extends JSTransferable { | |||
| 106 | 98 | } | |
| 107 | 99 | ||
| 108 | 100 | check(address, family = 'ipv4') { | |
| 109 | - if (typeof address !== 'string') | ||
| 110 | - throw new ERR_INVALID_ARG_TYPE('address', 'string', address); | ||
| 111 | - if (typeof family !== 'string') | ||
| 112 | - throw new ERR_INVALID_ARG_TYPE('family', 'string', family); | ||
| 101 | + validateString(address, 'address'); | ||
| 102 | + validateString(family, 'family'); | ||
| 113 | 103 | family = family.toLowerCase(); | |
| 114 | 104 | if (family !== 'ipv4' && family !== 'ipv6') | |
| 115 | 105 | throw new ERR_INVALID_ARG_VALUE('family', family); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,10 @@ const { | |||
| 14 | 14 | ||
| 15 | 15 | const errors = require('internal/errors'); | |
| 16 | 16 | const { isIP } = require('internal/net'); | |
| 17 | - const { validateInt32 } = require('internal/validators'); | ||
| 17 | + const { | ||
| 18 | + validateInt32, | ||
| 19 | + validateString, | ||
| 20 | + } = require('internal/validators'); | ||
| 18 | 21 | const { | |
| 19 | 22 | ChannelWrap, | |
| 20 | 23 | strerror, | |
@@ -71,9 +74,7 @@ class Resolver { | |||
| 71 | 74 | const newSet = []; | |
| 72 | 75 | ||
| 73 | 76 | ArrayPrototypeForEach(servers, (serv, index) => { | |
| 74 | - if (typeof serv !== 'string') { | ||
| 75 | - throw new ERR_INVALID_ARG_TYPE(`servers[${index}]`, 'string', serv); | ||
| 76 | - } | ||
| 77 | + validateString(serv, `servers[${index}]`); | ||
| 77 | 78 | let ipVersion = isIP(serv); | |
| 78 | 79 | ||
| 79 | 80 | if (ipVersion !== 0) | |
@@ -121,9 +122,7 @@ class Resolver { | |||
| 121 | 122 | } | |
| 122 | 123 | ||
| 123 | 124 | setLocalAddress(ipv4, ipv6) { | |
| 124 | - if (typeof ipv4 !== 'string') { | ||
| 125 | - throw new ERR_INVALID_ARG_TYPE('ipv4', 'String', ipv4); | ||
| 126 | - } | ||
| 125 | + validateString(ipv4, 'ipv4'); | ||
| 127 | 126 | ||
| 128 | 127 | if (typeof ipv6 !== 'string' && ipv6 !== undefined) { | |
| 129 | 128 | throw new ERR_INVALID_ARG_TYPE('ipv6', ['String', 'undefined'], ipv6); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ const { | |||
| 28 | 28 | ERR_INVALID_THIS, | |
| 29 | 29 | } | |
| 30 | 30 | } = require('internal/errors'); | |
| 31 | - const { validateObject } = require('internal/validators'); | ||
| 31 | + const { validateObject, validateString } = require('internal/validators'); | ||
| 32 | 32 | ||
| 33 | 33 | const { customInspectSymbol } = require('internal/util'); | |
| 34 | 34 | const { inspect } = require('util'); | |
@@ -487,9 +487,7 @@ class NodeEventTarget extends EventTarget { | |||
| 487 | 487 | return this; | |
| 488 | 488 | } | |
| 489 | 489 | emit(type, arg) { | |
| 490 | - if (typeof type !== 'string') { | ||
| 491 | - throw new ERR_INVALID_ARG_TYPE('type', 'string', type); | ||
| 492 | - } | ||
| 490 | + validateString(type, 'type'); | ||
| 493 | 491 | const hadListeners = this.listenerCount(type) > 0; | |
| 494 | 492 | this[kHybridDispatch](arg, type); | |
| 495 | 493 | return hadListeners; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ const { | |||
| 10 | 10 | ||
| 11 | 11 | const assert = require('internal/assert'); | |
| 12 | 12 | const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes; | |
| 13 | + const { validateString } = require('internal/validators'); | ||
| 13 | 14 | ||
| 14 | 15 | // Lazily loaded | |
| 15 | 16 | let fs; | |
@@ -120,14 +121,13 @@ function emitWarning(warning, type, code, ctor) { | |||
| 120 | 121 | code = undefined; | |
| 121 | 122 | type = 'Warning'; | |
| 122 | 123 | } | |
| 123 | - if (type !== undefined && typeof type !== 'string') { | ||
| 124 | - throw new ERR_INVALID_ARG_TYPE('type', 'string', type); | ||
| 125 | - } | ||
| 124 | + if (type !== undefined) | ||
| 125 | + validateString(type, 'type'); | ||
| 126 | 126 | if (typeof code === 'function') { | |
| 127 | 127 | ctor = code; | |
| 128 | 128 | code = undefined; | |
| 129 | - } else if (code !== undefined && typeof code !== 'string') { | ||
| 130 | - throw new ERR_INVALID_ARG_TYPE('code', 'string', code); | ||
| 129 | + } else if (code !== undefined) { | ||
| 130 | + validateString(code, 'code'); | ||
| 131 | 131 | } | |
| 132 | 132 | if (typeof warning === 'string') { | |
| 133 | 133 | warning = createWarningObject(warning, type, code, ctor, detail); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments