Dead code in base64_encode?
codemasher opened this issue · 4 comments
Am i missing something or is anything below line 38 dead code?
https://github.com/kvz/locutus/blob/97d2da1ea3d5bfb969e3c3d08eeb6c8115eb8ab3/src/php/url/base64_encode.js#L38
No, it's not dead code. It's used only in browsers which don't have built-in window.btoa function.
In other words, this condition is true
if (typeof window !== 'undefined') {
and this is false
if (typeof window.btoa !== 'undefined') {
The code could probably use a small refactor/restructure to make it more clear.
But it would then run into the else over here?https://github.com/kvz/locutus/blob/97d2da1ea3d5bfb969e3c3d08eeb6c8115eb8ab3/src/php/url/base64_encode.js#L35-L37
Nope. The condition
if (typeof window !== 'undefined') {
is truthy, so we go inside the IF block. It has a nested IF, which - when falsy - doesn't do anything and the code continues below the IF...ELSE statement.
Ok, got it - i'm dumb :D