OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 /** | 4 /** |
5 * @unrestricted | 5 * @unrestricted |
6 */ | 6 */ |
7 SDK.ServerTiming = class { | 7 SDK.ServerTiming = class { |
8 /** | 8 /** |
9 * @param {string} metric | 9 * @param {string} metric |
10 * @param {number} value | 10 * @param {?number} value |
11 * @param {string} description | 11 * @param {?string} description |
12 */ | 12 */ |
13 constructor(metric, value, description) { | 13 constructor(metric, value, description) { |
14 this.metric = metric; | 14 this.metric = metric; |
15 this.value = value; | 15 this.value = value; |
16 this.description = description; | 16 this.description = description; |
17 } | 17 } |
18 | 18 |
19 /** | 19 /** |
20 * @param {!Array<!SDK.NetworkRequest.NameValue>} headers | 20 * @param {!Array<!SDK.NetworkRequest.NameValue>} headers |
21 * @return {?Array<!SDK.ServerTiming>} | 21 * @return {?Array<!SDK.ServerTiming>} |
(...skipping 10 matching lines...) Expand all Loading... | |
32 function createFromHeaderValue(valueString) { | 32 function createFromHeaderValue(valueString) { |
33 // https://www.w3.org/TR/server-timing/ | 33 // https://www.w3.org/TR/server-timing/ |
34 var serverTimingMetricRegExp = | 34 var serverTimingMetricRegExp = |
35 /[ \t]*([\!\#\$\%\&\'\*\+\-\.\^\_\`\|\~0-9A-Za-z]+)[ \t]*(?:=[ \t]*(\d +(?:\.\d+)?))?[ \t]*(?:;[ \t]*(?:"([^"]+)"|([\!\#\$\%\&\'\*\+\-\.\^\_\`\|\~0-9A- Za-z]+)))?[ \t]*(?:,(.*))?/; | 35 /[ \t]*([\!\#\$\%\&\'\*\+\-\.\^\_\`\|\~0-9A-Za-z]+)[ \t]*(?:=[ \t]*(\d +(?:\.\d+)?))?[ \t]*(?:;[ \t]*(?:"([^"]+)"|([\!\#\$\%\&\'\*\+\-\.\^\_\`\|\~0-9A- Za-z]+)))?[ \t]*(?:,(.*))?/; |
36 var metricMatch; | 36 var metricMatch; |
37 var result = []; | 37 var result = []; |
38 while (valueString && (metricMatch = serverTimingMetricRegExp.exec(valueSt ring))) { | 38 while (valueString && (metricMatch = serverTimingMetricRegExp.exec(valueSt ring))) { |
39 var metric = metricMatch[1]; | 39 var metric = metricMatch[1]; |
40 var value = metricMatch[2]; | 40 var value = metricMatch[2]; |
41 var description = metricMatch[3] || metricMatch[4]; | 41 var description = metricMatch[3] || metricMatch[4]; |
42 if (value !== null) | 42 if (value !== undefined) |
43 value = Math.abs(parseFloat(metricMatch[2])); | 43 value = Math.abs(parseFloat(metricMatch[2])); |
44 valueString = metricMatch[5]; // comma delimited headers | 44 valueString = metricMatch[5]; // comma delimited headers |
45 result.push(new SDK.ServerTiming(metric, value, description)); | 45 if (typeof value === 'number' || value === undefined) |
allada
2017/02/14 00:00:24
This can send in 'undefined' for value when null a
caseq
2017/02/14 00:06:21
This will be always true due to lines 42 & 43. I g
paulirish
2017/02/14 01:25:06
yup sg. done.
| |
46 result.push(new SDK.ServerTiming(metric, value, description)); | |
46 } | 47 } |
47 return result; | 48 return result; |
48 } | 49 } |
49 | 50 |
50 var serverTimings = rawServerTimingHeaders.reduce((memo, header) => { | 51 var serverTimings = rawServerTimingHeaders.reduce((memo, header) => { |
51 var timing = createFromHeaderValue(header.value); | 52 var timing = createFromHeaderValue(header.value); |
52 Array.prototype.push.apply(memo, timing); | 53 Array.prototype.push.apply(memo, timing); |
53 return memo; | 54 return memo; |
54 }, []); | 55 }, []); |
55 serverTimings.sort((a, b) => a.metric.toLowerCase().compareTo(b.metric.toLow erCase())); | 56 serverTimings.sort((a, b) => a.metric.toLowerCase().compareTo(b.metric.toLow erCase())); |
56 return serverTimings; | 57 return serverTimings; |
57 } | 58 } |
58 }; | 59 }; |
OLD | NEW |