perf_hooks: align toStringTag with other Web Performance implementations
This gets `Symbol.toStringTag` on Web Performance APIs to be aligned with the other runtime implementations. Signed-off-by: Daeyeon Jeong <daeyeon.dev@gmail.com> PR-URL: https://github.com/nodejs/node/pull/45157 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Feng Yu <F3n67u@outlook.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
b6eba6b72a
commit
631bdb4f3e
@ -29,10 +29,6 @@ class PerformanceResourceTiming extends PerformanceEntry {
|
|||||||
throw new ERR_ILLEGAL_CONSTRUCTOR();
|
throw new ERR_ILLEGAL_CONSTRUCTOR();
|
||||||
}
|
}
|
||||||
|
|
||||||
get [SymbolToStringTag]() {
|
|
||||||
return 'PerformanceResourceTiming';
|
|
||||||
}
|
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
validateInternalField(this, kRequestedUrl, 'PerformanceResourceTiming');
|
validateInternalField(this, kRequestedUrl, 'PerformanceResourceTiming');
|
||||||
return this[kRequestedUrl];
|
return this[kRequestedUrl];
|
||||||
@ -185,6 +181,11 @@ ObjectDefineProperties(PerformanceResourceTiming.prototype, {
|
|||||||
encodedBodySize: kEnumerableProperty,
|
encodedBodySize: kEnumerableProperty,
|
||||||
decodedBodySize: kEnumerableProperty,
|
decodedBodySize: kEnumerableProperty,
|
||||||
toJSON: kEnumerableProperty,
|
toJSON: kEnumerableProperty,
|
||||||
|
[SymbolToStringTag]: {
|
||||||
|
__proto__: null,
|
||||||
|
configurable: true,
|
||||||
|
value: 'PerformanceResourceTiming',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function createPerformanceResourceTiming(requestedUrl, initiatorType, timingInfo, cacheMode = '') {
|
function createPerformanceResourceTiming(requestedUrl, initiatorType, timingInfo, cacheMode = '') {
|
||||||
|
@ -98,10 +98,6 @@ class PerformanceMark {
|
|||||||
return this[kDetail];
|
return this[kDetail];
|
||||||
}
|
}
|
||||||
|
|
||||||
get [SymbolToStringTag]() {
|
|
||||||
return 'PerformanceMark';
|
|
||||||
}
|
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
@ -116,6 +112,11 @@ ObjectSetPrototypeOf(PerformanceMark, PerformanceEntry);
|
|||||||
ObjectSetPrototypeOf(PerformanceMark.prototype, PerformanceEntry.prototype);
|
ObjectSetPrototypeOf(PerformanceMark.prototype, PerformanceEntry.prototype);
|
||||||
ObjectDefineProperties(PerformanceMark.prototype, {
|
ObjectDefineProperties(PerformanceMark.prototype, {
|
||||||
detail: kEnumerableProperty,
|
detail: kEnumerableProperty,
|
||||||
|
[SymbolToStringTag]: {
|
||||||
|
__proto__: null,
|
||||||
|
configurable: true,
|
||||||
|
value: 'PerformanceMark',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
class PerformanceMeasure extends PerformanceEntry {
|
class PerformanceMeasure extends PerformanceEntry {
|
||||||
@ -127,13 +128,14 @@ class PerformanceMeasure extends PerformanceEntry {
|
|||||||
validateInternalField(this, kDetail, 'PerformanceMeasure');
|
validateInternalField(this, kDetail, 'PerformanceMeasure');
|
||||||
return this[kDetail];
|
return this[kDetail];
|
||||||
}
|
}
|
||||||
|
|
||||||
get [SymbolToStringTag]() {
|
|
||||||
return 'PerformanceMeasure';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ObjectDefineProperties(PerformanceMeasure.prototype, {
|
ObjectDefineProperties(PerformanceMeasure.prototype, {
|
||||||
detail: kEnumerableProperty,
|
detail: kEnumerableProperty,
|
||||||
|
[SymbolToStringTag]: {
|
||||||
|
__proto__: null,
|
||||||
|
configurable: true,
|
||||||
|
value: 'PerformanceMeasure',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function createPerformanceMeasure(name, start, duration, detail) {
|
function createPerformanceMeasure(name, start, duration, detail) {
|
||||||
|
@ -17,6 +17,11 @@ assert(PerformanceResourceTiming);
|
|||||||
assert(performance.clearResourceTimings);
|
assert(performance.clearResourceTimings);
|
||||||
assert(performance.markResourceTiming);
|
assert(performance.markResourceTiming);
|
||||||
|
|
||||||
|
assert.deepStrictEqual(
|
||||||
|
Object.getOwnPropertyDescriptor(PerformanceResourceTiming.prototype, Symbol.toStringTag),
|
||||||
|
{ configurable: true, enumerable: false, value: 'PerformanceResourceTiming', writable: false },
|
||||||
|
);
|
||||||
|
|
||||||
function createTimingInfo({
|
function createTimingInfo({
|
||||||
startTime = 0,
|
startTime = 0,
|
||||||
redirectStartTime = 0,
|
redirectStartTime = 0,
|
||||||
|
@ -6,6 +6,7 @@ const {
|
|||||||
PerformanceObserver,
|
PerformanceObserver,
|
||||||
PerformanceEntry,
|
PerformanceEntry,
|
||||||
PerformanceMark,
|
PerformanceMark,
|
||||||
|
PerformanceMeasure,
|
||||||
performance,
|
performance,
|
||||||
performance: {
|
performance: {
|
||||||
nodeTiming,
|
nodeTiming,
|
||||||
@ -18,6 +19,18 @@ assert(PerformanceMark);
|
|||||||
assert(performance.mark);
|
assert(performance.mark);
|
||||||
assert(performance.measure);
|
assert(performance.measure);
|
||||||
|
|
||||||
|
[PerformanceMark, PerformanceMeasure].forEach((c) => {
|
||||||
|
assert.deepStrictEqual(
|
||||||
|
Object.getOwnPropertyDescriptor(c.prototype, Symbol.toStringTag),
|
||||||
|
{
|
||||||
|
configurable: true,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
value: c.name,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
[undefined, 'a', 'null', 1, true].forEach((i) => {
|
[undefined, 'a', 'null', 1, true].forEach((i) => {
|
||||||
const m = performance.mark(i);
|
const m = performance.mark(i);
|
||||||
assert(m instanceof PerformanceEntry);
|
assert(m instanceof PerformanceEntry);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user