top | item 30267879

(no title)

adam_ellsworth | 4 years ago

Thank you. And thank you for making it open source.

Concerning this line: https://github.com/arkadiyt/zoom-redirector/blob/master/back... Why is it sometimes returning undefined? (or is that known)?

Cheers!

discuss

order

arkadiyt|4 years ago

> Thank you. And thank you for making it open source.

Sure thing. All browser extension source code is available to you anyhow, even if the author doesn't publish it.

> Why is it sometimes returning undefined?

Looks like a simple bug as some folks below have pointed out. It doesn't impact the functionality of the extension in any way here.

squeaky-clean|4 years ago

Not the developer but nice catch. const match would be null, not undefined, if the regex search does not match, right?

cipherboy|4 years ago

In a browser console:

> const match = /^\/[js]\/(\d+)\/?$/.exec("something")

> undefined

vinayakpandey|4 years ago

A function returns undefined if any value was not returned.

chrismorgan|4 years ago

True generally, but irrelevant here: the function in question is RegExp.prototype.match. By definition, it never returns undefined, but only an array or null. The only way `match == undefined` could be true would be if smething had overridden RegExp.prototype.match, which would be… surprising and worthy of explicit note.

Also match[1] will never be undefined: it’ll either throw an exception, or be a string. No, this is just a bug, a poorly written guard that fails to guard what it was supposed to, and I suppose an exception is just silently swallowed and treated equivalently to the intended early return. But the clause should be changed to just `if (!match) return;` or similar.