1
0
Fork 0
firefox/dom/simpledb/test/modules/system/SimpleDBUtils.sys.mjs
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

49 lines
1.4 KiB
JavaScript

/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
import { RequestError } from "resource://testing-common/dom/quota/test/modules/RequestError.sys.mjs";
export const SimpleDBUtils = {
createConnection(principal) {
const connection = Cc["@mozilla.org/dom/sdb-connection;1"].createInstance(
Ci.nsISDBConnection
);
connection.init(principal);
return connection;
},
/**
* Handles the completion of a request, awaiting the callback to be called
* before proceeding.
*
* This function is designed to handle requests of the type `nsISDBRequest`
*
* These requests are typically returned by the connection.
*
* @param {Object} request
* The request object, which must have a callback property and
* result-related properties (e.g., resultCode, resultName).
* @returns {Promise}
* Resolves with the request's result when the operation is successful.
* @throws {RequestError}
* If the request's resultCode is not `Cr.NS_OK`, indicating an error in
* the request.
*/
async requestFinished(request) {
await new Promise(function (resolve) {
request.callback = function () {
resolve();
};
});
if (request.resultCode !== Cr.NS_OK) {
throw new RequestError(request.resultCode, request.resultName);
}
return request.result;
},
};