UNPKG

@wapython/wasi

Version:

Javascript library for interacting with WASI Modules in Node.js and the Browser.

51 lines (50 loc) 1.75 kB
"use strict"; /* This is https://github.com/cabinjs/browser-hrtime/blob/master/src/index.ts but modified to not use window, since I want to use this in a WebWorker. Upstream is MIT license. This also doesn't define any global variables. */ Object.defineProperty(exports, "__esModule", { value: true }); var _perfomancePolyfill = function () { // based on https://gist.github.com/paulirish/5438650 copyright Paul Irish 2015. if (!("performance" in self)) { self.performance = {}; } Date.now = Date.now || (function () { // thanks IE8 return new Date().getTime(); }); if ("now" in self.performance === false) { var nowOffset_1 = Date.now(); if (performance.timing && performance.timing.navigationStart) { nowOffset_1 = performance.timing.navigationStart; } self.performance.now = function () { return Date.now() - nowOffset_1; }; } }; var _hrtime = function (previousTimestamp) { _perfomancePolyfill(); var baseNow = Math.floor((Date.now() - performance.now()) * 1e-3); var clocktime = performance.now() * 1e-3; var seconds = Math.floor(clocktime) + baseNow; var nanoseconds = Math.floor((clocktime % 1) * 1e9); if (previousTimestamp) { seconds = seconds - previousTimestamp[0]; nanoseconds = nanoseconds - previousTimestamp[1]; if (nanoseconds < 0) { seconds--; nanoseconds += 1e9; } } return [seconds, nanoseconds]; }; var NS_PER_SEC = 1e9; _hrtime.bigint = function (time) { var diff = _hrtime(time); return (diff[0] * NS_PER_SEC + diff[1]); }; exports.default = _hrtime; //# sourceMappingURL=browser-hrtime.js.map