forceGetParentVarAtFqn returns non-object/non-array #144

Closed
whatsallthisthn opened this Issue Oct 4, 2011 · 4 comments

Comments

Projects
None yet
3 participants
@whatsallthisthn

on the client side now.js file you have a function util.createVarAtFqn, and it relies on util.forceGetParentVarAtFqn

the problem is when you try to set double-nested objects, like, lets say i had

now.blah0.blah1 = false;

and i want to change it to

now.blah0.blah1 = {blah2:blah3};

util.createVarAtFqn will sometimes try to set values of like blah3 before it changes blah1 from false into an object, and that will cause the currVal returned by util.forceGetParentVarAtFqn to be undefined, which fucks everything up

so i just added the lines

if ((typeof(currVar[prop]) !== "object")&&(typeof(currVar[prop]) !== "array")) {
currVar[prop] = {};
}

right before

currVar = currVar[prop];

and i think this fixes the problem, but i don't know if there are any unintended consequences, or whether the function was originally setup the way that it was for a reason

@steveWang

This comment has been minimized.

Show comment
Hide comment
@steveWang

steveWang Oct 4, 2011

Contributor

In fact you only need the first check, since arrays are actually objects. The better way to do it is as follows:

if (currVar[prop] && typeof currVar[prop] === "object") { 
  ...
}

since null is also considered to be an object but has a falsy value.

Contributor

steveWang commented Oct 4, 2011

In fact you only need the first check, since arrays are actually objects. The better way to do it is as follows:

if (currVar[prop] && typeof currVar[prop] === "object") { 
  ...
}

since null is also considered to be an object but has a falsy value.

@ericz

This comment has been minimized.

Show comment
Hide comment
@ericz

ericz Oct 4, 2011

Contributor

Ahh indeed there is a bug here. I'll see what the repercussions of the fix might be

Contributor

ericz commented Oct 4, 2011

Ahh indeed there is a bug here. I'll see what the repercussions of the fix might be

@ericz ericz closed this Oct 4, 2011

ericz added a commit that referenced this issue Oct 4, 2011

@ericz

This comment has been minimized.

Show comment
Hide comment
@ericz

ericz Oct 4, 2011

Contributor

Fixed

Contributor

ericz commented Oct 4, 2011

Fixed

ericz added a commit that referenced this issue Oct 4, 2011

ericz added a commit that referenced this issue Oct 4, 2011

@ericz

This comment has been minimized.

Show comment
Hide comment
@ericz

ericz Oct 4, 2011

Contributor

I couldn't actually reproduce the issue (couldnt get children to write before parent object was written) but I put the fix in for good measure as I determined there would be no issues created by it

Contributor

ericz commented Oct 4, 2011

I couldn't actually reproduce the issue (couldnt get children to write before parent object was written) but I put the fix in for good measure as I determined there would be no issues created by it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment