Skip to content

Commit fc94f0d

Browse files
committed
perf_hooks: add class comments
1 parent 3127408 commit fc94f0d

File tree

3 files changed

+44
-22
lines changed

3 files changed

+44
-22
lines changed

Diff for: lib/internal/perf/performance.js

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ ObjectDefineProperties(Performance.prototype, {
166166
enumerable: false,
167167
value: nodeTiming,
168168
},
169+
// In the browser, this function is not public. However, it must be used inside fetch
170+
// which is a Node.js dependency, not a internal module
169171
markResourceTiming: {
170172
configurable: true,
171173
enumerable: false,

Diff for: lib/internal/perf/resource_timing.js

+23-17
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ const kTimingInfo = Symbol('kTimingInfo');
1313
const kInitiatorType = Symbol('kInitiatorType');
1414

1515
class PerformanceResourceTiming extends InternalPerformanceEntry {
16-
constructor(requestedUrl, start, initiatorType, timingInfo, cacheMode = '') {
17-
super(requestedUrl, 'resource', start);
18-
// https://w3c.github.io/resource-timing/#dfn-setup-the-resource-timing-entry
19-
assert.ok(cacheMode === '' || cacheMode === 'local');
16+
constructor(requestedUrl, initiatorType, timingInfo, cacheMode = '') {
17+
super(requestedUrl, 'resource');
2018
this[kInitiatorType] = initiatorType;
2119
this[kRequestedUrl] = requestedUrl;
2220
// https://fetch.spec.whatwg.org/#fetch-timing-info
21+
// This class is using timingInfo assuming it's already validated.
22+
// The spec doesn't say to validate it in the class construction.
2323
this[kTimingInfo] = timingInfo;
2424
this[kCacheMode] = cacheMode;
2525
}
@@ -111,14 +111,27 @@ class PerformanceResourceTiming extends InternalPerformanceEntry {
111111

112112
toJSON() {
113113
return {
114-
initiatorType: this[kInitiatorType],
115-
requestedUrl: this[kRequestedUrl],
116-
cacheMode: this[kCacheMode],
117-
// TODO(rafaelgss): should return timingInfo as well?
118114
name: this.name,
119115
entryType: this.entryType,
120116
startTime: this.startTime,
121117
duration: this.duration,
118+
initiatorType: this[kInitiatorType],
119+
nextHopProtocol: this.nextHopProtocol,
120+
workerStart: this.workerStart,
121+
redirectStart: this.redirectStart,
122+
redirectEnd: this.redirectEnd,
123+
fetchStart: this.fetchStart,
124+
domainLookupStart: this.domainLookupStart,
125+
domainLookupEnd: this.domainLookupEnd,
126+
connectStart: this.connectStart,
127+
connectEnd: this.connectEnd,
128+
secureConnectionStart: this.secureConnectionStart,
129+
requestStart: this.requestStart,
130+
responseStart: this.responseStart,
131+
responseEnd: this.responseEnd,
132+
transferSize: this.transferSize,
133+
encodedBodySize: this.encodedBodySize,
134+
decodedBodySize: this.decodedBodySize,
122135
};
123136
}
124137
}
@@ -131,17 +144,10 @@ function markResourceTiming(
131144
global,
132145
cacheMode,
133146
) {
134-
// TODO(rafaelgss): Probably must have some asserts here for:
135-
// - timingInfo
136-
// - requestedUrl
137-
// - initiatorType
138-
// - cacheMode
139-
// 1. Create a PerformanceResourceTiming object entry in global's realm.
140-
// TODO(rafaelgss): why and how should I put `resource` into global object?
147+
// https://w3c.github.io/resource-timing/#dfn-setup-the-resource-timing-entry
148+
assert(cacheMode === '' || cacheMode === 'local');
141149
const resource = new PerformanceResourceTiming(
142150
requestedUrl,
143-
// TODO(rafaelgss): not sure about that
144-
timingInfo.startTime,
145151
initiatorType,
146152
timingInfo,
147153
cacheMode,

Diff for: test/parallel/test-perf-hooks-resourcetiming.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,27 @@ function createTimingInfo({
142142
assert.strictEqual(resource.decodedBodySize, 0);
143143
assert.strictEqual(resource.transferSize, 0);
144144
assert.deepStrictEqual(resource.toJSON(), {
145-
initiatorType,
146-
requestedUrl,
147-
cacheMode,
148145
name: requestedUrl,
149146
entryType: 'resource',
150-
startTime: timingInfo.startTime,
151-
duration: 0
147+
startTime: 0,
148+
duration: 0,
149+
initiatorType,
150+
nextHopProtocol: [],
151+
workerStart: 0,
152+
redirectStart: 0,
153+
redirectEnd: 0,
154+
fetchStart: 0,
155+
domainLookupStart: 0,
156+
domainLookupEnd: 0,
157+
connectStart: 0,
158+
connectEnd: 0,
159+
secureConnectionStart: 0,
160+
requestStart: 0,
161+
responseStart: 0,
162+
responseEnd: 0,
163+
transferSize: 0,
164+
encodedBodySize: 0,
165+
decodedBodySize: 0,
152166
});
153167

154168
assert(resource instanceof PerformanceEntry);

0 commit comments

Comments
 (0)