Skip to content

Commit

Permalink
bump traceviewer to master.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Aug 1, 2016
1 parent 9d9642c commit a628f62
Show file tree
Hide file tree
Showing 101 changed files with 6,382 additions and 1,823 deletions.
1 change: 0 additions & 1 deletion lighthouse-core/scripts/traceviewer-module-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
<link rel="import" href="/tracing/extras/full_config.html">


<link rel="import" href="/tracing/metrics/value_list.html">
<link rel="import" href="/tracing/metrics/all_metrics.html">
16 changes: 9 additions & 7 deletions lighthouse-core/third_party/traceviewer-js/base/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ global.tr = (function() {
panicElement = document.createElement('div');
panicElement.style.webkitFlex = '1 1 auto';
panicElement.style.overflow = 'auto';
panicOverlay.appendChild(panicElement);
Polymer.dom(panicOverlay).appendChild(panicElement);

if (!document.body) {
setTimeout(function() {
document.body.appendChild(panicOverlay);
Polymer.dom(document.body).appendChild(panicOverlay);
}, 150);
} else {
document.body.appendChild(panicOverlay);
Polymer.dom(document.body).appendChild(panicOverlay);
}
}

Expand All @@ -118,12 +118,14 @@ global.tr = (function() {

showPanicElementIfNeeded();
var panicMessageEl = document.createElement('div');
panicMessageEl.innerHTML =
Polymer.dom(panicMessageEl).innerHTML =
'<h2 id="message"></h2>' +
'<pre id="details"></pre>';
panicMessageEl.querySelector('#message').textContent = panicTitle;
panicMessageEl.querySelector('#details').textContent = panicDetails;
panicElement.appendChild(panicMessageEl);
Polymer.dom(Polymer.dom(panicMessageEl).querySelector('#message')).
textContent = panicTitle;
Polymer.dom(Polymer.dom(panicMessageEl).querySelector('#details')).
textContent = panicDetails;
Polymer.dom(panicElement).appendChild(panicMessageEl);

rawPanicMessages.push({
title: panicTitle,
Expand Down
15 changes: 8 additions & 7 deletions lighthouse-core/third_party/traceviewer-js/base/color_scheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ global.tr.exportTo('tr.b', function() {
rail_animation: new tr.b.Color(244, 74, 63),
rail_idle: new tr.b.Color(238, 142, 0),
rail_load: new tr.b.Color(13, 168, 97),
startup: new tr.b.Color(230, 230, 0),

used_memory_column: new tr.b.Color(0, 0, 255),
older_used_memory_column: new tr.b.Color(153, 204, 255),
Expand Down Expand Up @@ -179,10 +180,10 @@ global.tr.exportTo('tr.b', function() {

// Build reservedColorNameToIdMap.
var reservedColorNameToIdMap = (function() {
var m = {};
var m = new Map();
var i = generalPurposeColors.length;
tr.b.iterItems(reservedColorsByName, function(key, value) {
m[key] = i++;
m.set(key, i++);
});
return m;
})();
Expand All @@ -192,7 +193,7 @@ global.tr.exportTo('tr.b', function() {
* @return {Number} The color ID for the given color name.
*/
ColorScheme.getColorIdForReservedName = function(name) {
var id = reservedColorNameToIdMap[name];
var id = reservedColorNameToIdMap.get(name);
if (id === undefined)
throw new Error('Unrecognized color ') + name;
return id;
Expand All @@ -217,19 +218,19 @@ global.tr.exportTo('tr.b', function() {

// Previously computed string color IDs. They are based on a stable hash, so
// it is safe to save them throughout the program time.
var stringColorIdCache = {};
var stringColorIdCache = new Map();

/**
* @return {Number} A color ID that is stably associated to the provided via
* the getStringHash method. The color ID will be chosen from the general
* purpose ID space only, e.g. no reserved ID will be used.
*/
ColorScheme.getColorIdForGeneralPurposeString = function(string) {
if (stringColorIdCache[string] === undefined) {
if (stringColorIdCache.get(string) === undefined) {
var hash = ColorScheme.getStringHash(string);
stringColorIdCache[string] = hash % numGeneralPurposeColorIds;
stringColorIdCache.set(string, hash % numGeneralPurposeColorIds);
}
return stringColorIdCache[string];
return stringColorIdCache.get(string);
};

return {
Expand Down
10 changes: 9 additions & 1 deletion lighthouse-core/third_party/traceviewer-js/base/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,19 @@ global.tr.exportTo('tr.b', function() {
* @param {boolean=} opt_bubbles Whether the event bubbles or not.
* @param {boolean=} opt_cancelable Whether the default action of the event
* can be prevented.
* @param {!Object=} opt_fields
*
* @return {boolean} If any of the listeners called {@code preventDefault}
* during the dispatch this will return false.
*/
function dispatchSimpleEvent(target, type, opt_bubbles, opt_cancelable) {
function dispatchSimpleEvent(target, type, opt_bubbles, opt_cancelable,
opt_fields) {
var e = new tr.b.Event(type, opt_bubbles, opt_cancelable);
if (opt_fields) {
tr.b.iterItems(opt_fields, function(name, value) {
e[name] = value;
});
}
return target.dispatchEvent(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
**/

require("./iteration_helpers.js");
require("./event_target.js");
require("./extension_registry_base.js");
require("./extension_registry_basic.js");
require("./extension_registry_type_based.js");
require("./iteration_helpers.js");

'use strict';

Expand All @@ -23,9 +24,6 @@ require("./extension_registry_type_based.js");
* of tracing categories or typeNames, then query
* for it based on a category, typeName or both.
*
* Use these for pure-JS classes or ui.define'd classes. For polymer element
* related registries, consult base/polymer_utils.html.
*
* When you register subtypes, you pass the constructor for the
* subtype, and any metadata you want associated with the subtype. Use metadata
* instead of stuffing fields onto the constructor. E.g.:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,55 @@ require("./base.js");
'use strict';

global.tr.exportTo('tr.b', function() {
function asArray(arrayish) {

/**
* Converts any object which is either (a) an iterable, or (b) an
* "array-ish" object (has length property and can be indexed into)
* into an array.
*/
function asArray(x) {
var values = [];
for (var i = 0; i < arrayish.length; i++)
values.push(arrayish[i]);
if (x[Symbol.iterator])
for (var value of x)
values.push(value);
else
for (var i = 0; i < x.length; i++)
values.push(x[i]);
return values;
}

/**
* Returns the only element in the iterable. If the iterable is empty or has
* more than one element, an error is thrown.
*/
function getOnlyElement(iterable) {
var iterator = iterable[Symbol.iterator]();

var firstIteration = iterator.next();
if (firstIteration.done)
throw new Error('getOnlyElement was passed an empty iterable.');

var secondIteration = iterator.next();
if (!secondIteration.done)
throw new Error(
'getOnlyElement was passed an iterable with multiple elements.');

return firstIteration.value;
}

/**
* Returns the first element in the iterable. If the iterable is empty, an
* error is thrown.
*/
function getFirstElement(iterable) {
var iterator = iterable[Symbol.iterator]();
var result = iterator.next();
if (result.done)
throw new Error('getFirstElement was passed an empty iterable.');

return result.value;
}

function compareArrays(x, y, elementCmp) {
var minLength = Math.min(x.length, y.length);
for (var i = 0; i < minLength; i++) {
Expand Down Expand Up @@ -117,24 +159,34 @@ global.tr.exportTo('tr.b', function() {
return false;
}

/**
* Returns true if all the elements of the iterable pass the predicate.
*/
function every(iterable, predicate) {
for (var x of iterable)
if (!predicate(x))
return false;
return true;
}

/**
* Returns a new dictionary with items grouped by the return value of the
* specified function being called on each item.
* @param {!Array.<Object>} ary The array being iterated through
* @param {!Function} fn The mapping function between the array value and the
* map key.
* @param {!Array.<!*>} ary The array being iterated through
* @param {!function(!*):!*} callback The mapping function between the array
* value and the map key.
* @param {*=} opt_this
*/
function group(ary, fn) {
return ary.reduce(function(accumulator, curr) {
var key = fn(curr);

if (key in accumulator)
accumulator[key].push(curr);
function group(ary, callback, opt_this) {
var results = {};
for (var element of ary) {
var key = callback.call(opt_this, element);
if (key in results)
results[key].push(element);
else
accumulator[key] = [curr];

return accumulator;
}, {});
results[key] = [element];
}
return results;
}

function iterItems(dict, fn, opt_this) {
Expand Down Expand Up @@ -373,6 +425,9 @@ global.tr.exportTo('tr.b', function() {
dictionaryKeys: dictionaryKeys,
dictionaryValues: dictionaryValues,
dictionaryContainsValue: dictionaryContainsValue,
every: every,
getOnlyElement: getOnlyElement,
getFirstElement: getFirstElement,
group: group,
iterItems: iterItems,
mapItems: mapItems,
Expand Down
8 changes: 8 additions & 0 deletions lighthouse-core/third_party/traceviewer-js/base/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ require("./base.js");
'use strict';

global.tr.exportTo('tr.b', function() {
/* Returns true when x and y are within delta of each other. */
function approximately(x, y, delta) {
if (delta === undefined)
delta = 1e-9;
return Math.abs(x - y) < delta;
}

function clamp(x, lo, hi) {
return Math.min(Math.max(x, lo), hi);
}
Expand Down Expand Up @@ -152,6 +159,7 @@ global.tr.exportTo('tr.b', function() {
};

return {
approximately: approximately,
clamp: clamp,
lerp: lerp,
normalize: normalize,
Expand Down
Loading

0 comments on commit a628f62

Please sign in to comment.