From 34d401ce78aadca6e4d62d3304fe011ab7d95956 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Thu, 10 Aug 2017 12:29:47 -0700 Subject: [PATCH] Fix missing window.perfTiming and correct line-endings --- .gitattributes | 1 + perf.js | 135 +++++++++++++++++++++++++------------------------ 2 files changed, 70 insertions(+), 66 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..2125666 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto \ No newline at end of file diff --git a/perf.js b/perf.js index e1bae03..3aad6c4 100644 --- a/perf.js +++ b/perf.js @@ -1,66 +1,69 @@ -/** - * @license - * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. - * This code may only be used under the BSD style license found at http:polymer.github.io/LICENSE.txt - * The complete set of authors may be found at http:polymer.github.io/AUTHORS.txt - * The complete set of contributors may be found at http:polymer.github.io/CONTRIBUTORS.txt - * Code distributed by Google as part of the polymer project is also - * subject to an additional IP rights grant found at http:polymer.github.io/PATENTS.txt - */ -// x-browser compat. -(function() { - let wcr = false; - - addEventListener('WebComponentsReady', function() { - wcr = true; - }); - - console.perf = function() { - if (window.HTMLImports && !HTMLImports.useNative && !wcr) { - let fn = console._perf.bind(console); - HTMLImports.whenReady(fn); - } else { - console._perf(); - } - }; - - console._perf = function() { - if (window.gc) { - for (let i=0; i<20; i++) { - gc(); - } - } - if (console.time) { - console.time('perf'); - } - console.perf.time = performance.now(); - }; - - console.perfEnd = function(info) { - if (window.WebComponents) { - if (!wcr) { - addEventListener('WebComponentsReady', function() { - console._perfEnd(info); - }); - } else { - console._perfEnd(info); - } - } else { - console._perfEnd(info); - } - }; - - console._perfEnd = function(info) { - // force layout - document.body.offsetWidth; - let time = performance.now() - console.perf.time; - if (console.time) { - console.timeEnd('perf'); - } - document.title = time.toFixed(1) + 'ms: ' + document.title; - if (window.top !== window) { - window.top.postMessage({time: time + 'ms', info: info}, '*'); - } - }; - -})(); +/** + * @license + * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. + * This code may only be used under the BSD style license found at + * http:polymer.github.io/LICENSE.txt The complete set of authors may be found + * at http:polymer.github.io/AUTHORS.txt The complete set of contributors may be + * found at http:polymer.github.io/CONTRIBUTORS.txt Code distributed by Google + * as part of the polymer project is also subject to an additional IP rights + * grant found at http:polymer.github.io/PATENTS.txt + */ +// x-browser compat. +(function() { +let wcr = false; + +addEventListener('WebComponentsReady', function() { + wcr = true; +}); + +console.perf = function() { + if (window.HTMLImports && !HTMLImports.useNative && !wcr) { + let fn = console._perf.bind(console); + HTMLImports.whenReady(fn); + } else { + console._perf(); + } +}; + +console._perf = function() { + if (window.gc) { + for (let i = 0; i < 20; i++) { + gc(); + } + } + if (console.time) { + console.time('perf'); + } + console.perf.time = performance.now(); +}; + +console.perfEnd = function(info) { + if (window.WebComponents) { + if (!wcr) { + addEventListener('WebComponentsReady', function() { + console._perfEnd(info); + }); + } else { + console._perfEnd(info); + } + } else { + console._perfEnd(info); + } +}; + +console._perfEnd = function(info, options = {}) { + if (!options.skipForceLayout) { + // force layout + document.body.offsetWidth; + } + window.perfTiming = performance.now() - console.perf.time; + if (console.time) { + console.timeEnd('perf'); + } + document.title = window.perfTiming.toFixed(1) + 'ms: ' + document.title; + if (window.top !== window) { + window.top.postMessage({time: window.perfTiming + 'ms', info}, '*'); + } +}; + +})();