commit 83c1e67c3530aada4f2bf4dfb1be41bdacd92773
parent 4e607d86ef0c1467cc3e806227e3be09b1f7fcc6
Author: Lorenz A <me@lorenzackermann.xyz>
Date: Wed, 17 Dec 2025 16:33:54 +0000
Bug 2004246 - [devtools] Turn devtools/server/actors/resources/storage/indexed-db.js into an ES class. r=devtools-reviewers,nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D276549
Diffstat:
1 file changed, 73 insertions(+), 70 deletions(-)
diff --git a/devtools/server/actors/resources/storage/indexed-db.js b/devtools/server/actors/resources/storage/indexed-db.js
@@ -75,17 +75,18 @@ const ILLEGAL_CHAR_REGEX = new RegExp(illegalFileNameCharacters, "g");
/**
* Meta data object for a particular index in an object store
- *
- * @param {IDBIndex} index
- * The particular index from the object store.
*/
-function IndexMetadata(index) {
- this._name = index.name;
- this._keyPath = index.keyPath;
- this._unique = index.unique;
- this._multiEntry = index.multiEntry;
-}
-IndexMetadata.prototype = {
+class IndexMetadata {
+ /**
+ * @param {IDBIndex} index
+ * The particular index from the object store.
+ */
+ constructor(index) {
+ this._name = index.name;
+ this._keyPath = index.keyPath;
+ this._unique = index.unique;
+ this._multiEntry = index.multiEntry;
+ }
toObject() {
return {
name: this._name,
@@ -93,40 +94,41 @@ IndexMetadata.prototype = {
unique: this._unique,
multiEntry: this._multiEntry,
};
- },
-};
+ }
+}
/**
* Meta data object for a particular object store in a db
- *
- * @param {IDBObjectStore} objectStore
- * The particular object store from the db.
*/
-function ObjectStoreMetadata(objectStore) {
- this._name = objectStore.name;
- this._keyPath = objectStore.keyPath;
- this._autoIncrement = objectStore.autoIncrement;
- this._indexes = [];
-
- for (let i = 0; i < objectStore.indexNames.length; i++) {
- const index = objectStore.index(objectStore.indexNames[i]);
-
- const newIndex = {
- keypath: index.keyPath,
- multiEntry: index.multiEntry,
- name: index.name,
- objectStore: {
- autoIncrement: index.objectStore.autoIncrement,
- indexNames: [...index.objectStore.indexNames],
- keyPath: index.objectStore.keyPath,
- name: index.objectStore.name,
- },
- };
+class ObjectStoreMetadata {
+ /**
+ * @param {IDBObjectStore} objectStore
+ * The particular object store from the db.
+ */
+ constructor(objectStore) {
+ this._name = objectStore.name;
+ this._keyPath = objectStore.keyPath;
+ this._autoIncrement = objectStore.autoIncrement;
+ this._indexes = [];
+
+ for (let i = 0; i < objectStore.indexNames.length; i++) {
+ const index = objectStore.index(objectStore.indexNames[i]);
+
+ const newIndex = {
+ keypath: index.keyPath,
+ multiEntry: index.multiEntry,
+ name: index.name,
+ objectStore: {
+ autoIncrement: index.objectStore.autoIncrement,
+ indexNames: [...index.objectStore.indexNames],
+ keyPath: index.objectStore.keyPath,
+ name: index.objectStore.name,
+ },
+ };
- this._indexes.push([newIndex, new IndexMetadata(index)]);
+ this._indexes.push([newIndex, new IndexMetadata(index)]);
+ }
}
-}
-ObjectStoreMetadata.prototype = {
toObject() {
return {
name: this._name,
@@ -136,44 +138,45 @@ ObjectStoreMetadata.prototype = {
[...this._indexes.values()].map(index => index.toObject())
),
};
- },
-};
+ }
+}
/**
* Meta data object for a particular indexed db in a host.
- *
- * @param {string} origin
- * The host associated with this indexed db.
- * @param {IDBDatabase} db
- * The particular indexed db.
- * @param {string} storage
- * Storage type, either "temporary", "default" or "persistent".
*/
-function DatabaseMetadata(origin, db, storage) {
- this._origin = origin;
- this._name = db.name;
- this._version = db.version;
- this._objectStores = [];
- this.storage = storage;
-
- if (db.objectStoreNames.length) {
- const transaction = db.transaction(db.objectStoreNames, "readonly");
-
- for (let i = 0; i < transaction.objectStoreNames.length; i++) {
- const objectStore = transaction.objectStore(
- transaction.objectStoreNames[i]
- );
- this._objectStores.push([
- transaction.objectStoreNames[i],
- new ObjectStoreMetadata(objectStore),
- ]);
+class DatabaseMetadata {
+ /**
+ * @param {string} origin
+ * The host associated with this indexed db.
+ * @param {IDBDatabase} db
+ * The particular indexed db.
+ * @param {string} storage
+ * Storage type, either "temporary", "default" or "persistent".
+ */
+ constructor(origin, db, storage) {
+ this._origin = origin;
+ this._name = db.name;
+ this._version = db.version;
+ this._objectStores = [];
+ this.storage = storage;
+
+ if (db.objectStoreNames.length) {
+ const transaction = db.transaction(db.objectStoreNames, "readonly");
+
+ for (let i = 0; i < transaction.objectStoreNames.length; i++) {
+ const objectStore = transaction.objectStore(
+ transaction.objectStoreNames[i]
+ );
+ this._objectStores.push([
+ transaction.objectStoreNames[i],
+ new ObjectStoreMetadata(objectStore),
+ ]);
+ }
}
}
-}
-DatabaseMetadata.prototype = {
get objectStores() {
return this._objectStores;
- },
+ }
toObject() {
return {
@@ -184,8 +187,8 @@ DatabaseMetadata.prototype = {
version: this._version,
objectStores: this._objectStores.size,
};
- },
-};
+ }
+}
class IndexedDBStorageActor extends BaseStorageActor {
constructor(storageActor) {