1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 00:29:09 -05:00

feat(web): add performance.timeOrigin (#14489)

Add support for the `performance.timeOrigin` web API.

Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
This commit is contained in:
Geert-Jan Zwiers 2022-05-06 19:37:18 +02:00 committed by GitHub
parent 23c77df664
commit dd1d6a0f67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 3 deletions

View file

@ -450,6 +450,7 @@ declare class Worker extends EventTarget {
declare type PerformanceEntryList = PerformanceEntry[];
declare class Performance {
readonly timeOrigin: number;
constructor();
/** Removes the stored timestamp with the associated name. */

View file

@ -20,6 +20,13 @@ Deno.test({ permissions: { hrtime: false } }, async function performanceNow() {
assert(totalTime >= 10);
});
Deno.test(function timeOrigin() {
const origin = performance.timeOrigin;
assert(origin > 0);
assert(Date.now() >= origin);
});
Deno.test(function performanceMark() {
const mark = performance.mark("test");
assert(mark instanceof PerformanceMark);

View file

@ -24,6 +24,7 @@
const illegalConstructorKey = Symbol("illegalConstructorKey");
const customInspect = SymbolFor("Deno.customInspect");
let performanceEntries = [];
let timeOrigin;
webidl.converters["PerformanceMarkOptions"] = webidl
.createDictionaryConverter(
@ -77,6 +78,10 @@
return webidl.converters.DOMString(V, opts);
};
function setTimeOrigin(origin) {
timeOrigin = origin;
}
function findMostRecent(
name,
type,
@ -327,6 +332,10 @@
webidl.illegalConstructor();
}
get timeOrigin() {
return timeOrigin;
}
clearMarks(markName = undefined) {
webidl.assertBranded(this, PerformancePrototype);
if (markName !== undefined) {
@ -566,5 +575,6 @@
PerformanceMeasure,
Performance,
performance: webidl.createBranded(Performance),
setTimeOrigin,
};
})(this);

View file

@ -9,6 +9,7 @@ delete Object.prototype.__proto__;
const core = Deno.core;
const {
ArrayPrototypeMap,
DateNow,
Error,
FunctionPrototypeCall,
FunctionPrototypeBind,
@ -530,6 +531,7 @@ delete Object.prototype.__proto__;
throw new Error("Worker runtime already bootstrapped");
}
performance.setTimeOrigin(DateNow());
const consoleFromV8 = window.console;
const wrapConsole = window.__bootstrap.console.wrapConsole;
@ -622,6 +624,7 @@ delete Object.prototype.__proto__;
throw new Error("Worker runtime already bootstrapped");
}
performance.setTimeOrigin(DateNow());
const consoleFromV8 = window.console;
const wrapConsole = window.__bootstrap.console.wrapConsole;

View file

@ -1179,7 +1179,6 @@
"Performance interface: existence and properties of interface object",
"Performance interface: existence and properties of interface prototype object",
"Performance interface: attribute timeOrigin",
"Performance interface: performance must inherit property \"timeOrigin\" with the proper type",
"Performance interface: default toJSON operation on performance",
"Window interface: attribute performance"
],
@ -1187,12 +1186,11 @@
"Performance interface: existence and properties of interface object",
"Performance interface: existence and properties of interface prototype object",
"Performance interface: attribute timeOrigin",
"Performance interface: performance must inherit property \"timeOrigin\" with the proper type",
"Performance interface: default toJSON operation on performance",
"WorkerGlobalScope interface: attribute performance",
"WorkerGlobalScope interface: self must inherit property \"performance\" with the proper type"
],
"window-worker-timeOrigin.window.html": false,
"window-worker-timeOrigin.window.html": true,
"idlharness-shadowrealm.window.html": false
},
"streams": {