Skip to content

Commit c0d2932

Browse files
Merge pull request #14454 from Snuffleupagus/util-more-unreachable
Replace some `assert` usage with `unreachable` in the `src/shared/util.js` file
2 parents 625f829 + 0e1b93b commit c0d2932

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/shared/util.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,13 @@ class AbortException extends BaseException {
576576
}
577577

578578
function bytesToString(bytes) {
579-
assert(
580-
bytes !== null && typeof bytes === "object" && bytes.length !== undefined,
581-
"Invalid argument for bytesToString"
582-
);
579+
if (
580+
typeof bytes !== "object" ||
581+
bytes === null ||
582+
bytes.length === undefined
583+
) {
584+
unreachable("Invalid argument for bytesToString");
585+
}
583586
const length = bytes.length;
584587
const MAX_ARGUMENT_COUNT = 8192;
585588
if (length < MAX_ARGUMENT_COUNT) {
@@ -595,7 +598,9 @@ function bytesToString(bytes) {
595598
}
596599

597600
function stringToBytes(str) {
598-
assert(typeof str === "string", "Invalid argument for stringToBytes");
601+
if (typeof str !== "string") {
602+
unreachable("Invalid argument for stringToBytes");
603+
}
599604
const length = str.length;
600605
const bytes = new Uint8Array(length);
601606
for (let i = 0; i < length; ++i) {
@@ -609,12 +614,15 @@ function stringToBytes(str) {
609614
* @param {Array<any>|Uint8Array|string} arr
610615
* @returns {number}
611616
*/
617+
// eslint-disable-next-line consistent-return
612618
function arrayByteLength(arr) {
613619
if (arr.length !== undefined) {
614620
return arr.length;
615621
}
616-
assert(arr.byteLength !== undefined, "arrayByteLength - invalid argument.");
617-
return arr.byteLength;
622+
if (arr.byteLength !== undefined) {
623+
return arr.byteLength;
624+
}
625+
unreachable("Invalid argument for arrayByteLength");
618626
}
619627

620628
/**

0 commit comments

Comments
 (0)