2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const primordials = globalThis.__bootstrap.primordials;
|
|
|
|
const {
|
|
|
|
ArrayPrototypeFilter,
|
|
|
|
ArrayPrototypeFind,
|
|
|
|
ArrayPrototypePush,
|
|
|
|
ArrayPrototypeReverse,
|
|
|
|
ArrayPrototypeSlice,
|
|
|
|
ObjectKeys,
|
|
|
|
ObjectPrototypeIsPrototypeOf,
|
|
|
|
ReflectHas,
|
|
|
|
Symbol,
|
|
|
|
SymbolFor,
|
|
|
|
TypeError,
|
|
|
|
} = primordials;
|
2023-03-08 06:44:54 -05:00
|
|
|
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
|
|
|
import { structuredClone } from "ext:deno_web/02_structured_clone.js";
|
2023-04-30 05:11:37 -04:00
|
|
|
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
|
2023-03-08 06:44:54 -05:00
|
|
|
import { EventTarget } from "ext:deno_web/02_event.js";
|
|
|
|
import { opNow } from "ext:deno_web/02_timers.js";
|
|
|
|
import DOMException from "ext:deno_web/01_dom_exception.js";
|
2023-02-07 14:22:46 -05:00
|
|
|
|
|
|
|
const illegalConstructorKey = Symbol("illegalConstructorKey");
|
|
|
|
const customInspect = SymbolFor("Deno.customInspect");
|
|
|
|
let performanceEntries = [];
|
|
|
|
let timeOrigin;
|
|
|
|
|
|
|
|
webidl.converters["PerformanceMarkOptions"] = webidl
|
|
|
|
.createDictionaryConverter(
|
|
|
|
"PerformanceMarkOptions",
|
|
|
|
[
|
|
|
|
{
|
|
|
|
key: "detail",
|
|
|
|
converter: webidl.converters.any,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "startTime",
|
|
|
|
converter: webidl.converters.DOMHighResTimeStamp,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-05-01 06:47:13 -04:00
|
|
|
webidl.converters["DOMString or DOMHighResTimeStamp"] = (
|
|
|
|
V,
|
|
|
|
prefix,
|
|
|
|
context,
|
|
|
|
opts,
|
|
|
|
) => {
|
2023-02-07 14:22:46 -05:00
|
|
|
if (webidl.type(V) === "Number" && V !== null) {
|
2023-05-01 06:47:13 -04:00
|
|
|
return webidl.converters.DOMHighResTimeStamp(V, prefix, context, opts);
|
2022-05-06 13:37:18 -04:00
|
|
|
}
|
2023-05-01 06:47:13 -04:00
|
|
|
return webidl.converters.DOMString(V, prefix, context, opts);
|
2023-02-07 14:22:46 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
webidl.converters["PerformanceMeasureOptions"] = webidl
|
|
|
|
.createDictionaryConverter(
|
|
|
|
"PerformanceMeasureOptions",
|
|
|
|
[
|
|
|
|
{
|
|
|
|
key: "detail",
|
|
|
|
converter: webidl.converters.any,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "start",
|
|
|
|
converter: webidl.converters["DOMString or DOMHighResTimeStamp"],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "duration",
|
|
|
|
converter: webidl.converters.DOMHighResTimeStamp,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "end",
|
|
|
|
converter: webidl.converters["DOMString or DOMHighResTimeStamp"],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
2022-05-06 13:37:18 -04:00
|
|
|
|
2023-05-01 06:47:13 -04:00
|
|
|
webidl.converters["DOMString or PerformanceMeasureOptions"] = (
|
|
|
|
V,
|
|
|
|
prefix,
|
|
|
|
context,
|
|
|
|
opts,
|
|
|
|
) => {
|
2023-02-07 14:22:46 -05:00
|
|
|
if (webidl.type(V) === "Object" && V !== null) {
|
2023-05-01 06:47:13 -04:00
|
|
|
return webidl.converters["PerformanceMeasureOptions"](
|
|
|
|
V,
|
|
|
|
prefix,
|
|
|
|
context,
|
|
|
|
opts,
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2023-05-01 06:47:13 -04:00
|
|
|
return webidl.converters.DOMString(V, prefix, context, opts);
|
2023-02-07 14:22:46 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
function setTimeOrigin(origin) {
|
|
|
|
timeOrigin = origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
function findMostRecent(
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
) {
|
|
|
|
return ArrayPrototypeFind(
|
|
|
|
ArrayPrototypeReverse(ArrayPrototypeSlice(performanceEntries)),
|
|
|
|
(entry) => entry.name === name && entry.entryType === type,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertMarkToTimestamp(mark) {
|
|
|
|
if (typeof mark === "string") {
|
|
|
|
const entry = findMostRecent(mark, "mark");
|
|
|
|
if (!entry) {
|
|
|
|
throw new DOMException(
|
|
|
|
`Cannot find mark: "${mark}".`,
|
|
|
|
"SyntaxError",
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
return entry.startTime;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
if (mark < 0) {
|
|
|
|
throw new TypeError("Mark cannot be negative.");
|
|
|
|
}
|
|
|
|
return mark;
|
|
|
|
}
|
|
|
|
|
|
|
|
function filterByNameType(
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
) {
|
|
|
|
return ArrayPrototypeFilter(
|
|
|
|
performanceEntries,
|
|
|
|
(entry) =>
|
|
|
|
(name ? entry.name === name : true) &&
|
|
|
|
(type ? entry.entryType === type : true),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const now = opNow;
|
|
|
|
|
|
|
|
const _name = Symbol("[[name]]");
|
|
|
|
const _entryType = Symbol("[[entryType]]");
|
|
|
|
const _startTime = Symbol("[[startTime]]");
|
|
|
|
const _duration = Symbol("[[duration]]");
|
|
|
|
class PerformanceEntry {
|
|
|
|
[_name] = "";
|
|
|
|
[_entryType] = "";
|
|
|
|
[_startTime] = 0;
|
|
|
|
[_duration] = 0;
|
|
|
|
|
|
|
|
get name() {
|
|
|
|
webidl.assertBranded(this, PerformanceEntryPrototype);
|
|
|
|
return this[_name];
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get entryType() {
|
|
|
|
webidl.assertBranded(this, PerformanceEntryPrototype);
|
|
|
|
return this[_entryType];
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get startTime() {
|
|
|
|
webidl.assertBranded(this, PerformanceEntryPrototype);
|
|
|
|
return this[_startTime];
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get duration() {
|
|
|
|
webidl.assertBranded(this, PerformanceEntryPrototype);
|
|
|
|
return this[_duration];
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
constructor(
|
|
|
|
name = null,
|
|
|
|
entryType = null,
|
|
|
|
startTime = null,
|
|
|
|
duration = null,
|
|
|
|
key = undefined,
|
|
|
|
) {
|
|
|
|
if (key !== illegalConstructorKey) {
|
|
|
|
webidl.illegalConstructor();
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
this[webidl.brand] = webidl.brand;
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
this[_name] = name;
|
|
|
|
this[_entryType] = entryType;
|
|
|
|
this[_startTime] = startTime;
|
|
|
|
this[_duration] = duration;
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
toJSON() {
|
|
|
|
webidl.assertBranded(this, PerformanceEntryPrototype);
|
|
|
|
return {
|
|
|
|
name: this[_name],
|
|
|
|
entryType: this[_entryType],
|
|
|
|
startTime: this[_startTime],
|
|
|
|
duration: this[_duration],
|
|
|
|
};
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
[customInspect](inspect) {
|
|
|
|
return inspect(createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(
|
|
|
|
PerformanceEntryPrototype,
|
|
|
|
this,
|
|
|
|
),
|
|
|
|
keys: [
|
|
|
|
"name",
|
|
|
|
"entryType",
|
|
|
|
"startTime",
|
|
|
|
"duration",
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
webidl.configurePrototype(PerformanceEntry);
|
|
|
|
const PerformanceEntryPrototype = PerformanceEntry.prototype;
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const _detail = Symbol("[[detail]]");
|
|
|
|
class PerformanceMark extends PerformanceEntry {
|
|
|
|
[_detail] = null;
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get detail() {
|
|
|
|
webidl.assertBranded(this, PerformanceMarkPrototype);
|
|
|
|
return this[_detail];
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get entryType() {
|
|
|
|
webidl.assertBranded(this, PerformanceMarkPrototype);
|
|
|
|
return "mark";
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
constructor(
|
|
|
|
name,
|
|
|
|
options = {},
|
|
|
|
) {
|
|
|
|
const prefix = "Failed to construct 'PerformanceMark'";
|
2023-04-12 15:58:57 -04:00
|
|
|
webidl.requiredArguments(arguments.length, 1, prefix);
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-05-01 06:47:13 -04:00
|
|
|
name = webidl.converters.DOMString(name, prefix, "Argument 1");
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-05-01 06:47:13 -04:00
|
|
|
options = webidl.converters.PerformanceMarkOptions(
|
|
|
|
options,
|
2023-02-07 14:22:46 -05:00
|
|
|
prefix,
|
2023-05-01 06:47:13 -04:00
|
|
|
"Argument 2",
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const { detail = null, startTime = now() } = options;
|
2021-01-24 10:05:18 -05:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
super(name, "mark", startTime, 0, illegalConstructorKey);
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
if (startTime < 0) {
|
|
|
|
throw new TypeError("startTime cannot be negative");
|
|
|
|
}
|
|
|
|
this[_detail] = structuredClone(detail);
|
|
|
|
}
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
toJSON() {
|
|
|
|
webidl.assertBranded(this, PerformanceMarkPrototype);
|
|
|
|
return {
|
|
|
|
name: this.name,
|
|
|
|
entryType: this.entryType,
|
|
|
|
startTime: this.startTime,
|
|
|
|
duration: this.duration,
|
|
|
|
detail: this.detail,
|
|
|
|
};
|
|
|
|
}
|
2021-01-24 10:05:18 -05:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
[customInspect](inspect) {
|
|
|
|
return inspect(createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(PerformanceMarkPrototype, this),
|
|
|
|
keys: [
|
|
|
|
"name",
|
|
|
|
"entryType",
|
|
|
|
"startTime",
|
|
|
|
"duration",
|
|
|
|
"detail",
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
webidl.configurePrototype(PerformanceMark);
|
|
|
|
const PerformanceMarkPrototype = PerformanceMark.prototype;
|
|
|
|
class PerformanceMeasure extends PerformanceEntry {
|
|
|
|
[_detail] = null;
|
|
|
|
|
|
|
|
get detail() {
|
|
|
|
webidl.assertBranded(this, PerformanceMeasurePrototype);
|
|
|
|
return this[_detail];
|
|
|
|
}
|
2021-01-24 10:05:18 -05:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get entryType() {
|
|
|
|
webidl.assertBranded(this, PerformanceMeasurePrototype);
|
|
|
|
return "measure";
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
constructor(
|
|
|
|
name = null,
|
|
|
|
startTime = null,
|
|
|
|
duration = null,
|
|
|
|
detail = null,
|
|
|
|
key = undefined,
|
|
|
|
) {
|
|
|
|
if (key !== illegalConstructorKey) {
|
|
|
|
webidl.illegalConstructor();
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
super(name, "measure", startTime, duration, key);
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
this[_detail] = structuredClone(detail);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
toJSON() {
|
|
|
|
webidl.assertBranded(this, PerformanceMeasurePrototype);
|
|
|
|
return {
|
|
|
|
name: this.name,
|
|
|
|
entryType: this.entryType,
|
|
|
|
startTime: this.startTime,
|
|
|
|
duration: this.duration,
|
|
|
|
detail: this.detail,
|
|
|
|
};
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
[customInspect](inspect) {
|
|
|
|
return inspect(createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(
|
|
|
|
PerformanceMeasurePrototype,
|
|
|
|
this,
|
|
|
|
),
|
|
|
|
keys: [
|
|
|
|
"name",
|
|
|
|
"entryType",
|
|
|
|
"startTime",
|
|
|
|
"duration",
|
|
|
|
"detail",
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
webidl.configurePrototype(PerformanceMeasure);
|
|
|
|
const PerformanceMeasurePrototype = PerformanceMeasure.prototype;
|
|
|
|
class Performance extends EventTarget {
|
|
|
|
constructor(key = null) {
|
|
|
|
if (key != illegalConstructorKey) {
|
|
|
|
webidl.illegalConstructor();
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
super();
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
}
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get timeOrigin() {
|
|
|
|
webidl.assertBranded(this, PerformancePrototype);
|
|
|
|
return timeOrigin;
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
clearMarks(markName = undefined) {
|
|
|
|
webidl.assertBranded(this, PerformancePrototype);
|
|
|
|
if (markName !== undefined) {
|
2023-05-01 06:47:13 -04:00
|
|
|
markName = webidl.converters.DOMString(
|
|
|
|
markName,
|
|
|
|
"Failed to execute 'clearMarks' on 'Performance'",
|
|
|
|
"Argument 1",
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
performanceEntries = ArrayPrototypeFilter(
|
|
|
|
performanceEntries,
|
|
|
|
(entry) => !(entry.name === markName && entry.entryType === "mark"),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
performanceEntries = ArrayPrototypeFilter(
|
|
|
|
performanceEntries,
|
|
|
|
(entry) => entry.entryType !== "mark",
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
2022-05-11 21:15:54 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
clearMeasures(measureName = undefined) {
|
|
|
|
webidl.assertBranded(this, PerformancePrototype);
|
|
|
|
if (measureName !== undefined) {
|
2023-05-01 06:47:13 -04:00
|
|
|
measureName = webidl.converters.DOMString(
|
|
|
|
measureName,
|
|
|
|
"Failed to execute 'clearMeasures' on 'Performance'",
|
|
|
|
"Argument 1",
|
|
|
|
);
|
2022-05-06 13:37:18 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
performanceEntries = ArrayPrototypeFilter(
|
|
|
|
performanceEntries,
|
|
|
|
(entry) =>
|
|
|
|
!(entry.name === measureName && entry.entryType === "measure"),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
performanceEntries = ArrayPrototypeFilter(
|
|
|
|
performanceEntries,
|
|
|
|
(entry) => entry.entryType !== "measure",
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
getEntries() {
|
|
|
|
webidl.assertBranded(this, PerformancePrototype);
|
|
|
|
return filterByNameType();
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
getEntriesByName(
|
|
|
|
name,
|
|
|
|
type = undefined,
|
|
|
|
) {
|
|
|
|
webidl.assertBranded(this, PerformancePrototype);
|
|
|
|
const prefix = "Failed to execute 'getEntriesByName' on 'Performance'";
|
2023-04-12 15:58:57 -04:00
|
|
|
webidl.requiredArguments(arguments.length, 1, prefix);
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-05-01 06:47:13 -04:00
|
|
|
name = webidl.converters.DOMString(name, prefix, "Argument 1");
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
if (type !== undefined) {
|
2023-05-01 06:47:13 -04:00
|
|
|
type = webidl.converters.DOMString(type, prefix, "Argument 2");
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
return filterByNameType(name, type);
|
|
|
|
}
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
getEntriesByType(type) {
|
|
|
|
webidl.assertBranded(this, PerformancePrototype);
|
|
|
|
const prefix = "Failed to execute 'getEntriesByName' on 'Performance'";
|
2023-04-12 15:58:57 -04:00
|
|
|
webidl.requiredArguments(arguments.length, 1, prefix);
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-05-01 06:47:13 -04:00
|
|
|
type = webidl.converters.DOMString(type, prefix, "Argument 1");
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
return filterByNameType(undefined, type);
|
|
|
|
}
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
mark(
|
|
|
|
markName,
|
|
|
|
markOptions = {},
|
|
|
|
) {
|
|
|
|
webidl.assertBranded(this, PerformancePrototype);
|
|
|
|
const prefix = "Failed to execute 'mark' on 'Performance'";
|
2023-04-12 15:58:57 -04:00
|
|
|
webidl.requiredArguments(arguments.length, 1, prefix);
|
2023-02-07 14:22:46 -05:00
|
|
|
|
2023-05-01 06:47:13 -04:00
|
|
|
markName = webidl.converters.DOMString(markName, prefix, "Argument 1");
|
2023-02-07 14:22:46 -05:00
|
|
|
|
2023-05-01 06:47:13 -04:00
|
|
|
markOptions = webidl.converters.PerformanceMarkOptions(
|
|
|
|
markOptions,
|
2023-02-07 14:22:46 -05:00
|
|
|
prefix,
|
2023-05-01 06:47:13 -04:00
|
|
|
"Argument 2",
|
|
|
|
);
|
2023-02-07 14:22:46 -05:00
|
|
|
|
|
|
|
// 3.1.1.1 If the global object is a Window object and markName uses the
|
|
|
|
// same name as a read only attribute in the PerformanceTiming interface,
|
|
|
|
// throw a SyntaxError. - not implemented
|
|
|
|
const entry = new PerformanceMark(markName, markOptions);
|
|
|
|
// 3.1.1.7 Queue entry - not implemented
|
|
|
|
ArrayPrototypePush(performanceEntries, entry);
|
|
|
|
return entry;
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
measure(
|
|
|
|
measureName,
|
|
|
|
startOrMeasureOptions = {},
|
|
|
|
endMark = undefined,
|
|
|
|
) {
|
|
|
|
webidl.assertBranded(this, PerformancePrototype);
|
|
|
|
const prefix = "Failed to execute 'measure' on 'Performance'";
|
2023-04-12 15:58:57 -04:00
|
|
|
webidl.requiredArguments(arguments.length, 1, prefix);
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-05-01 06:47:13 -04:00
|
|
|
measureName = webidl.converters.DOMString(
|
|
|
|
measureName,
|
2023-02-07 14:22:46 -05:00
|
|
|
prefix,
|
2023-05-01 06:47:13 -04:00
|
|
|
"Argument 1",
|
|
|
|
);
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
startOrMeasureOptions = webidl.converters
|
2023-05-01 06:47:13 -04:00
|
|
|
["DOMString or PerformanceMeasureOptions"](
|
|
|
|
startOrMeasureOptions,
|
2021-07-05 07:17:11 -04:00
|
|
|
prefix,
|
2023-05-01 06:47:13 -04:00
|
|
|
"Argument 2",
|
|
|
|
);
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
if (endMark !== undefined) {
|
2023-05-01 06:47:13 -04:00
|
|
|
endMark = webidl.converters.DOMString(endMark, prefix, "Argument 3");
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
if (
|
|
|
|
startOrMeasureOptions && typeof startOrMeasureOptions === "object" &&
|
|
|
|
ObjectKeys(startOrMeasureOptions).length > 0
|
|
|
|
) {
|
|
|
|
if (endMark) {
|
|
|
|
throw new TypeError("Options cannot be passed with endMark.");
|
2021-07-05 07:17:11 -04:00
|
|
|
}
|
2020-10-19 22:43:29 -04:00
|
|
|
if (
|
2023-02-07 14:22:46 -05:00
|
|
|
!ReflectHas(startOrMeasureOptions, "start") &&
|
|
|
|
!ReflectHas(startOrMeasureOptions, "end")
|
2020-07-19 13:49:44 -04:00
|
|
|
) {
|
2023-02-07 14:22:46 -05:00
|
|
|
throw new TypeError(
|
|
|
|
"A start or end mark must be supplied in options.",
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
if (
|
2023-02-07 14:22:46 -05:00
|
|
|
ReflectHas(startOrMeasureOptions, "start") &&
|
|
|
|
ReflectHas(startOrMeasureOptions, "duration") &&
|
|
|
|
ReflectHas(startOrMeasureOptions, "end")
|
2020-07-19 13:49:44 -04:00
|
|
|
) {
|
2023-02-07 14:22:46 -05:00
|
|
|
throw new TypeError(
|
|
|
|
"Cannot specify start, end, and duration together in options.",
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2021-07-05 07:17:11 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
let endTime;
|
|
|
|
if (endMark) {
|
|
|
|
endTime = convertMarkToTimestamp(endMark);
|
|
|
|
} else if (
|
|
|
|
typeof startOrMeasureOptions === "object" &&
|
|
|
|
ReflectHas(startOrMeasureOptions, "end")
|
|
|
|
) {
|
|
|
|
endTime = convertMarkToTimestamp(startOrMeasureOptions.end);
|
|
|
|
} else if (
|
|
|
|
typeof startOrMeasureOptions === "object" &&
|
|
|
|
ReflectHas(startOrMeasureOptions, "start") &&
|
|
|
|
ReflectHas(startOrMeasureOptions, "duration")
|
|
|
|
) {
|
|
|
|
const start = convertMarkToTimestamp(startOrMeasureOptions.start);
|
|
|
|
const duration = convertMarkToTimestamp(startOrMeasureOptions.duration);
|
|
|
|
endTime = start + duration;
|
|
|
|
} else {
|
|
|
|
endTime = now();
|
|
|
|
}
|
|
|
|
let startTime;
|
|
|
|
if (
|
|
|
|
typeof startOrMeasureOptions === "object" &&
|
|
|
|
ReflectHas(startOrMeasureOptions, "start")
|
|
|
|
) {
|
|
|
|
startTime = convertMarkToTimestamp(startOrMeasureOptions.start);
|
|
|
|
} else if (
|
|
|
|
typeof startOrMeasureOptions === "object" &&
|
|
|
|
ReflectHas(startOrMeasureOptions, "end") &&
|
|
|
|
ReflectHas(startOrMeasureOptions, "duration")
|
|
|
|
) {
|
|
|
|
const end = convertMarkToTimestamp(startOrMeasureOptions.end);
|
|
|
|
const duration = convertMarkToTimestamp(startOrMeasureOptions.duration);
|
|
|
|
startTime = end - duration;
|
|
|
|
} else if (typeof startOrMeasureOptions === "string") {
|
|
|
|
startTime = convertMarkToTimestamp(startOrMeasureOptions);
|
|
|
|
} else {
|
|
|
|
startTime = 0;
|
|
|
|
}
|
|
|
|
const entry = new PerformanceMeasure(
|
|
|
|
measureName,
|
|
|
|
startTime,
|
|
|
|
endTime - startTime,
|
|
|
|
typeof startOrMeasureOptions === "object"
|
|
|
|
? startOrMeasureOptions.detail ?? null
|
|
|
|
: null,
|
|
|
|
illegalConstructorKey,
|
|
|
|
);
|
|
|
|
ArrayPrototypePush(performanceEntries, entry);
|
|
|
|
return entry;
|
|
|
|
}
|
2021-07-05 07:17:11 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
now() {
|
|
|
|
webidl.assertBranded(this, PerformancePrototype);
|
|
|
|
return now();
|
2021-07-05 07:17:11 -04:00
|
|
|
}
|
2020-09-19 17:30:59 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
toJSON() {
|
|
|
|
webidl.assertBranded(this, PerformancePrototype);
|
|
|
|
return {
|
|
|
|
timeOrigin: this.timeOrigin,
|
|
|
|
};
|
|
|
|
}
|
2022-05-11 21:15:54 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
[customInspect](inspect) {
|
|
|
|
return inspect(createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(PerformancePrototype, this),
|
|
|
|
keys: [],
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
webidl.configurePrototype(Performance);
|
|
|
|
const PerformancePrototype = Performance.prototype;
|
|
|
|
|
|
|
|
webidl.converters["Performance"] = webidl.createInterfaceConverter(
|
|
|
|
"Performance",
|
|
|
|
PerformancePrototype,
|
|
|
|
);
|
|
|
|
|
|
|
|
const performance = new Performance(illegalConstructorKey);
|
|
|
|
|
|
|
|
export {
|
|
|
|
Performance,
|
|
|
|
performance,
|
|
|
|
PerformanceEntry,
|
|
|
|
PerformanceMark,
|
|
|
|
PerformanceMeasure,
|
|
|
|
setTimeOrigin,
|
|
|
|
};
|