Skip to content

Commit 3562824

Browse files
authored
Remove try/catch from intArrayFromBase64. NFC (#20375)
It seems like the error is strictly worse than just letting the exception propagate out. For example, we have a report of someone hitting this error but I can't tell what the root cause was: #20349 This try/catch and this error message was part of the original function back #5296 but I don't see any reason for them.
1 parent a024288 commit 3562824

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/base64Utils.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include "polyfill/atob.js"
99
#endif
1010

11-
// Converts a string of base64 into a byte array.
12-
// Throws error on invalid input.
11+
// Converts a string of base64 into a byte array (Uint8Array).
1312
function intArrayFromBase64(s) {
1413
#if ENVIRONMENT_MAY_BE_NODE
1514
if (typeof ENVIRONMENT_IS_NODE != 'undefined' && ENVIRONMENT_IS_NODE) {
@@ -18,16 +17,12 @@ function intArrayFromBase64(s) {
1817
}
1918
#endif
2019

21-
try {
22-
var decoded = atob(s);
23-
var bytes = new Uint8Array(decoded.length);
24-
for (var i = 0 ; i < decoded.length ; ++i) {
25-
bytes[i] = decoded.charCodeAt(i);
26-
}
27-
return bytes;
28-
} catch (_) {
29-
throw new Error('Converting base64 string to bytes failed.');
20+
var decoded = atob(s);
21+
var bytes = new Uint8Array(decoded.length);
22+
for (var i = 0 ; i < decoded.length ; ++i) {
23+
bytes[i] = decoded.charCodeAt(i);
3024
}
25+
return bytes;
3126
}
3227

3328
// If filename is a base64 data URI, parses and returns data (Buffer on node,

0 commit comments

Comments
 (0)