Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Commit

Permalink
'in' Filters with too many elements fail with "Uncaught RangeError"
Browse files Browse the repository at this point in the history
Fixes mapbox/mapbox-gl-js#1782

If too many elements (varies by environment, but appx 1-2k) are used for an 'in' filter, it will fail with "Uncaught RangeError: Maximum call stack size exceeded". This is because the logical comparison of many infix comarisons (eg "(p['foo']==='bar') || (p['foo']==='cat') || ...") becomes too long for the v8natives to handle.
  • Loading branch information
peckjon committed Jan 13, 2016
1 parent 814cd0b commit 05ecf41
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ var operators = {
'<=': strictInfix('<='),
'>=': strictInfix('>='),
'in': function(_, key) {
return (key==='$type')?
Array.prototype.slice.call(arguments, 2).map(function(value) {
return '(' + operators['=='](_, key, value) + ')';
}).join('||') || 'false'
:
JSON.stringify(Array.prototype.slice.call(arguments, 2))+'.indexOf(p['+JSON.stringify(key)+'])>=0';
return '[' + Array.prototype.slice.call(arguments, 2).map(function(value) {
return '(' + operators['=='](_, key, value) + ')';
}).join(',') + '].indexOf(true) >= 0';
},
'!in': function() {
return '!(' + operators.in.apply(this, arguments) + ')';
Expand Down

0 comments on commit 05ecf41

Please sign in to comment.