diff --git a/lib/linter/linter.js b/lib/linter/linter.js index 63247069746..a49d850859b 100644 --- a/lib/linter/linter.js +++ b/lib/linter/linter.js @@ -262,7 +262,7 @@ function createDisableDirectives(options) { */ function getDirectiveComments(filename, ast, ruleMapper) { const configuredRules = {}; - const enabledGlobals = {}; + const enabledGlobals = Object.create(null); const exportedVariables = {}; const problems = []; const disableDirectives = []; diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index da052b339a7..3cfef3bbe4c 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -1208,6 +1208,16 @@ describe("Linter", () => { }); }); + describe("when evaluating code containing a /*global */ block with specific variables", () => { + const code = "/* global toString hasOwnProperty valueOf: true */"; + + it("should not throw an error if comment block has global variables which are Object.prototype contains", () => { + const config = { rules: { checker: "error" } }; + + linter.verify(code, config); + }); + }); + describe("when evaluating code containing /*eslint-env */ block", () => { it("variables should be available in global scope", () => { const code = `/*${ESLINT_ENV} node*/ function f() {} /*${ESLINT_ENV} browser, foo*/`;