mirror of
https://github.com/denoland/deno.git
synced 2025-01-11 08:33:43 -05:00
feat(ext/web): add performance.toJSON (#14548)
This commit is contained in:
parent
939a070c8c
commit
0568be863b
4 changed files with 16 additions and 3 deletions
4
cli/dts/lib.deno.shared_globals.d.ts
vendored
4
cli/dts/lib.deno.shared_globals.d.ts
vendored
|
@ -450,6 +450,7 @@ declare class Worker extends EventTarget {
|
|||
declare type PerformanceEntryList = PerformanceEntry[];
|
||||
|
||||
declare class Performance {
|
||||
/** Returns a timestamp representing the start of the performance measurement. */
|
||||
readonly timeOrigin: number;
|
||||
constructor();
|
||||
|
||||
|
@ -490,6 +491,9 @@ declare class Performance {
|
|||
* ```
|
||||
*/
|
||||
now(): number;
|
||||
|
||||
/** Returns a JSON representation of the performance object. */
|
||||
toJSON(): any;
|
||||
}
|
||||
|
||||
declare var performance: Performance;
|
||||
|
|
|
@ -27,6 +27,15 @@ Deno.test(function timeOrigin() {
|
|||
assert(Date.now() >= origin);
|
||||
});
|
||||
|
||||
Deno.test(function performanceToJSON() {
|
||||
const json = performance.toJSON();
|
||||
|
||||
assert("timeOrigin" in json);
|
||||
assert(json.timeOrigin === performance.timeOrigin);
|
||||
// check there are no other keys
|
||||
assertEquals(Object.keys(json).length, 1);
|
||||
});
|
||||
|
||||
Deno.test(function performanceMark() {
|
||||
const mark = performance.mark("test");
|
||||
assert(mark instanceof PerformanceMark);
|
||||
|
|
|
@ -556,7 +556,9 @@
|
|||
|
||||
toJSON() {
|
||||
webidl.assertBranded(this, PerformancePrototype);
|
||||
return {};
|
||||
return {
|
||||
timeOrigin: this.timeOrigin,
|
||||
};
|
||||
}
|
||||
|
||||
[customInspect](inspect) {
|
||||
|
|
|
@ -1182,13 +1182,11 @@
|
|||
"idlharness.any.html": [
|
||||
"Performance interface: existence and properties of interface object",
|
||||
"Performance interface: existence and properties of interface prototype object",
|
||||
"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: default toJSON operation on performance",
|
||||
"WorkerGlobalScope interface: attribute performance",
|
||||
"WorkerGlobalScope interface: self must inherit property \"performance\" with the proper type"
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue