From b12a07e35918e5d17be66c5382e9a38b092fae32 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 13 Feb 2018 06:25:14 +0100 Subject: [PATCH] fix: handle instrumentation when a function is called Function (#131) --- packages/istanbul-lib-instrument/src/visitor.js | 1 + .../test/specs/functions.yaml | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/istanbul-lib-instrument/src/visitor.js b/packages/istanbul-lib-instrument/src/visitor.js index 3cfccee0..5a01cf7e 100644 --- a/packages/istanbul-lib-instrument/src/visitor.js +++ b/packages/istanbul-lib-instrument/src/visitor.js @@ -468,6 +468,7 @@ const coverageTemplate = template(` var COVERAGE_VAR = (function () { var path = PATH, hash = HASH, + Function = (function(){}).constructor, global = (new Function('return this'))(), gcv = GLOBAL_COVERAGE_VAR, coverageData = INITIAL, diff --git a/packages/istanbul-lib-instrument/test/specs/functions.yaml b/packages/istanbul-lib-instrument/test/specs/functions.yaml index 5c33a594..0044d250 100644 --- a/packages/istanbul-lib-instrument/test/specs/functions.yaml +++ b/packages/istanbul-lib-instrument/test/specs/functions.yaml @@ -130,3 +130,17 @@ tests: functions: {'0': 0, '1': 0, '2': 1, '3': 0} statements: {'0': 0, '1': 1, '2': 1, '3': 1} guard: isInferredFunctionNameAvailable + +--- +name: function named Function +code: | + function Function () { + this.x = 42 + } + output = new Function().x +tests: + - name: does not fail if a function is called Function + out: 42 + lines: {'2': 1, '4': 1} + functions: {'0': 1} + statements: {'0': 1, '1': 1}