Skip to content

Commit

Permalink
fix: handle instrumentation when a function is called Function (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax authored and bcoe committed Feb 13, 2018
1 parent 0968206 commit b12a07e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/istanbul-lib-instrument/src/visitor.js
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions packages/istanbul-lib-instrument/test/specs/functions.yaml
Expand Up @@ -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}

0 comments on commit b12a07e

Please sign in to comment.