util.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.installTimerFunctions = exports.pick = void 0;
  7. const globalThis_js_1 = __importDefault(require("./globalThis.js"));
  8. function pick(obj, ...attr) {
  9. return attr.reduce((acc, k) => {
  10. if (obj.hasOwnProperty(k)) {
  11. acc[k] = obj[k];
  12. }
  13. return acc;
  14. }, {});
  15. }
  16. exports.pick = pick;
  17. // Keep a reference to the real timeout functions so they can be used when overridden
  18. const NATIVE_SET_TIMEOUT = setTimeout;
  19. const NATIVE_CLEAR_TIMEOUT = clearTimeout;
  20. function installTimerFunctions(obj, opts) {
  21. if (opts.useNativeTimers) {
  22. obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThis_js_1.default);
  23. obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThis_js_1.default);
  24. }
  25. else {
  26. obj.setTimeoutFn = setTimeout.bind(globalThis_js_1.default);
  27. obj.clearTimeoutFn = clearTimeout.bind(globalThis_js_1.default);
  28. }
  29. }
  30. exports.installTimerFunctions = installTimerFunctions;