Skip to content

Commit

Permalink
Remove try/catch from intArrayFromBase64. NFC
Browse files Browse the repository at this point in the history
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:
emscripten-core#20349

This try/catch and this error message was part of the original
function back emscripten-core#5296 but I don't see any reason for them.
  • Loading branch information
sbc100 committed Oct 3, 2023
1 parent c0711b2 commit a77941f
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/base64Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#include "polyfill/atob.js"
#endif

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

try {
var decoded = atob(s);
var bytes = new Uint8Array(decoded.length);
for (var i = 0 ; i < decoded.length ; ++i) {
bytes[i] = decoded.charCodeAt(i);
}
return bytes;
} catch (_) {
throw new Error('Converting base64 string to bytes failed.');
var decoded = atob(s);
var bytes = new Uint8Array(decoded.length);
for (var i = 0 ; i < decoded.length ; ++i) {
bytes[i] = decoded.charCodeAt(i);
}
return bytes;
}

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

0 comments on commit a77941f

Please sign in to comment.