Isolate values returned across window contexts

This commit is contained in:
toasted-nutbread 2019-12-13 23:33:11 -05:00
parent ddaf44ba7b
commit 0bbba8fcc7

View File

@ -35,6 +35,7 @@ function utilIsolate(value) {
function utilFunctionIsolate(func) { function utilFunctionIsolate(func) {
return function (...args) { return function (...args) {
try { try {
args = args.map((v) => utilIsolate(v));
return func.call(this, ...args); return func.call(this, ...args);
} catch (e) { } catch (e) {
try { try {
@ -99,49 +100,49 @@ function utilBackend() {
return chrome.extension.getBackgroundPage().yomichan_backend; return chrome.extension.getBackgroundPage().yomichan_backend;
} }
function utilAnkiGetModelNames() { async function utilAnkiGetModelNames() {
return utilBackend().anki.getModelNames(); return utilIsolate(await utilBackend().anki.getModelNames());
} }
function utilAnkiGetDeckNames() { async function utilAnkiGetDeckNames() {
return utilBackend().anki.getDeckNames(); return utilIsolate(await utilBackend().anki.getDeckNames());
} }
function utilDatabaseGetDictionaryInfo() { async function utilDatabaseGetDictionaryInfo() {
return utilBackend().translator.database.getDictionaryInfo(); return utilIsolate(await utilBackend().translator.database.getDictionaryInfo());
} }
function utilDatabaseGetDictionaryCounts(dictionaryNames, getTotal) { async function utilDatabaseGetDictionaryCounts(dictionaryNames, getTotal) {
return utilBackend().translator.database.getDictionaryCounts( return utilIsolate(await utilBackend().translator.database.getDictionaryCounts(
utilBackgroundIsolate(dictionaryNames), utilBackgroundIsolate(dictionaryNames),
utilBackgroundIsolate(getTotal) utilBackgroundIsolate(getTotal)
); ));
} }
function utilAnkiGetModelFieldNames(modelName) { async function utilAnkiGetModelFieldNames(modelName) {
return utilBackend().anki.getModelFieldNames( return utilIsolate(await utilBackend().anki.getModelFieldNames(
utilBackgroundIsolate(modelName) utilBackgroundIsolate(modelName)
); ));
} }
function utilDatabasePurge() { async function utilDatabasePurge() {
return utilBackend().translator.purgeDatabase(); return utilIsolate(await utilBackend().translator.purgeDatabase());
} }
function utilDatabaseDeleteDictionary(dictionaryName, onProgress) { async function utilDatabaseDeleteDictionary(dictionaryName, onProgress) {
return utilBackend().translator.database.deleteDictionary( return utilIsolate(await utilBackend().translator.database.deleteDictionary(
utilBackgroundIsolate(dictionaryName), utilBackgroundIsolate(dictionaryName),
utilBackgroundFunctionIsolate(onProgress) utilBackgroundFunctionIsolate(onProgress)
); ));
} }
async function utilDatabaseImport(data, onProgress, details) { async function utilDatabaseImport(data, onProgress, details) {
data = await utilReadFile(data); data = await utilReadFile(data);
return utilBackend().translator.database.importDictionary( return utilIsolate(await utilBackend().translator.database.importDictionary(
utilBackgroundIsolate(data), utilBackgroundIsolate(data),
utilBackgroundFunctionIsolate(onProgress), utilBackgroundFunctionIsolate(onProgress),
utilBackgroundIsolate(details) utilBackgroundIsolate(details)
); ));
} }
function utilReadFile(file) { function utilReadFile(file) {