mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -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 type PerformanceEntryList = PerformanceEntry[];
|
||||||
|
|
||||||
declare class Performance {
|
declare class Performance {
|
||||||
|
/** Returns a timestamp representing the start of the performance measurement. */
|
||||||
readonly timeOrigin: number;
|
readonly timeOrigin: number;
|
||||||
constructor();
|
constructor();
|
||||||
|
|
||||||
|
@ -490,6 +491,9 @@ declare class Performance {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
now(): number;
|
now(): number;
|
||||||
|
|
||||||
|
/** Returns a JSON representation of the performance object. */
|
||||||
|
toJSON(): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare var performance: Performance;
|
declare var performance: Performance;
|
||||||
|
|
|
@ -27,6 +27,15 @@ Deno.test(function timeOrigin() {
|
||||||
assert(Date.now() >= origin);
|
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() {
|
Deno.test(function performanceMark() {
|
||||||
const mark = performance.mark("test");
|
const mark = performance.mark("test");
|
||||||
assert(mark instanceof PerformanceMark);
|
assert(mark instanceof PerformanceMark);
|
||||||
|
|
|
@ -556,7 +556,9 @@
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
webidl.assertBranded(this, PerformancePrototype);
|
webidl.assertBranded(this, PerformancePrototype);
|
||||||
return {};
|
return {
|
||||||
|
timeOrigin: this.timeOrigin,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[customInspect](inspect) {
|
[customInspect](inspect) {
|
||||||
|
|
|
@ -1182,13 +1182,11 @@
|
||||||
"idlharness.any.html": [
|
"idlharness.any.html": [
|
||||||
"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: default toJSON operation on performance",
|
|
||||||
"Window interface: attribute performance"
|
"Window interface: attribute performance"
|
||||||
],
|
],
|
||||||
"idlharness.any.worker.html": [
|
"idlharness.any.worker.html": [
|
||||||
"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: 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"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Add table
Reference in a new issue