Skip to content

Commit

Permalink
feat(web): add performance.timeOrigin (#14489)
Browse files Browse the repository at this point in the history
Add support for the `performance.timeOrigin` web API.

Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
  • Loading branch information
GJZwiers and JoviDeCroock committed May 6, 2022
1 parent 23c77df commit dd1d6a0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions cli/dts/lib.deno.shared_globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
7 changes: 7 additions & 0 deletions cli/tests/unit/performance_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions ext/web/15_performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
const illegalConstructorKey = Symbol("illegalConstructorKey");
const customInspect = SymbolFor("Deno.customInspect");
let performanceEntries = [];
let timeOrigin;

webidl.converters["PerformanceMarkOptions"] = webidl
.createDictionaryConverter(
Expand Down Expand Up @@ -77,6 +78,10 @@
return webidl.converters.DOMString(V, opts);
};

function setTimeOrigin(origin) {
timeOrigin = origin;
}

function findMostRecent(
name,
type,
Expand Down Expand Up @@ -327,6 +332,10 @@
webidl.illegalConstructor();
}

get timeOrigin() {
return timeOrigin;
}

clearMarks(markName = undefined) {
webidl.assertBranded(this, PerformancePrototype);
if (markName !== undefined) {
Expand Down Expand Up @@ -566,5 +575,6 @@
PerformanceMeasure,
Performance,
performance: webidl.createBranded(Performance),
setTimeOrigin,
};
})(this);
3 changes: 3 additions & 0 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ delete Object.prototype.__proto__;
const core = Deno.core;
const {
ArrayPrototypeMap,
DateNow,
Error,
FunctionPrototypeCall,
FunctionPrototypeBind,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions tools/wpt/expectation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1179,20 +1179,18 @@
"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"
],
"idlharness.any.worker.html": [
"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": {
Expand Down

0 comments on commit dd1d6a0

Please sign in to comment.