mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix: make Performance global an EventTarget
This commit updates the Performance global to extend EventTarget.
This commit is contained in:
parent
364da468d2
commit
95312ab53a
4 changed files with 30 additions and 11 deletions
2
cli/dts/lib.deno.shared_globals.d.ts
vendored
2
cli/dts/lib.deno.shared_globals.d.ts
vendored
|
@ -449,7 +449,7 @@ declare class Worker extends EventTarget {
|
|||
|
||||
declare type PerformanceEntryList = PerformanceEntry[];
|
||||
|
||||
declare class Performance {
|
||||
declare class Performance extends EventTarget {
|
||||
/** Returns a timestamp representing the start of the performance measurement. */
|
||||
readonly timeOrigin: number;
|
||||
constructor();
|
||||
|
|
|
@ -140,3 +140,16 @@ Deno.test(function performanceMeasureIllegalConstructor() {
|
|||
"Illegal constructor",
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test(function performanceIsEventTarget() {
|
||||
assert(performance instanceof EventTarget);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const handler = () => {
|
||||
resolve();
|
||||
};
|
||||
|
||||
performance.addEventListener("test", handler, { once: true });
|
||||
performance.dispatchEvent(new Event("test"));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -327,9 +327,14 @@
|
|||
}
|
||||
webidl.configurePrototype(PerformanceMeasure);
|
||||
const PerformanceMeasurePrototype = PerformanceMeasure.prototype;
|
||||
class Performance {
|
||||
constructor() {
|
||||
webidl.illegalConstructor();
|
||||
class Performance extends EventTarget {
|
||||
constructor(key = null) {
|
||||
if (key != illegalConstructorKey) {
|
||||
webidl.illegalConstructor();
|
||||
}
|
||||
|
||||
super();
|
||||
this[webidl.brand] = webidl.brand;
|
||||
}
|
||||
|
||||
get timeOrigin() {
|
||||
|
@ -572,12 +577,17 @@
|
|||
webidl.configurePrototype(Performance);
|
||||
const PerformancePrototype = Performance.prototype;
|
||||
|
||||
webidl.converters["Performance"] = webidl.createInterfaceConverter(
|
||||
"Performance",
|
||||
PerformancePrototype,
|
||||
);
|
||||
|
||||
window.__bootstrap.performance = {
|
||||
PerformanceEntry,
|
||||
PerformanceMark,
|
||||
PerformanceMeasure,
|
||||
Performance,
|
||||
performance: webidl.createBranded(Performance),
|
||||
performance: new Performance(illegalConstructorKey),
|
||||
setTimeOrigin,
|
||||
};
|
||||
})(this);
|
||||
|
|
|
@ -1161,12 +1161,8 @@
|
|||
"hr-time": {
|
||||
"monotonic-clock.any.html": true,
|
||||
"monotonic-clock.any.worker.html": true,
|
||||
"basic.any.html": [
|
||||
"Performance interface extends EventTarget."
|
||||
],
|
||||
"basic.any.worker.html": [
|
||||
"Performance interface extends EventTarget."
|
||||
],
|
||||
"basic.any.html": true,
|
||||
"basic.any.worker.html": true,
|
||||
"idlharness.any.html": [
|
||||
"Performance interface: existence and properties of interface object",
|
||||
"Performance interface: existence and properties of interface prototype object",
|
||||
|
|
Loading…
Reference in a new issue