diff options
| author | Geert-Jan Zwiers <geertjanzwiers@protonmail.com> | 2022-05-06 19:37:18 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-06 19:37:18 +0200 |
| commit | dd1d6a0f67cb386941ddc08aa453612f8398144f (patch) | |
| tree | 450ebcac29f6c812245939449a08d83e4e5e3e61 | |
| parent | 23c77df6643f5b5a8846f67a738fe2e9c1e3c716 (diff) | |
feat(web): add `performance.timeOrigin` (#14489)
Add support for the `performance.timeOrigin` web API.
Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
| -rw-r--r-- | cli/dts/lib.deno.shared_globals.d.ts | 1 | ||||
| -rw-r--r-- | cli/tests/unit/performance_test.ts | 7 | ||||
| -rw-r--r-- | ext/web/15_performance.js | 10 | ||||
| -rw-r--r-- | runtime/js/99_main.js | 3 | ||||
| -rw-r--r-- | tools/wpt/expectation.json | 4 |
5 files changed, 22 insertions, 3 deletions
diff --git a/cli/dts/lib.deno.shared_globals.d.ts b/cli/dts/lib.deno.shared_globals.d.ts index 5f44e2d1b..b96c56dba 100644 --- a/cli/dts/lib.deno.shared_globals.d.ts +++ b/cli/dts/lib.deno.shared_globals.d.ts @@ -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. */ diff --git a/cli/tests/unit/performance_test.ts b/cli/tests/unit/performance_test.ts index 4c7d08d4e..252a31fc4 100644 --- a/cli/tests/unit/performance_test.ts +++ b/cli/tests/unit/performance_test.ts @@ -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); diff --git a/ext/web/15_performance.js b/ext/web/15_performance.js index 41b40159e..07fa2a01d 100644 --- a/ext/web/15_performance.js +++ b/ext/web/15_performance.js @@ -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); diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 07a350424..d83a2e6c8 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -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; diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json index 67e256353..1c402903e 100644 --- a/tools/wpt/expectation.json +++ b/tools/wpt/expectation.json @@ -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": { |
