lib: make lazyDOMException more common

PR-URL: https://github.com/nodejs/node/pull/39105
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
XadillaX committed 2021-06-28 13:44:28 +08:00
1 parent ccc50a9820
commit 2de139b5d5
15 files changed
+56 -32

No files matched your search

+3 -10
View File
@@ -75,6 +75,7 @@ const {
const {
customInspectSymbol,
isInsideNodeModules,
lazyDOMException,
normalizeEncoding,
kIsEncodingSymbol
} = require('internal/util');
@@ -1208,14 +1209,6 @@ if (internalBinding('config').hasIntl) {
};
}
let DOMException;
const lazyInvalidCharError = hideStackFrames((message, name) => {
if (DOMException === undefined)
DOMException = internalBinding('messaging').DOMException;
throw new DOMException('Invalid character', 'InvalidCharacterError');
});
function btoa(input) {
// The implementation here has not been performance optimized in any way and
// should not be.
@@ -1223,7 +1216,7 @@ function btoa(input) {
input = `${input}`;
for (let n = 0; n < input.length; n++) {
if (input[n].charCodeAt(0) > 0xff)
lazyInvalidCharError();
throw lazyDOMException('Invalid character', 'InvalidCharacterError');
}
const buf = Buffer.from(input, 'latin1');
return buf.toString('base64');
@@ -1239,7 +1232,7 @@ function atob(input) {
input = `${input}`;
for (let n = 0; n < input.length; n++) {
if (!kBase64Digits.includes(input[n]))
lazyInvalidCharError();
throw lazyDOMException('Invalid character', 'InvalidCharacterError');
}
return Buffer.from(input, 'base64').toString('latin1');
}
+4 -1
View File
@@ -36,7 +36,6 @@ const {
getArrayBufferOrView,
hasAnyNotIn,
jobPromise,
lazyDOMException,
validateByteLength,
validateKeyOps,
validateMaxBufferLength,
@@ -45,6 +44,10 @@ const {
kKeyObject,
} = require('internal/crypto/util');
const {
lazyDOMException,
} = require('internal/util');
const { PromiseReject } = primordials;
const {
+4 -1
View File
@@ -47,6 +47,10 @@ const {
isAnyArrayBuffer,
} = require('internal/util/types');
const {
lazyDOMException,
} = require('internal/util');
const {
KeyObject,
InternalCryptoKey,
@@ -66,7 +70,6 @@ const {
getUsagesUnion,
hasAnyNotIn,
jobPromise,
lazyDOMException,
toBuf,
kHandle,
kKeyObject,
+4 -1
View File
@@ -44,13 +44,16 @@ const {
getUsagesUnion,
hasAnyNotIn,
jobPromise,
lazyDOMException,
normalizeHashName,
validateKeyOps,
kKeyObject,
kHandle,
} = require('internal/crypto/util');
const {
lazyDOMException,
} = require('internal/util');
function verifyAcceptableDsaKeyUse(name, type, usages) {
let checkSet;
switch (type) {
+4 -1
View File
@@ -38,7 +38,6 @@ const {
getUsagesUnion,
hasAnyNotIn,
jobPromise,
lazyDOMException,
normalizeHashName,
validateKeyOps,
kHandle,
@@ -46,6 +45,10 @@ const {
kNamedCurveAliases,
} = require('internal/crypto/util');
const {
lazyDOMException,
} = require('internal/util');
const {
generateKeyPair,
} = require('internal/crypto/keygen');
+4 -1
View File
@@ -23,7 +23,6 @@ const { kMaxLength } = require('buffer');
const {
getArrayBufferOrView,
lazyDOMException,
normalizeHashName,
toBuf,
validateByteSource,
@@ -35,6 +34,10 @@ const {
isKeyObject,
} = require('internal/crypto/keys');
const {
lazyDOMException,
} = require('internal/util');
const {
isAnyArrayBuffer,
isArrayBufferView,
+4 -1
View File
@@ -18,7 +18,6 @@ const {
getHashLength,
hasAnyNotIn,
jobPromise,
lazyDOMException,
normalizeHashName,
validateBitLength,
validateKeyOps,
@@ -26,6 +25,10 @@ const {
kKeyObject,
} = require('internal/crypto/util');
const {
lazyDOMException,
} = require('internal/util');
const {
codes: {
ERR_MISSING_OPTION,
+4 -1
View File
@@ -25,11 +25,14 @@ const { ERR_MISSING_OPTION } = require('internal/errors').codes;
const {
getArrayBufferOrView,
getDefaultEncoding,
lazyDOMException,
normalizeHashName,
kKeyObject,
} = require('internal/crypto/util');
const {
lazyDOMException,
} = require('internal/util');
function pbkdf2(password, salt, iterations, keylen, digest, callback) {
if (typeof digest === 'function') {
callback = digest;
+1 -1
View File
@@ -27,7 +27,7 @@ const {
const {
lazyDOMException,
} = require('internal/crypto/util');
} = require('internal/util');
const { Buffer, kMaxLength } = require('buffer');
+4 -1
View File
@@ -40,7 +40,6 @@ const {
getUsagesUnion,
hasAnyNotIn,
jobPromise,
lazyDOMException,
normalizeHashName,
validateKeyOps,
validateMaxBufferLength,
@@ -48,6 +47,10 @@ const {
kKeyObject,
} = require('internal/crypto/util');
const {
lazyDOMException,
} = require('internal/util');
const {
isUint8Array,
} = require('internal/util/types');
+4 -1
View File
@@ -30,10 +30,13 @@ const {
const {
getArrayBufferOrView,
getDefaultEncoding,
lazyDOMException,
kKeyObject,
} = require('internal/crypto/util');
const {
lazyDOMException,
} = require('internal/util');
const defaults = {
N: 16384,
r: 8,
+1 -8
View File
@@ -51,6 +51,7 @@ const { Buffer } = require('buffer');
const {
cachedResult,
filterDuplicateStrings,
lazyDOMException,
} = require('internal/util');
const {
@@ -70,13 +71,6 @@ function lazyRequire(name) {
return ret;
}
let DOMException;
const lazyDOMException = hideStackFrames((message, name) => {
if (DOMException === undefined)
DOMException = internalBinding('messaging').DOMException;
return new DOMException(message, name);
});
var defaultEncoding = 'buffer';
function setDefaultEncoding(val) {
@@ -428,7 +422,6 @@ module.exports = {
normalizeAlgorithm,
normalizeHashName,
hasAnyNotIn,
lazyDOMException,
validateBitLength,
validateByteLength,
validateByteSource,
+4 -1
View File
@@ -49,7 +49,6 @@ const {
const {
getArrayBufferOrView,
hasAnyNotIn,
lazyDOMException,
lazyRequire,
normalizeAlgorithm,
normalizeHashName,
@@ -59,6 +58,10 @@ const {
kKeyObject,
} = require('internal/crypto/util');
const {
lazyDOMException,
} = require('internal/util');
const {
getRandomValues,
} = require('internal/crypto/random');
+2 -3
View File
@@ -76,7 +76,7 @@ const {
validateString,
} = require('internal/validators');
const pathModule = require('path');
const { promisify } = require('internal/util');
const { lazyDOMException, promisify } = require('internal/util');
const { EventEmitterMixin } = require('internal/event_target');
const { watch } = require('internal/fs/watchers');
const { isIterable } = require('internal/streams/utils');
@@ -211,8 +211,7 @@ class FileHandle extends EventEmitterMixin(JSTransferable) {
[kTransfer]() {
if (this[kClosePromise] || this[kRefs] > 1) {
const DOMException = internalBinding('messaging').DOMException;
throw new DOMException('Cannot transfer FileHandle while in use',
throw lazyDOMException('Cannot transfer FileHandle while in use',
'DataCloneError');
}
+9
View File
@@ -28,6 +28,7 @@ const {
} = primordials;
const {
hideStackFrames,
codes: {
ERR_INVALID_ARG_TYPE,
ERR_NO_CRYPTO,
@@ -441,6 +442,13 @@ function createDeferredPromise() {
return { promise, resolve, reject };
}
let DOMException;
const lazyDOMException = hideStackFrames((message, name) => {
if (DOMException === undefined)
DOMException = internalBinding('messaging').DOMException;
return new DOMException(message, name);
});
module.exports = {
assertCrypto,
cachedResult,
@@ -457,6 +465,7 @@ module.exports = {
isError,
isInsideNodeModules,
join,
lazyDOMException,
normalizeEncoding,
once,
promisify,