0
0
Fork 0
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:
Geert-Jan Zwiers 2022-05-13 18:36:00 +02:00 committed by GitHub
parent 939a070c8c
commit 0568be863b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 3 deletions

View file

@ -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;

View file

@ -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);

View file

@ -556,7 +556,9 @@
toJSON() { toJSON() {
webidl.assertBranded(this, PerformancePrototype); webidl.assertBranded(this, PerformancePrototype);
return {}; return {
timeOrigin: this.timeOrigin,
};
} }
[customInspect](inspect) { [customInspect](inspect) {

View file

@ -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"
], ],