From ca108dec5a94c07ae53742cf46e32e48c623a866 Mon Sep 17 00:00:00 2001 From: finico Date: Wed, 3 Jul 2019 11:47:42 +0300 Subject: [PATCH 1/2] Fix: creating of enabledGlobals object without prototype --- lib/linter/linter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 = []; From e534ec52374f40ffc05a172d85fc91a1b4fb2776 Mon Sep 17 00:00:00 2001 From: finico Date: Wed, 3 Jul 2019 13:59:22 +0300 Subject: [PATCH 2/2] Chore: Add test (#11935) --- tests/lib/linter/linter.js | 10 ++++++++++ 1 file changed, 10 insertions(+) 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*/`;