File size: 926 Bytes
76cc654 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/**
* @overview
* Utility for creating a proxy object that warns extension authors to not use the runtime.extensionStorage
* or target.extensionStorage APIs, as they're both deprecated.
*/
/**
* A set of extensions that have been warned. A set is used for performance reasons.
*/
const WARNED_EXTENSIONS = new Set();
/**
* Creates the actual proxy object.
* @param {object.<string, any>} [default_content] Used by the deserializer to set the values of extensionStorage.
*/
const ExtensionStorage = (default_content = {}) => {
return new Proxy(
default_content,
{
set: function (target, key, value) {
if (!WARNED_EXTENSIONS.has(key)) {
console.warn("extensionStorage APIs are deprecated. Please avoid using them in your extensions.");
WARNED_EXTENSIONS.add(key);
}
return target[key] = value;
},
}
);
};
module.exports = ExtensionStorage;
|