Skip to content

Commit

Permalink
marmelab#57 Change for..of to use hasOwnProperty.
Browse files Browse the repository at this point in the history
The former causes "ReferenceError: Symbol is not defined" in ng-admin.
  • Loading branch information
RichardBradley committed Dec 16, 2015
1 parent 2c65472 commit a455071
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
10 changes: 6 additions & 4 deletions lib/Field/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ class Field {
}

getMappedValue(value, entry) {
for (let mapFn of this._maps) {
value = mapFn(value, entry);
for (let i in this._maps) {
if (!this._maps.hasOwnProperty(i)) continue;
value = this._maps[i](value, entry);
}

return value;
Expand All @@ -125,8 +126,9 @@ class Field {
}

getTransformedValue(value, entry) {
for (let transformFn of this._transforms) {
value = transformFn(value, entry);
for (let i in this._transforms) {
if (!this._transforms.hasOwnProperty(i)) continue;
value = this._transforms[i](value, entry);
}

return value;
Expand Down
5 changes: 3 additions & 2 deletions lib/Field/ReferenceField.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ class ReferenceField extends Field {
}

if (identifier instanceof Array) {
for (let j of identifier) {
results[j] = true;
for (let j in identifier) {
if (!identifier.hasOwnProperty(j)) continue;
results[identifier[j]] = true;
}
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Queries/ReadQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ class ReadQueries extends Queries {
let calls = [],
getRawValues = this.getRawValues.bind(this);

for (let reference of references) {
for (let i in references) {
if (!references.hasOwnProperty(i)) continue;
let reference = references[i];
let targetEntity = reference.targetEntity();

const permanentFilters = reference.permanentFilters();
Expand Down
5 changes: 3 additions & 2 deletions lib/Utils/PromisesResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class PromisesResolver {
function resolveState(result) {
states[key] = true;
results[key] = result; // result may be an error
for (let state of states) {
if (!state) {
for (let i in states) {
if (!states.hasOwnProperty(i)) continue;
if (!states[i]) {
return;
}
}
Expand Down
8 changes: 5 additions & 3 deletions lib/Utils/orderElement.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export default {
order: function (input) {
var results = [];
var results = [],
objectKey;

for (let i of input) {
results.push(i);
for (objectKey in input) {
if (!input.hasOwnProperty(objectKey)) continue;
results.push(input[objectKey]);
}

return results.sort((e1, e2) => e1.order() - e2.order());
Expand Down
5 changes: 3 additions & 2 deletions lib/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ class View {
if (arg.constructor.name === 'Object') {
console.warn('Passing literal of Field to fields method is deprecated use array instead');
let result = [];
for (let field of arg) {
result = result.concat(View.flatten(field));
for (let fieldName in arg) {
if (!arg.hasOwnProperty(fieldName)) continue;
result = result.concat(View.flatten(arg[fieldName]));
}
return result;
}
Expand Down
4 changes: 1 addition & 3 deletions tests/before_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ beforeEach(function() {
"Don't use for..in to enumerate Array properties, as users are free to " +
"add entries to the Array prototype, for example for polyfills. " +
"You should instead use\n" +
" for (let i in xs) { if (!xs.hasOwnProperty(i)) continue; var x = xs[i]; ... }\n" +
"or\n" +
" for (let x of xs) { ... }";
" for (let i in xs) { if (!xs.hasOwnProperty(i)) continue; var x = xs[i]; ... }";
}
});

0 comments on commit a455071

Please sign in to comment.