tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

IndexedDBUtils.sys.mjs (1182B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 export const IndexedDBUtils = {
      7  /**
      8   * Handles the completion of a request, awaiting either the `onsuccess` or
      9   * `onerror` event before proceeding.
     10   *
     11   * This function is designed to handle requests of the types:
     12   * - `IDBRequest`
     13   * - `IDBOpenDBRequest`
     14   *
     15   * These requests are typically returned by IndexedDB API.
     16   *
     17   * @param {IDBRequest|IDBOpenDBRequest} request
     18   *   The request object, which must have `onsuccess` and `onerror` event
     19   *   handlers, as well as result and error properties.
     20   * @returns {Promise}
     21   *   Resolves with the request's result when the operation is successful.
     22   * @throws {Error}
     23   *   If the request encounters an error, this function throws the request's
     24   *   `error` property.
     25   */
     26  async requestFinished(request) {
     27    await new Promise(function (resolve) {
     28      request.onerror = function () {
     29        resolve();
     30      };
     31      request.onsuccess = function () {
     32        resolve();
     33      };
     34    });
     35 
     36    if (request.error) {
     37      throw request.error;
     38    }
     39 
     40    return request.result;
     41  },
     42 };