Skip to content

Commit

Permalink
[[FIX]] Prevent regressions in bug fix
Browse files Browse the repository at this point in the history
Explicitly re-implement the erroneous behavior corrected by the previous
commit in order to avoid breaking changes. Tolerate
backwards-incompatable changes in those instances where the input is
invalid JavaScript.
  • Loading branch information
jugglinmike authored and lukeapage committed Jul 19, 2015
1 parent 925a983 commit 477d3ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4618,7 +4618,7 @@ var JSHINT = (function() {
name = tkn.value;
}

if (props[name]) {
if (props[name] && name !== "__proto__") {
warning("W075", state.tokens.next, msg, name);
} else {
props[name] = Object.create(null);
Expand Down Expand Up @@ -4654,7 +4654,7 @@ var JSHINT = (function() {
state.nameStack.set(tkn);

if (props[name]) {
if (props[name].basic || props[name][flagName]) {
if ((props[name].basic || props[name][flagName]) && name !== "__proto__") {
warning("W075", state.tokens.next, msg, name);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/scope-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ var scopeManager = function(state, predefined, exported, declared) {
} else if (state.option.shadow !== true) {
// now since we didn't get any block scope variables, test for var/function
// shadowing
if (declaredInCurrentFunctionScope) {
if (declaredInCurrentFunctionScope && labelName !== "__proto__") {

// see https://github.com/jshint/jshint/issues/2400
if (!_currentFunct["(global)"]) {
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1778,8 +1778,9 @@ exports.duplicateProto = function (test) {
"}());"
];

// TODO: Enable this expected warning in the next major release
TestRun(test, "Duplicate `var`s")
.addError(3, "'__proto__' is already defined.")
//.addError(3, "'__proto__' is already defined.")
.test(src, { proto: true });

src = [
Expand Down Expand Up @@ -1811,8 +1812,9 @@ exports.duplicateProto = function (test) {
"};"
];

// TODO: Enable this expected warning in the next major release
TestRun(test, "Duplicate keys (data)")
.addError(3, "Duplicate key '__proto__'.")
//.addError(3, "Duplicate key '__proto__'.")
.test(src, { proto: true });

src = [
Expand All @@ -1822,8 +1824,9 @@ exports.duplicateProto = function (test) {
"};"
];

// TODO: Enable this expected warning in the next major release
TestRun(test, "Duplicate keys (data and accessor)")
.addError(3, "Duplicate key '__proto__'.")
//.addError(3, "Duplicate key '__proto__'.")
.test(src, { proto: true });

src = [
Expand Down

0 comments on commit 477d3ad

Please sign in to comment.