Skip to content
New issue

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

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

Already on GitHub? # to your account

Protect array for/in loops #8686

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions js/foundation.interchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ class Interchange {

// Iterate through each rule, but only save the last match
for (var i in this.rules) {
var rule = this.rules[i];
if(this.rules.hasOwnProperty(i)) {
var rule = this.rules[i];

if (window.matchMedia(rule.query).matches) {
match = rule;
if (window.matchMedia(rule.query).matches) {
match = rule;
}
}
}

Expand All @@ -78,8 +80,10 @@ class Interchange {
*/
_addBreakpoints() {
for (var i in Foundation.MediaQuery.queries) {
var query = Foundation.MediaQuery.queries[i];
Interchange.SPECIAL_QUERIES[query.name] = query.value;
if (Foundation.MediaQuery.queries.hasOwnProperty(i)) {
var query = Foundation.MediaQuery.queries[i];
Interchange.SPECIAL_QUERIES[query.name] = query.value;
}
}
}

Expand All @@ -102,18 +106,20 @@ class Interchange {
}

for (var i in rules) {
var rule = rules[i].slice(1, -1).split(', ');
var path = rule.slice(0, -1).join('');
var query = rule[rule.length - 1];

if (Interchange.SPECIAL_QUERIES[query]) {
query = Interchange.SPECIAL_QUERIES[query];
if(rules.hasOwnProperty(i)) {
var rule = rules[i].slice(1, -1).split(', ');
var path = rule.slice(0, -1).join('');
var query = rule[rule.length - 1];

if (Interchange.SPECIAL_QUERIES[query]) {
query = Interchange.SPECIAL_QUERIES[query];
}

rulesList.push({
path: path,
query: query
});
}

rulesList.push({
path: path,
query: query
});
}

this.rules = rulesList;
Expand Down
16 changes: 10 additions & 6 deletions js/foundation.util.mediaQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ var MediaQuery = {
namedQueries = parseStyleToObject(extractedStyles);

for (var key in namedQueries) {
self.queries.push({
name: key,
value: `only screen and (min-width: ${namedQueries[key]})`
});
if(namedQueries.hasOwnProperty(key)) {
self.queries.push({
name: key,
value: `only screen and (min-width: ${namedQueries[key]})`
});
}
}

this.current = this._getCurrentSize();
Expand Down Expand Up @@ -68,8 +70,10 @@ var MediaQuery = {
*/
get(size) {
for (var i in this.queries) {
var query = this.queries[i];
if (size === query.name) return query.value;
if(this.queries.hasOwnProperty(i)) {
var query = this.queries[i];
if (size === query.name) return query.value;
}
}

return null;
Expand Down