Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1f7c2a9

Browse filesBrowse files
KhafraDevtargos
authored andcommitted
perf_hooks: add deliveryType and responseStatus fields
PR-URL: #51589 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 11e9789 commit 1f7c2a9
Copy full SHA for 1f7c2a9

File tree

Expand file treeCollapse file tree

8 files changed

+96
-24
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+96
-24
lines changed
Open diff view settings
Collapse file

‎doc/api/perf_hooks.md‎

Copy file name to clipboardExpand all lines: doc/api/perf_hooks.md
+9-1Lines changed: 9 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -246,19 +246,26 @@ and can be queried with `performance.getEntries`,
246246
observation is performed, the entries should be cleared from the global
247247
Performance Timeline manually with `performance.clearMarks`.
248248

249-
### `performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, global, cacheMode)`
249+
### `performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, global, cacheMode, bodyInfo, responseStatus[, deliveryType])`
250250

251251
<!-- YAML
252252
added:
253253
- v18.2.0
254254
- v16.17.0
255+
changes:
256+
- version: REPLACEME
257+
pr-url: https://github.com/nodejs/node/pull/51589
258+
description: Added bodyInfo, responseStatus, and deliveryType arguments.
255259
-->
256260

257261
* `timingInfo` {Object} [Fetch Timing Info][]
258262
* `requestedUrl` {string} The resource url
259263
* `initiatorType` {string} The initiator name, e.g: 'fetch'
260264
* `global` {Object}
261265
* `cacheMode` {string} The cache mode must be an empty string ('') or 'local'
266+
* `bodyInfo` {Object} [Fetch Response Body Info][]
267+
* `responseStatus` {number} The response's status code
268+
* `deliveryType` {string} The delivery type. **Default:** `''`.
262269

263270
_This property is an extension by Node.js. It is not available in Web browsers._
264271

