From 714d35aa27ce43e294d9db00fbbc985a867150f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Wed, 20 Aug 2014 14:30:49 +0200 Subject: [PATCH] New offender for maxDepth --- .../modules/domComplexYLT/domComplexYLT.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/phantomas_custom/modules/domComplexYLT/domComplexYLT.js b/phantomas_custom/modules/domComplexYLT/domComplexYLT.js index 1d37d9f..3efa341 100644 --- a/phantomas_custom/modules/domComplexYLT/domComplexYLT.js +++ b/phantomas_custom/modules/domComplexYLT/domComplexYLT.js @@ -37,6 +37,7 @@ exports.module = function(phantomas) { var runner = new phantomas.nodeRunner(), whitespacesRegExp = /^\s+$/, DOMelementMaxDepth = 0, + DOMelementMaxDepthElts = [], size = 0; // include all nodes @@ -58,7 +59,13 @@ exports.module = function(phantomas) { case Node.ELEMENT_NODE: phantomas.incrMetric('DOMelementsCount'); - DOMelementMaxDepth = Math.max(DOMelementMaxDepth, depth); + + if (depth > DOMelementMaxDepth) { + DOMelementMaxDepth = depth; + DOMelementMaxDepthElts = [phantomas.getDOMPath(node)]; + } else if (depth === DOMelementMaxDepth) { + DOMelementMaxDepthElts.push(phantomas.getDOMPath(node)); + } if (node.id) { // Send id to a collection so that duplicated ids can be counted @@ -105,6 +112,9 @@ exports.module = function(phantomas) { }); phantomas.setMetric('DOMelementMaxDepth', DOMelementMaxDepth); + DOMelementMaxDepthElts.forEach(function(path) { + phantomas.addOffender('DOMelementMaxDepth', path); + }); phantomas.spyEnabled(false, 'counting iframes and images');