w3c-hr-time
Advanced tools
Comparing version 1.0.0 to 1.0.1
# Change log | ||
## 1.0.1 (2018-01-03) | ||
* Make `performance.toJSON()` return an object with `timeOrigin` property, per [clarifications from specification authors][heycam/webidl#505]. | ||
## 1.0.0 (2018-01-02) | ||
* Initial release. | ||
[heycam/webidl#505]: https://github.com/heycam/webidl/pull/505 |
@@ -46,7 +46,6 @@ "use strict"; | ||
// Doesn't return anything useful because we don't implement timing APIs. timeOrigin is not part of the JSON returned | ||
// since it is a DOMHighResTimeStamp, which is not included in "numeric types" or "JSON types" as it is only a typedef | ||
// for a numeric type. | ||
toJSON() { | ||
return {}; | ||
return { | ||
timeOrigin: this.timeOrigin | ||
}; | ||
} | ||
@@ -53,0 +52,0 @@ } |
{ | ||
"name": "w3c-hr-time", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "An implementation of the W3C High Resolution Time Level 2 specification.", | ||
@@ -19,3 +19,4 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "jest" | ||
"test": "jest", | ||
"lint": "eslint ." | ||
}, | ||
@@ -22,0 +23,0 @@ "files": [ |
@@ -15,4 +15,2 @@ # w3c-hr-time | ||
Probably the most interesting export is the [`Performance`][] class. | ||
```js | ||
@@ -35,11 +33,11 @@ const { Performance } = require("w3c-hr-time"); | ||
By constructing the class, you can get an instance quite similar to the `window.performance` object in browsers. Specifically, the following APIs are implemented: | ||
Perhaps the most interesting export is the [`Performance`][] class. By constructing the class, you can get an instance quite similar to the `window.performance` object in browsers. Specifically, the following APIs are implemented: | ||
* [`performance.now(): number`][`Performance#now()`] returns the high-resolution duration since the construction of the `Performance` object. | ||
* [`performance.timeOrigin: number`][`Performance#timeOrigin`] is a high-resolution timestamp of the `Performance` object's construction, expressed in [Unix time][]. | ||
* [`performance.toJSON(): object`][`Performance#toJSON()`] always returns an empty object. In browsers, the returned object may contain additional properties such as `navigation` and `timing`. However, those properties are specific to browser navigation and are unsuitable for a Node.js implementation like this module. Furthermore, they are specified not in the High Resolution Time spec but in [Navigation Timing][NAVIGATION-TIMING], and are thereby outside the scope of this module. For compatibility, the method always returns the empty object. | ||
* [`performance.toJSON(): object`][`Performance#toJSON()`] returns an object with `timeOrigin` property set to the corresponding value of this object. This allows serializing the `Performance` object with `JSON.stringify()`. In browsers, the returned object may contain additional properties such as `navigation` and `timing`. However, those properties are specific to browser navigation and are unsuitable for a Node.js implementation. Furthermore, they are specified not in the High Resolution Time spec but in [Navigation Timing][NAVIGATION-TIMING], and are thereby outside the scope of this module. | ||
### Limitations | ||
This module does not aim for full [Web IDL][WEBIDL] conformance, so things like `performance.toJSON.call(undefined)` will not throw `TypeError`s like it does in browsers. If you need full Web IDL conformance, you may be interested in the [webidl2js][] module. | ||
This module does not aim for full [Web IDL][WEBIDL] conformance, so things like `performance.toJSON.call({})` will not throw `TypeError`s like it does in browsers. If you need full Web IDL conformance, you may be interested in the [webidl2js][] module. | ||
@@ -74,3 +72,3 @@ The `Performance` class provided also does not have `mark()`, `measure()`, `getEntries()`, and such functions. They are specified in other specs than High Resolution Timing, such as [User Timing][USER-TIMING] (marks and measures) and [Performance Timeline][PERFORMANCE-TIMELINE] (entries management). Those specs extend the definition of the `Performance` class defined in High Resolution Timing, and to implement those specs you can extend the `Performance` class exported by this module. | ||
The High Resolution Time spec [specifies][`DOMHighResTimeStamp`] that | ||
The High Resolution Time spec [states][HR-TIME §4] that | ||
@@ -102,3 +100,3 @@ > A [`DOMHighResTimeStamp`][] *SHOULD* represent a time in milliseconds accurate to 5 microseconds - see [8. Privacy and Security][HR-TIME §8]. | ||
For example, if `performance.now()` returns 1000, it is guaranteed that the time of this call is exactly one second since the construction of the `Performance` object. But the difference in `Date.now()`'s value from the construction of the `Performance` object to when `performance.now()` returns 1000 may not be exactly 1000. You may also see `performance.now() - Date.now()` diverge over time as a result of clock drifts. | ||
For example, if `performance.now()` returns 1000, it is guaranteed that the time of this call is exactly one second since the construction of the `Performance` object. But the difference in `Date.now()`'s value from the construction of the `Performance` object to when `performance.now()` returns 1000 may not be exactly 1000. You may also see `performance.now() - Date.now()` diverge over time as a result of clock drifts. | ||
@@ -113,2 +111,3 @@ On the other hand, `performance.timeOrigin` returns the *[Unix time][]* at which the `Performance` object is constructed and relies on the current time exposed through `Date.now()`. That means that it is susceptible to clock drifts that has occurred before the `Performance` object was constructed. | ||
[HR-TIME §4]: https://w3c.github.io/hr-time/#dom-domhighrestimestamp | ||
[HR-TIME §8]: https://w3c.github.io/hr-time/#privacy-security | ||
@@ -115,0 +114,0 @@ |
14570
146
120