@@ -1911,6 +1918,7 @@ dns.promises.resolve('localhost');
19111918
```
19121919

19131920
[Async Hooks]: async_hooks.md
1921+
[Fetch Response Body Info]: https://fetch.spec.whatwg.org/#response-body-info
19141922
[Fetch Timing Info]: https://fetch.spec.whatwg.org/#fetch-timing-info
19151923
[High Resolution Time]: https://www.w3.org/TR/hr-time-2
19161924
[Performance Timeline]: https://w3c.github.io/performance-timeline/
Collapse file

‎lib/internal/perf/resource_timing.js‎

Copy file name to clipboardExpand all lines: lib/internal/perf/resource_timing.js
+33-1Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const kCacheMode = Symbol('kCacheMode');
2121
const kRequestedUrl = Symbol('kRequestedUrl');
2222
const kTimingInfo = Symbol('kTimingInfo');
2323
const kInitiatorType = Symbol('kInitiatorType');
24+
const kDeliveryType = Symbol('kDeliveryType');
25+
const kResponseStatus = Symbol('kResponseStatus');
2426

2527
class PerformanceResourceTiming extends PerformanceEntry {
2628
constructor(skipThrowSymbol = undefined, name = undefined, type = undefined) {
@@ -136,6 +138,16 @@ class PerformanceResourceTiming extends PerformanceEntry {
136138
return this[kTimingInfo].encodedBodySize + 300;
137139
}
138140

141+
get deliveryType() {
142+
validateInternalField(this, kTimingInfo, 'PerformanceResourceTiming');
143+
return this[kDeliveryType];
144+
}
145+
146+
get responseStatus() {
147+
validateInternalField(this, kTimingInfo, 'PerformanceResourceTiming');
148+
return this[kResponseStatus];
149+
}
150+
139151
toJSON() {
140152
validateInternalField(this, kInitiatorType, 'PerformanceResourceTiming');
141153
return {
@@ -160,6 +172,8 @@ class PerformanceResourceTiming extends PerformanceEntry {
160172
transferSize: this.transferSize,
161173
encodedBodySize: this.encodedBodySize,
162174
decodedBodySize: this.decodedBodySize,
175+
deliveryType: this.deliveryType,
176+
responseStatus: this.responseStatus,
163177
};
164178
}
165179
}
@@ -182,6 +196,8 @@ ObjectDefineProperties(PerformanceResourceTiming.prototype, {
182196
transferSize: kEnumerableProperty,
183197
encodedBodySize: kEnumerableProperty,
184198
decodedBodySize: kEnumerableProperty,
199+
deliveryType: kEnumerableProperty,
200+
responseStatus: kEnumerableProperty,
185201
toJSON: kEnumerableProperty,
186202
[SymbolToStringTag]: {
187203
__proto__: null,
@@ -190,7 +206,15 @@ ObjectDefineProperties(PerformanceResourceTiming.prototype, {
190206
},
191207
});
192208

193-
function createPerformanceResourceTiming(requestedUrl, initiatorType, timingInfo, cacheMode = '') {
209+
function createPerformanceResourceTiming(
210+
requestedUrl,
211+
initiatorType,
212+
timingInfo,
213+
cacheMode = '',
214+
bodyInfo,
215+
responseStatus,
216+
deliveryType,
217+
) {
194218
const resourceTiming = new PerformanceResourceTiming(kSkipThrow, requestedUrl, 'resource');
195219

196220
resourceTiming[kInitiatorType] = initiatorType;
@@ -200,6 +224,8 @@ function createPerformanceResourceTiming(requestedUrl, initiatorType, timingInfo
200224
// The spec doesn't say to validate it in the class construction.
201225
resourceTiming[kTimingInfo] = timingInfo;
202226
resourceTiming[kCacheMode] = cacheMode;
227+
resourceTiming[kDeliveryType] = deliveryType;
228+
resourceTiming[kResponseStatus] = responseStatus;
203229

204230
return resourceTiming;
205231
}
@@ -211,6 +237,9 @@ function markResourceTiming(
211237
initiatorType,
212238
global,
213239
cacheMode,
240+
bodyInfo,
241+
responseStatus,
242+
deliveryType = '',
214243
) {
215244
// https://w3c.github.io/resource-timing/#dfn-setup-the-resource-timing-entry
216245
assert(
@@ -222,6 +251,9 @@ function markResourceTiming(
222251
initiatorType,
223252
timingInfo,
224253
cacheMode,
254+
bodyInfo,
255+
responseStatus,
256+
deliveryType,
225257
);
226258

227259
enqueue(resource);
Collapse file

‎test/parallel/test-perf-hooks-resourcetiming.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-perf-hooks-resourcetiming.js
+22-2Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ function createTimingInfo({
8686
initiatorType,
8787
customGlobal,
8888
cacheMode,
89+
{},
90+
200,
91+
'',
8992
);
9093

9194
assert(resource instanceof PerformanceEntry);
@@ -128,6 +131,9 @@ function createTimingInfo({
128131
initiatorType,
129132
customGlobal,
130133
cacheMode,
134+
{},
135+
200,
136+
'',
131137
);
132138

133139
assert(resource instanceof PerformanceEntry);
@@ -155,6 +161,8 @@ function createTimingInfo({
155161
assert.strictEqual(resource.encodedBodySize, 0);
156162
assert.strictEqual(resource.decodedBodySize, 0);
157163
assert.strictEqual(resource.transferSize, 0);
164+
assert.strictEqual(resource.deliveryType, '');
165+
assert.strictEqual(resource.responseStatus, 200);
158166
assert.deepStrictEqual(resource.toJSON(), {
159167
name: requestedUrl,
160168
entryType: 'resource',
@@ -177,6 +185,8 @@ function createTimingInfo({
177185
transferSize: 0,
178186
encodedBodySize: 0,
179187
decodedBodySize: 0,
188+
responseStatus: 200,
189+
deliveryType: '',
180190
});
181191
assert.strictEqual(util.inspect(performance.getEntries()), `[
182192
PerformanceResourceTiming {
@@ -200,7 +210,9 @@ function createTimingInfo({
200210
responseEnd: 0,
201211
transferSize: 0,
202212
encodedBodySize: 0,
203-
decodedBodySize: 0
213+
decodedBodySize: 0,
214+
deliveryType: '',
215+
responseStatus: 200
204216
}
205217
]`);
206218
assert.strictEqual(util.inspect(resource), `PerformanceResourceTiming {
@@ -224,7 +236,9 @@ function createTimingInfo({
224236
responseEnd: 0,
225237
transferSize: 0,
226238
encodedBodySize: 0,
227-
decodedBodySize: 0
239+
decodedBodySize: 0,
240+
deliveryType: '',
241+
responseStatus: 200
228242
}`);
229243

230244
assert(resource instanceof PerformanceEntry);
@@ -252,6 +266,9 @@ function createTimingInfo({
252266
initiatorType,
253267
customGlobal,
254268
cacheMode,
269+
{},
270+
200,
271+
'',
255272
);
256273

257274
assert(resource instanceof PerformanceEntry);
@@ -307,6 +324,9 @@ function createTimingInfo({
307324
initiatorType,
308325
customGlobal,
309326
cacheMode,
327+
{},
328+
200,
329+
''
310330
);
311331

312332
assert(resource instanceof PerformanceEntry);
Collapse file

‎test/parallel/test-performance-resourcetimingbufferfull.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-performance-resourcetimingbufferfull.js
+18-9Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,19 @@ const cacheMode = '';
3434

3535
async function main() {
3636
performance.setResourceTimingBufferSize(1);
37-
performance.markResourceTiming(createTimingInfo(1), requestedUrl, initiatorType, globalThis, cacheMode);
37+
const args = [
38+
requestedUrl,
39+
initiatorType,
40+
globalThis,
41+
cacheMode,
42+
{}, // body info
43+
200,
44+
'',
45+
];
46+
performance.markResourceTiming(createTimingInfo(1), ...args);
3847
// Trigger a resourcetimingbufferfull event.
39-
performance.markResourceTiming(createTimingInfo(2), requestedUrl, initiatorType, globalThis, cacheMode);
40-
performance.markResourceTiming(createTimingInfo(3), requestedUrl, initiatorType, globalThis, cacheMode);
48+
performance.markResourceTiming(createTimingInfo(2), ...args);
49+
performance.markResourceTiming(createTimingInfo(3), ...args);
4150
assert.strictEqual(performance.getEntriesByType('resource').length, 1);
4251

4352
// Clear resource timings on resourcetimingbufferfull event.
@@ -65,10 +74,10 @@ async function main() {
6574

6675
performance.clearResourceTimings();
6776
performance.setResourceTimingBufferSize(1);
68-
performance.markResourceTiming(createTimingInfo(4), requestedUrl, initiatorType, globalThis, cacheMode);
77+
performance.markResourceTiming(createTimingInfo(4), ...args);
6978
// Trigger a resourcetimingbufferfull event.
70-
performance.markResourceTiming(createTimingInfo(5), requestedUrl, initiatorType, globalThis, cacheMode);
71-
performance.markResourceTiming(createTimingInfo(6), requestedUrl, initiatorType, globalThis, cacheMode);
79+
performance.markResourceTiming(createTimingInfo(5), ...args);
80+
performance.markResourceTiming(createTimingInfo(6), ...args);
7281

7382
// Increase the buffer size on resourcetimingbufferfull event.
7483
await new Promise((resolve) => {
@@ -96,10 +105,10 @@ async function main() {
96105

97106
performance.clearResourceTimings();
98107
performance.setResourceTimingBufferSize(2);
99-
performance.markResourceTiming(createTimingInfo(7), requestedUrl, initiatorType, globalThis, cacheMode);
100-
performance.markResourceTiming(createTimingInfo(8), requestedUrl, initiatorType, globalThis, cacheMode);
108+
performance.markResourceTiming(createTimingInfo(7), ...args);
109+
performance.markResourceTiming(createTimingInfo(8), ...args);
101110
// Trigger a resourcetimingbufferfull event.
102-
performance.markResourceTiming(createTimingInfo(9), requestedUrl, initiatorType, globalThis, cacheMode);
111+
performance.markResourceTiming(createTimingInfo(9), ...args);
103112

104113
// Decrease the buffer size on resourcetimingbufferfull event.
105114
await new Promise((resolve) => {
Collapse file

‎test/parallel/test-performance-resourcetimingbuffersize.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-performance-resourcetimingbuffersize.js
+12-5Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,28 @@ const initiatorType = '';
3030
const cacheMode = '';
3131

3232
async function main() {
33+
const args = [
34+
timingInfo,
35+
requestedUrl,
36+
initiatorType,
37+
globalThis,
38+
cacheMode,
39+
];
3340
// Invalid buffer size values are converted to 0.
3441
const invalidValues = [ null, undefined, true, false, -1, 0.5, Infinity, NaN, '', 'foo', {}, [], () => {} ];
3542
for (const value of invalidValues) {
3643
performance.setResourceTimingBufferSize(value);
37-
performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, globalThis, cacheMode);
44+
performance.markResourceTiming(...args);
3845
assert.strictEqual(performance.getEntriesByType('resource').length, 0);
3946
performance.clearResourceTimings();
4047
}
4148
// Wait for the buffer full event to be cleared.
4249
await waitBufferFullEvent();
4350

4451
performance.setResourceTimingBufferSize(1);
45-
performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, globalThis, cacheMode);
52+
performance.markResourceTiming(...args);
4653
// Trigger a resourcetimingbufferfull event.
47-
performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, globalThis, cacheMode);
54+
performance.markResourceTiming(...args);
4855
assert.strictEqual(performance.getEntriesByType('resource').length, 1);
4956
await waitBufferFullEvent();
5057

@@ -56,14 +63,14 @@ async function main() {
5663
performance.clearResourceTimings();
5764
assert.strictEqual(performance.getEntriesByType('resource').length, 0);
5865
// Trigger a resourcetimingbufferfull event.
59-
performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, globalThis, cacheMode);
66+
performance.markResourceTiming(...args);
6067
// New entry is not added to the global buffer.
6168
assert.strictEqual(performance.getEntriesByType('resource').length, 0);
6269
await waitBufferFullEvent();
6370

6471
// Apply a new buffer size limit
6572
performance.setResourceTimingBufferSize(1);
66-
performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, globalThis, cacheMode);
73+
performance.markResourceTiming(...args);
6774
assert.strictEqual(performance.getEntriesByType('resource').length, 1);
6875
}
6976

Collapse file

‎test/wpt/status/resource-timing.json‎

Copy file name to clipboardExpand all lines: test/wpt/status/resource-timing.json
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@
2323
"idlharness.any.js": {
2424
"fail": {
2525
"expected": [
26-
"PerformanceResourceTiming interface: attribute deliveryType",
2726
"PerformanceResourceTiming interface: attribute firstInterimResponseStart",
28-
"PerformanceResourceTiming interface: attribute responseStatus",
2927
"PerformanceResourceTiming interface: attribute renderBlockingStatus",
3028
"PerformanceResourceTiming interface: attribute contentType",
31-
"PerformanceResourceTiming interface: resource must inherit property \"deliveryType\" with the proper type",
3229
"PerformanceResourceTiming interface: resource must inherit property \"firstInterimResponseStart\" with the proper type",
33-
"PerformanceResourceTiming interface: resource must inherit property \"responseStatus\" with the proper type",
3430
"PerformanceResourceTiming interface: resource must inherit property \"renderBlockingStatus\" with the proper type",
3531
"PerformanceResourceTiming interface: resource must inherit property \"contentType\" with the proper type",
3632
"PerformanceResourceTiming interface: default toJSON operation on resource"
Collapse file

‎test/wpt/test-performance-timeline.js‎

Copy file name to clipboardExpand all lines: test/wpt/test-performance-timeline.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ runner.setInitScript(`
2727
finalNetworkResponseStartTime: 0,
2828
encodedBodySize: 0,
2929
decodedBodySize: 0,
30-
}, 'https://nodejs.org', '', global, '');
30+
}, 'https://nodejs.org', '', global, '', {}, 200, '');
3131
`);
3232

3333
runner.runJsTests();
Collapse file

‎test/wpt/test-resource-timing.js‎

Copy file name to clipboardExpand all lines: test/wpt/test-resource-timing.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ runner.setInitScript(`
2525
finalNetworkResponseStartTime: 0,
2626
encodedBodySize: 0,
2727
decodedBodySize: 0,
28-
}, 'https://nodejs.org', '', global, '');
28+
}, 'https://nodejs.org', '', global, '', {}, 200, '');
2929
`);
3030

3131
runner.runJsTests();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.