Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Issue #1449: Check for hasOwnProperty when iterating through tokens

Signed-off-by: Anton Kovalyov <anton@kovalyov.net>
  • Loading branch information...
commit eee3e805e62dbf77ad7b0fb3578f7c021b9c2760 1 parent 5f75b2c
@eviltrout eviltrout authored valueof committed
Showing with 45 additions and 30 deletions.
  1. +36 −30 src/jshint.js
  2. +9 −0 tests/unit/core.js
View
66 src/jshint.js
@@ -3364,16 +3364,18 @@ var JSHINT = (function () {
lone = true;
}
for (var t in tokens) {
- t = tokens[t];
- if (funct[t.id] === "const") {
- warning("E011", null, t.id);
- }
- if (funct["(global)"] && predefined[t.id] === false) {
- warning("W079", t.token, t.id);
- }
- if (t.id) {
- addlabel(t.id, { token: t.token, type: "const", unused: true });
- names.push(t.token);
+ if (tokens.hasOwnProperty(t)) {
+ t = tokens[t];
+ if (funct[t.id] === "const") {
+ warning("E011", null, t.id);
+ }
+ if (funct["(global)"] && predefined[t.id] === false) {
+ warning("W079", t.token, t.id);
+ }
+ if (t.id) {
+ addlabel(t.id, { token: t.token, type: "const", unused: true });
+ names.push(t.token);
+ }
}
}
if (prefix) {
@@ -3436,16 +3438,18 @@ var JSHINT = (function () {
lone = true;
}
for (var t in tokens) {
- t = tokens[t];
- if (state.option.inESNext() && funct[t.id] === "const") {
- warning("E011", null, t.id);
- }
- if (funct["(global)"] && predefined[t.id] === false) {
- warning("W079", t.token, t.id);
- }
- if (t.id) {
- addlabel(t.id, { type: "unused", token: t.token });
- names.push(t.token);
+ if (tokens.hasOwnProperty(t)) {
+ t = tokens[t];
+ if (state.option.inESNext() && funct[t.id] === "const") {
+ warning("E011", null, t.id);
+ }
+ if (funct["(global)"] && predefined[t.id] === false) {
+ warning("W079", t.token, t.id);
+ }
+ if (t.id) {
+ addlabel(t.id, { type: "unused", token: t.token });
+ names.push(t.token);
+ }
}
}
if (prefix) {
@@ -3517,16 +3521,18 @@ var JSHINT = (function () {
lone = true;
}
for (var t in tokens) {
- t = tokens[t];
- if (state.option.inESNext() && funct[t.id] === "const") {
- warning("E011", null, t.id);
- }
- if (funct["(global)"] && predefined[t.id] === false) {
- warning("W079", t.token, t.id);
- }
- if (t.id && !funct["(nolet)"]) {
- addlabel(t.id, { type: "unused", token: t.token, islet: true });
- names.push(t.token);
+ if (tokens.hasOwnProperty(t)) {
+ t = tokens[t];
+ if (state.option.inESNext() && funct[t.id] === "const") {
+ warning("E011", null, t.id);
+ }
+ if (funct["(global)"] && predefined[t.id] === false) {
+ warning("W079", t.token, t.id);
+ }
+ if (t.id && !funct["(nolet)"]) {
+ addlabel(t.id, { type: "unused", token: t.token, islet: true });
+ names.push(t.token);
+ }
}
}
if (prefix) {
View
9 tests/unit/core.js
@@ -769,3 +769,12 @@ exports.testColumnNumAfterNonStrictComparison = function (test) {
.test(src, {eqeqeq: true});
test.done();
};
+
+
+exports.testArrayPrototypeExtensions = function (test) {
+ Array.prototype.undefinedPrototypeProperty = undefined;
+
+ JSHINT("var x = 123;\nlet y = 456;\nconst z = 123;");
+ delete Array.prototype.undefinedPrototypeProperty;
+ test.done();
+};
Please sign in to comment.
Something went wrong with that request. Please try again.