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

Unreachable code #7

Open
killmenot opened this issue Sep 6, 2017 · 5 comments
Open

Unreachable code #7

killmenot opened this issue Sep 6, 2017 · 5 comments

Comments

@killmenot
Copy link
Contributor

if (value === null) value = '';

This doesn't work because

var a = null;
typeof a === 'object' // true

above, we have this validation: https://github.com/robtweed/ewd-document-store/blob/master/lib/proto/setDocument.js#L49

@killmenot
Copy link
Contributor Author

killmenot commented Sep 6, 2017

Another such place:

if (value === null || typeof value === 'undefined') value = '';

@robtweed
Copy link
Owner

robtweed commented Sep 7, 2017

So the problem you're highlighting would occur if an array within the object we're saving to global storage contained a member that was null, right?

@killmenot
Copy link
Contributor Author

I think highlighting lines are not correct because value cannot be null or undefined on these steps. Let me explain:

  1. If we consider line 58. This line makes no sense because if value (a.k.a. obj[i][j]) is null, we went this way because type of for null is 'object'.

  2. If we consider second scenario. Line 68 can be passed when obj[i] is undefined (typeof -> 'undefined') but will be skipped if obj[i] is null. This means that line 70 should be

if (typeof value === 'undefined') value = '';

Another option here to have line 68

if (obj[i] === null || typeof obj[i] !== 'object')

@robtweed
Copy link
Owner

robtweed commented Sep 8, 2017

Unfortunately I don't have any examples to hand, but those conditions were added specifically as a result of scenarios I encountered where they proved to be required. I'd rather leave them in now than remove them at the risk of breaking anything

@killmenot
Copy link
Contributor Author

OK, try to provide examples

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

No branches or pull requests

2 participants