From 6bc4dd08c0433c1fd0ebd52a4f9d1277f0521342 Mon Sep 17 00:00:00 2001 From: Richard Bradley Date: Wed, 16 Dec 2015 17:22:27 +0000 Subject: [PATCH] #57 Change for..of to use hasOwnProperty. The former causes "ReferenceError: Symbol is not defined" in ng-admin. --- lib/Field/Field.js | 10 ++++++---- lib/Field/ReferenceField.js | 5 +++-- lib/Queries/ReadQueries.js | 4 +++- lib/Utils/PromisesResolver.js | 5 +++-- lib/Utils/orderElement.js | 8 +++++--- lib/View/View.js | 5 +++-- tests/before_all.js | 4 +--- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/Field/Field.js b/lib/Field/Field.js index a7bb789..e6e7693 100644 --- a/lib/Field/Field.js +++ b/lib/Field/Field.js @@ -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; @@ -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; diff --git a/lib/Field/ReferenceField.js b/lib/Field/ReferenceField.js index 55fbde5..ca82b08 100644 --- a/lib/Field/ReferenceField.js +++ b/lib/Field/ReferenceField.js @@ -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; } diff --git a/lib/Queries/ReadQueries.js b/lib/Queries/ReadQueries.js index 6eb09d3..8d8522e 100644 --- a/lib/Queries/ReadQueries.js +++ b/lib/Queries/ReadQueries.js @@ -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(); diff --git a/lib/Utils/PromisesResolver.js b/lib/Utils/PromisesResolver.js index 1019904..72fd17c 100644 --- a/lib/Utils/PromisesResolver.js +++ b/lib/Utils/PromisesResolver.js @@ -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; } } diff --git a/lib/Utils/orderElement.js b/lib/Utils/orderElement.js index e01f54d..5b29ed1 100644 --- a/lib/Utils/orderElement.js +++ b/lib/Utils/orderElement.js @@ -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()); diff --git a/lib/View/View.js b/lib/View/View.js index b1b42b4..e7875e9 100644 --- a/lib/View/View.js +++ b/lib/View/View.js @@ -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; } diff --git a/tests/before_all.js b/tests/before_all.js index 56a2e06..a8ab6d5 100644 --- a/tests/before_all.js +++ b/tests/before_all.js @@ -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]; ... }"; } });