1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 16:49:18 -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 type PerformanceEntryList = PerformanceEntry[];
declare class Performance { declare class Performance {
readonly timeOrigin: number;
constructor(); constructor();
/** Removes the stored timestamp with the associated name. */ /** 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); assert(totalTime >= 10);
}); });
Deno.test(function timeOrigin() {
const origin = performance.timeOrigin;
assert(origin > 0);
assert(Date.now() >= origin);
});
Deno.test(function performanceMark() { Deno.test(function performanceMark() {
const mark = performance.mark("test"); const mark = performance.mark("test");
assert(mark instanceof PerformanceMark); assert(mark instanceof PerformanceMark);

View file

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

View file

@ -9,6 +9,7 @@ delete Object.prototype.__proto__;
const core = Deno.core; const core = Deno.core;
const { const {
ArrayPrototypeMap, ArrayPrototypeMap,
DateNow,
Error, Error,
FunctionPrototypeCall, FunctionPrototypeCall,
FunctionPrototypeBind, FunctionPrototypeBind,
@ -530,6 +531,7 @@ delete Object.prototype.__proto__;
throw new Error("Worker runtime already bootstrapped"); throw new Error("Worker runtime already bootstrapped");
} }
performance.setTimeOrigin(DateNow());
const consoleFromV8 = window.console; const consoleFromV8 = window.console;
const wrapConsole = window.__bootstrap.console.wrapConsole; const wrapConsole = window.__bootstrap.console.wrapConsole;
@ -622,6 +624,7 @@ delete Object.prototype.__proto__;
throw new Error("Worker runtime already bootstrapped"); throw new Error("Worker runtime already bootstrapped");
} }
performance.setTimeOrigin(DateNow());
const consoleFromV8 = window.console; const consoleFromV8 = window.console;
const wrapConsole = window.__bootstrap.console.wrapConsole; 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 object",
"Performance interface: existence and properties of interface prototype object", "Performance interface: existence and properties of interface prototype object",
"Performance interface: attribute timeOrigin", "Performance interface: attribute timeOrigin",
"Performance interface: performance must inherit property \"timeOrigin\" with the proper type",
"Performance interface: default toJSON operation on performance", "Performance interface: default toJSON operation on performance",
"Window interface: attribute performance" "Window interface: attribute performance"
], ],
@ -1187,12 +1186,11 @@
"Performance interface: existence and properties of interface object", "Performance interface: existence and properties of interface object",
"Performance interface: existence and properties of interface prototype object", "Performance interface: existence and properties of interface prototype object",
"Performance interface: attribute timeOrigin", "Performance interface: attribute timeOrigin",
"Performance interface: performance must inherit property \"timeOrigin\" with the proper type",
"Performance interface: default toJSON operation on performance", "Performance interface: default toJSON operation on performance",
"WorkerGlobalScope interface: attribute performance", "WorkerGlobalScope interface: attribute performance",
"WorkerGlobalScope interface: self must inherit property \"performance\" with the proper type" "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 "idlharness-shadowrealm.window.html": false
}, },
"streams": { "streams": {