Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump catapult/traceviewer to latest #723

Merged
merged 7 commits into from
Oct 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lighthouse-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Example: --output-path=./lighthouse-results.html`
'help'
])

.choices('output', Object.values(Printer.OUTPUT_MODE))
.choices('output', Object.keys(Printer.OUTPUT_MODE))

// default values
.default('mobile', true)
Expand Down
25 changes: 24 additions & 1 deletion lighthouse-core/scripts/build-traceviewer-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const path = require('path');
const jsdom = require('jsdom');
const mkdirp = require('mkdirp');

const babel = require('babel-core');

const paths = {};
const INITIAL_IMPORT = 'scripts/traceviewer-module-index';

Expand All @@ -45,7 +47,7 @@ function convertImport(src) {
const imports = window.document.querySelectorAll('link[rel="import"]');
const scripts = window.document.querySelectorAll('script');
let scriptsContent = '';

scriptsContent += addUseStrictDirective();
scriptsContent += convertLicenseComments(html);

// traverse and rewrite the imports
Expand All @@ -66,6 +68,9 @@ function convertImport(src) {
scriptsContent += rewriteGlobals(scripts[s]);
}

// node4 compat
scriptsContent = polyfillNode4Support(dest, scriptsContent);

writeNewFile(dest, scriptsContent);

function convertLicenseComments(html) {
Expand Down Expand Up @@ -110,6 +115,24 @@ function convertImport(src) {
return script;
}

// the "use strict" must be found *above* the require() statements
function addUseStrictDirective() {
return '"use strict";\n';
}

// adjust and transpile for usage in node 4+
function polyfillNode4Support(dest, scriptsContent) {
let transformed = scriptsContent;
if (dest.endsWith('/slice.js')) {
// no babel plugin that can transpile `new.target`, so this is done manually
transformed = transformed.replace('if (new.target)', 'if (!(this instanceof Slice))');
}
transformed = babel.transform(transformed, {
plugins: ['transform-es2015-destructuring']
}).code;
return transformed;
}

function writeNewFile(dest, scriptsContent) {
dest = dest.replace('./third_party/src/catapult/tracing/tracing/', '');
dest = path.resolve('./third_party/traceviewer-js/' + dest);
Expand Down
50 changes: 20 additions & 30 deletions lighthouse-core/third_party/traceviewer-js/base/base.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
/**
Copyright (c) 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
**/


'use strict';

/**
Expand All @@ -13,9 +13,9 @@ found in the LICENSE file.
* @const
*/


/** Platform, package, object property, and Event support. */
global.tr = (function() {

global.tr = function () {
if (global.tr) {
console.warn('Base was multiply initialized. First init wins.');
return global.tr;
Expand Down Expand Up @@ -65,8 +65,7 @@ global.tr = (function() {
for (var i = 0; i < parts.length; i++) {
var partName = parts[i];
var nextObject = curObject[partName];
if (nextObject === undefined)
return false;
if (nextObject === undefined) return false;
curObject = nextObject;
}
return true;
Expand All @@ -75,8 +74,7 @@ global.tr = (function() {
var panicElement = undefined;
var rawPanicMessages = [];
function showPanicElementIfNeeded() {
if (panicElement)
return;
if (panicElement) return;

var panicOverlay = document.createElement('div');
panicOverlay.style.backgroundColor = 'white';
Expand All @@ -95,37 +93,31 @@ global.tr = (function() {
panicElement = document.createElement('div');
panicElement.style.webkitFlex = '1 1 auto';
panicElement.style.overflow = 'auto';
Polymer.dom(panicOverlay).appendChild(panicElement);
panicOverlay.appendChild(panicElement);

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

function showPanic(panicTitle, panicDetails) {
if (tr.isHeadless) {
if (panicDetails instanceof Error)
throw panicDetails;
if (panicDetails instanceof Error) throw panicDetails;
throw new Error('Panic: ' + panicTitle + ':\n' + panicDetails);
}

if (panicDetails instanceof Error)
panicDetails = panicDetails.stack;
if (panicDetails instanceof Error) panicDetails = panicDetails.stack;

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

rawPanicMessages.push({
title: panicTitle,
Expand All @@ -137,7 +129,7 @@ global.tr = (function() {
return rawPanicMessages.length !== 0;
}
function getPanicText() {
return rawPanicMessages.map(function(msg) {
return rawPanicMessages.map(function (msg) {
return msg.title;
}).join(', ');
}
Expand All @@ -150,10 +142,8 @@ global.tr = (function() {
// Maybe we should check the prototype chain here? The current usage
// pattern is always using an object literal so we only care about own
// properties.
var propertyDescriptor = Object.getOwnPropertyDescriptor(exports,
propertyName);
if (propertyDescriptor)
Object.defineProperty(obj, propertyName, propertyDescriptor);
var propertyDescriptor = Object.getOwnPropertyDescriptor(exports, propertyName);
if (propertyDescriptor) Object.defineProperty(obj, propertyName, propertyDescriptor);
}
};

Expand Down Expand Up @@ -189,6 +179,6 @@ global.tr = (function() {
hasPanic: hasPanic,
getPanicText: getPanicText
};
})();
}();

tr.initialize();
tr.initialize();
40 changes: 16 additions & 24 deletions lighthouse-core/third_party/traceviewer-js/base/base64.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
/**
Copyright (c) 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
Expand All @@ -8,40 +9,33 @@ require("./base.js");

'use strict';

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

function Base64() {
}
function Base64() {}

function b64ToUint6(nChr) {
if (nChr > 64 && nChr < 91)
return nChr - 65;
if (nChr > 96 && nChr < 123)
return nChr - 71;
if (nChr > 47 && nChr < 58)
return nChr + 4;
if (nChr === 43)
return 62;
if (nChr === 47)
return 63;
if (nChr > 64 && nChr < 91) return nChr - 65;
if (nChr > 96 && nChr < 123) return nChr - 71;
if (nChr > 47 && nChr < 58) return nChr + 4;
if (nChr === 43) return 62;
if (nChr === 47) return 63;
return 0;
}

Base64.getDecodedBufferLength = function(input) {
Base64.getDecodedBufferLength = function (input) {
return input.length * 3 + 1 >> 2;
};

Base64.EncodeArrayBufferToString = function(input) {
Base64.EncodeArrayBufferToString = function (input) {
// http://stackoverflow.com/questions/9267899/
var binary = '';
var bytes = new Uint8Array(input);
var len = bytes.byteLength;
for (var i = 0; i < len; i++)
binary += String.fromCharCode(bytes[i]);
for (var i = 0; i < len; i++) binary += String.fromCharCode(bytes[i]);
return btoa(binary);
};

Base64.DecodeToTypedArray = function(input, output) {
Base64.DecodeToTypedArray = function (input, output) {

var nInLen = input.length;
var nOutLen = nInLen * 3 + 1 >> 2;
Expand All @@ -50,8 +44,7 @@ global.tr.exportTo('tr.b', function() {
var nUint24 = 0;
var nOutIdx = 0;

if (nOutLen > output.byteLength)
throw new Error('Output buffer too small to decode.');
if (nOutLen > output.byteLength) throw new Error('Output buffer too small to decode.');

for (var nInIdx = 0; nInIdx < nInLen; nInIdx++) {
nMod4 = nInIdx & 3;
Expand All @@ -72,7 +65,7 @@ global.tr.exportTo('tr.b', function() {
* but we also want to use btoa when it is headless.
* For example we want to use it in a mapper
*/
Base64.btoa = function(input) {
Base64.btoa = function (input) {
return btoa(input);
};

Expand All @@ -82,12 +75,11 @@ global.tr.exportTo('tr.b', function() {
* but we also want to use atob when it is headless.
* For example we want to use it in a mapper
*/
Base64.atob = function(input) {
Base64.atob = function (input) {
return atob(input);
};

return {
Base64: Base64
};

});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
/**
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
Expand All @@ -12,7 +13,7 @@ require("./base.js");
* @fileoverview Helper code for working with tracing categories.
*
*/
global.tr.exportTo('tr.b', function() {
global.tr.exportTo('tr.b', function () {

// Cached values for getCategoryParts.
var categoryPartsFor = {};
Expand All @@ -28,8 +29,7 @@ global.tr.exportTo('tr.b', function() {
*/
function getCategoryParts(category) {
var parts = categoryPartsFor[category];
if (parts !== undefined)
return parts;
if (parts !== undefined) return parts;
parts = category.split(',');
categoryPartsFor[category] = parts;
return parts;
Expand All @@ -38,4 +38,4 @@ global.tr.exportTo('tr.b', function() {
return {
getCategoryParts: getCategoryParts
};
});
});
Loading