Bug 1467720 - Fix "dead object" error raised from ext-storage.js on browser.storage.local API calls. r=aswan

When ExtensionStorageIDB.selectBackend is called from a child process, it calls the main process
and cache the result as a promise, to be reused for the other contexts for the same extension
that are running in the same process.

The cached promise should not be tied to a particular extension context's cloneScope, otherwise
accessing it will raise "can't access dead object" errors after that cloneScope has been
destroyed.

MozReview-Commit-ID: GJuul8sQmlF

--HG--
extra : rebase_source : 63da9edaa2669a8a6c9f47f4d4110c0dae20232e
This commit is contained in:
Luca Greco 2018-06-08 05:19:34 +02:00
Родитель 42d6b2934a
Коммит 1b638f8061
1 изменённых файлов: 12 добавлений и 6 удалений

Просмотреть файл

@ -364,11 +364,17 @@ this.ExtensionStorageIDB = {
let promise;
if (context.childManager) {
// Ask the parent process if the new backend is enabled for the
// running extension.
promise = context.childManager.callParentAsyncFunction(
"storage.local.IDBBackend.selectBackend", []
).then(result => {
// Create a promise object that is not tied to the current extension context, because
// we are caching it for the entire life of the extension in the current process (and
// the promise returned by context.childManager.callParentAsyncFunction would become
// a dead object when the context.cloneScope has been destroyed).
promise = (async () => {
// Ask the parent process if the new backend is enabled for the
// running extension.
let result = await context.childManager.callParentAsyncFunction(
"storage.local.IDBBackend.selectBackend", []
);
if (!result.backendEnabled) {
return {backendEnabled: false};
}
@ -379,7 +385,7 @@ this.ExtensionStorageIDB = {
// from the StructuredCloneHolder used to send it across the processes.
storagePrincipal: result.storagePrincipal.deserialize(this),
};
});
})();
} else {
// If migrating to the IDB backend is not enabled by the preference, then we
// don't need to migrate any data and the new backend is not enabled.