Skip to content

Commit

Permalink
fix: be defensive when given a falsy context value (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
snyamathi authored and redonkulus committed Aug 14, 2019
1 parent 376ca2b commit af832bb
Show file tree
Hide file tree
Showing 5 changed files with 533 additions and 621 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ rules:
indent: [2, 4, {SwitchCase: 1}]
quotes: [2, 'single']
dot-notation: [2, {allowKeywords: false}]
no-console: 0
no-prototype-builtins: 0
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Ycb.prototype = {
return;
}
var value = context[depth];
if(value.constructor !== Array) {
if(!Array.isArray(value)) {
var keys = this.precedenceMap[value];
var n = keys.length;
for(var j=0; j<n; j++) {
Expand Down Expand Up @@ -162,7 +162,7 @@ Ycb.prototype = {
return;
}
var value = context[depth];
if(value.constructor !== Array) {
if(!Array.isArray(value)) {
var keys = this.precedenceMap[value];
var n = keys.length;
for(var j=0; j<n; j++) {
Expand Down Expand Up @@ -202,7 +202,7 @@ Ycb.prototype = {
var dimension = this.dimensionsList[i];
if(contextObj.hasOwnProperty(dimension)) {
var value = contextObj[dimension];
if(value.constructor === Array) {
if(Array.isArray(value)) {
var newValue = [];
for(var j=0; j<value.length; j++) {
var numValue = this.valueToNumber[dimension][value[j]];
Expand Down Expand Up @@ -454,7 +454,7 @@ Ycb.prototype = {
if(activeDimensions[i]) {
var dimensionName = this.dimensionsList[activeIndex];
var contextValue = fullContext[i];
if(contextValue.constructor === Array) {
if(Array.isArray(contextValue)) {
var newValue = [];
for(var k=0; k<contextValue.length; k++) {
var valueChunk = contextValue[k];
Expand Down Expand Up @@ -495,7 +495,7 @@ Ycb.prototype = {
_buildTreeHelper: function(root, depth, context, delta) {
var i;
var currentValue = context[depth];
var isMulti = currentValue.constructor === Array;
var isMulti = Array.isArray(currentValue);
if(depth === context.length-1) {
if(isMulti) {
for(i=0; i<currentValue.length; i++) {
Expand Down
Loading

0 comments on commit af832bb

Please sign in to comment.