deno.land / x / deno@v1.28.2 / ext / web / 15_performance.js
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license."use strict";
((window) => { const { ArrayPrototypeFilter, ArrayPrototypeFind, ArrayPrototypePush, ArrayPrototypeReverse, ArrayPrototypeSlice, ObjectKeys, ObjectPrototypeIsPrototypeOf, ReflectHas, Symbol, SymbolFor, TypeError, } = window.__bootstrap.primordials;
const { webidl, structuredClone } = window.__bootstrap; const consoleInternal = window.__bootstrap.console; const { EventTarget } = window.__bootstrap.eventTarget; const { opNow } = window.__bootstrap.timers; const { DOMException } = window.__bootstrap.domException;
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, }, ], );
webidl.converters["DOMString or DOMHighResTimeStamp"] = (V, opts) => { if (webidl.type(V) === "Number" && V !== null) { return webidl.converters.DOMHighResTimeStamp(V, opts); } return webidl.converters.DOMString(V, opts); };
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"], }, ], );
webidl.converters["DOMString or PerformanceMeasureOptions"] = (V, opts) => { if (webidl.type(V) === "Object" && V !== null) { return webidl.converters["PerformanceMeasureOptions"](V, opts); } return webidl.converters.DOMString(V, opts); };
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", ); } return entry.startTime; } 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]; }
get entryType() { webidl.assertBranded(this, PerformanceEntryPrototype); return this[_entryType]; }
get startTime() { webidl.assertBranded(this, PerformanceEntryPrototype); return this[_startTime]; }
get duration() { webidl.assertBranded(this, PerformanceEntryPrototype); return this[_duration]; }
constructor( name = null, entryType = null, startTime = null, duration = null, key = undefined, ) { if (key !== illegalConstructorKey) { webidl.illegalConstructor(); } this[webidl.brand] = webidl.brand;
this[_name] = name; this[_entryType] = entryType; this[_startTime] = startTime; this[_duration] = duration; }
toJSON() { webidl.assertBranded(this, PerformanceEntryPrototype); return { name: this[_name], entryType: this[_entryType], startTime: this[_startTime], duration: this[_duration], }; }
[customInspect](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, evaluate: ObjectPrototypeIsPrototypeOf( PerformanceEntryPrototype, this, ), keys: [ "name", "entryType", "startTime", "duration", ], })); } } webidl.configurePrototype(PerformanceEntry); const PerformanceEntryPrototype = PerformanceEntry.prototype;
const _detail = Symbol("[[detail]]"); class PerformanceMark extends PerformanceEntry { [_detail] = null;
get detail() { webidl.assertBranded(this, PerformanceMarkPrototype); return this[_detail]; }
get entryType() { webidl.assertBranded(this, PerformanceMarkPrototype); return "mark"; }
constructor( name, options = {}, ) { const prefix = "Failed to construct 'PerformanceMark'"; webidl.requiredArguments(arguments.length, 1, { prefix });
name = webidl.converters.DOMString(name, { prefix, context: "Argument 1", });
options = webidl.converters.PerformanceMarkOptions(options, { prefix, context: "Argument 2", });
const { detail = null, startTime = now() } = options;
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); }
toJSON() { webidl.assertBranded(this, PerformanceMarkPrototype); return { name: this.name, entryType: this.entryType, startTime: this.startTime, duration: this.duration, detail: this.detail, }; }
[customInspect](inspect) { return inspect(consoleInternal.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]; }
get entryType() { webidl.assertBranded(this, PerformanceMeasurePrototype); return "measure"; }
constructor( name = null, startTime = null, duration = null, detail = null, key = undefined, ) { if (key !== illegalConstructorKey) { webidl.illegalConstructor(); }
super(name, "measure", startTime, duration, key); this[webidl.brand] = webidl.brand; this[_detail] = structuredClone(detail); }
toJSON() { webidl.assertBranded(this, PerformanceMeasurePrototype); return { name: this.name, entryType: this.entryType, startTime: this.startTime, duration: this.duration, detail: this.detail, }; }
[customInspect](inspect) { return inspect(consoleInternal.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(); }
super(); this[webidl.brand] = webidl.brand; }
get timeOrigin() { webidl.assertBranded(this, PerformancePrototype); return timeOrigin; }
clearMarks(markName = undefined) { webidl.assertBranded(this, PerformancePrototype); if (markName !== undefined) { markName = webidl.converters.DOMString(markName, { prefix: "Failed to execute 'clearMarks' on 'Performance'", context: "Argument 1", });
performanceEntries = ArrayPrototypeFilter( performanceEntries, (entry) => !(entry.name === markName && entry.entryType === "mark"), ); } else { performanceEntries = ArrayPrototypeFilter( performanceEntries, (entry) => entry.entryType !== "mark", ); } }
clearMeasures(measureName = undefined) { webidl.assertBranded(this, PerformancePrototype); if (measureName !== undefined) { measureName = webidl.converters.DOMString(measureName, { prefix: "Failed to execute 'clearMeasures' on 'Performance'", context: "Argument 1", });
performanceEntries = ArrayPrototypeFilter( performanceEntries, (entry) => !(entry.name === measureName && entry.entryType === "measure"), ); } else { performanceEntries = ArrayPrototypeFilter( performanceEntries, (entry) => entry.entryType !== "measure", ); } }
getEntries() { webidl.assertBranded(this, PerformancePrototype); return filterByNameType(); }
getEntriesByName( name, type = undefined, ) { webidl.assertBranded(this, PerformancePrototype); const prefix = "Failed to execute 'getEntriesByName' on 'Performance'"; webidl.requiredArguments(arguments.length, 1, { prefix });
name = webidl.converters.DOMString(name, { prefix, context: "Argument 1", });
if (type !== undefined) { type = webidl.converters.DOMString(type, { prefix, context: "Argument 2", }); }
return filterByNameType(name, type); }
getEntriesByType(type) { webidl.assertBranded(this, PerformancePrototype); const prefix = "Failed to execute 'getEntriesByName' on 'Performance'"; webidl.requiredArguments(arguments.length, 1, { prefix });
type = webidl.converters.DOMString(type, { prefix, context: "Argument 1", });
return filterByNameType(undefined, type); }
mark( markName, markOptions = {}, ) { webidl.assertBranded(this, PerformancePrototype); const prefix = "Failed to execute 'mark' on 'Performance'"; webidl.requiredArguments(arguments.length, 1, { prefix });
markName = webidl.converters.DOMString(markName, { prefix, context: "Argument 1", });
markOptions = webidl.converters.PerformanceMarkOptions(markOptions, { prefix, context: "Argument 2", });
// 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; }
measure( measureName, startOrMeasureOptions = {}, endMark = undefined, ) { webidl.assertBranded(this, PerformancePrototype); const prefix = "Failed to execute 'measure' on 'Performance'"; webidl.requiredArguments(arguments.length, 1, { prefix });
measureName = webidl.converters.DOMString(measureName, { prefix, context: "Argument 1", });
startOrMeasureOptions = webidl.converters ["DOMString or PerformanceMeasureOptions"](startOrMeasureOptions, { prefix, context: "Argument 2", });
if (endMark !== undefined) { endMark = webidl.converters.DOMString(endMark, { prefix, context: "Argument 3", }); }
if ( startOrMeasureOptions && typeof startOrMeasureOptions === "object" && ObjectKeys(startOrMeasureOptions).length > 0 ) { if (endMark) { throw new TypeError("Options cannot be passed with endMark."); } if ( !ReflectHas(startOrMeasureOptions, "start") && !ReflectHas(startOrMeasureOptions, "end") ) { throw new TypeError( "A start or end mark must be supplied in options.", ); } if ( ReflectHas(startOrMeasureOptions, "start") && ReflectHas(startOrMeasureOptions, "duration") && ReflectHas(startOrMeasureOptions, "end") ) { throw new TypeError( "Cannot specify start, end, and duration together in options.", ); } } 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; }
now() { webidl.assertBranded(this, PerformancePrototype); return now(); }
toJSON() { webidl.assertBranded(this, PerformancePrototype); return { timeOrigin: this.timeOrigin, }; }
[customInspect](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, evaluate: ObjectPrototypeIsPrototypeOf(PerformancePrototype, this), keys: [], })); } } webidl.configurePrototype(Performance); const PerformancePrototype = Performance.prototype;
webidl.converters["Performance"] = webidl.createInterfaceConverter( "Performance", PerformancePrototype, );
window.__bootstrap.performance = { PerformanceEntry, PerformanceMark, PerformanceMeasure, Performance, performance: new Performance(illegalConstructorKey), setTimeOrigin, };})(this);
Version Info