Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make sure that document is available before reading location #1038

Merged
merged 1 commit into from
Sep 19, 2017

Conversation

kamilogorek
Copy link
Contributor

@kamilogorek kamilogorek commented Sep 13, 2017

Fixes #1037

https://github.com/getsentry/raven-js/pull/1038/files?w=1#diff-05367d6a2553cabeca57c6ca111093fcR34 – this is the only real change, the rest is just prettify catching up with the rest of the files through precommit hook

@@ -31,13 +31,11 @@ var UNKNOWN_FUNCTION = '?';
var ERROR_TYPES_RE = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;

function getLocationHref() {
if (typeof document === 'undefined' || typeof document.location === 'undefined')
return '';
if (document == null || document.location == null) return '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems problematic. What if document isn't defined? Won't accessing it to make a null comparison throw an exception?

Why not do:

if (typeof document === 'undefined' || document.location == null) return '';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that. I completely forgot that document is just a reference to window.document and it has to obey the same rules as every other property.

@kamilogorek
Copy link
Contributor Author

Updated

@benvinegar
Copy link
Contributor

Approved, but in the future, we should try to separate autoformatting changes from behavior changes. It's worth having separate PRs.

@kamilogorek kamilogorek merged commit 21daca5 into master Sep 19, 2017
@kamilogorek kamilogorek deleted the nonull-document branch September 19, 2017 10:34
@kamilogorek
Copy link
Contributor Author

I totally missed that @benvinegar, thanks for pointing that out. Fixed, merged code change only and updated PR here #1048

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants