Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): add performance.timeOrigin #14489

Merged
merged 17 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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