aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-14 16:21:41 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-14 16:21:41 -0400
commit6358b655aef94279133550c93a944dbe785cee44 (patch)
tree89007c97348c34416fef0da5e253ffc3663068ed
parentec816e676771b53f6eb2c9c68e1742830c9fd194 (diff)
Isolate options objects created via settings.js
Prevents dead objects created by different windows.
-rw-r--r--ext/bg/js/settings.js20
-rw-r--r--ext/bg/js/util.js5
2 files changed, 17 insertions, 8 deletions
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js
index 7f3e5c69..3d581ba5 100644
--- a/ext/bg/js/settings.js
+++ b/ext/bg/js/settings.js
@@ -60,7 +60,7 @@ async function formRead(options) {
const optionsAnkiEnableOld = options.anki.enable;
options.anki.enable = $('#anki-enable').prop('checked');
- options.anki.tags = $('#card-tags').val().split(/[,; ]+/);
+ options.anki.tags = utilBackgroundIsolate($('#card-tags').val().split(/[,; ]+/));
options.anki.sentenceExt = parseInt($('#sentence-detection-extent').val(), 10);
options.anki.server = $('#interface-server').val();
options.anki.screenshot.format = $('#screenshot-format').val();
@@ -70,20 +70,20 @@ async function formRead(options) {
if (optionsAnkiEnableOld && !ankiErrorShown()) {
options.anki.terms.deck = $('#anki-terms-deck').val();
options.anki.terms.model = $('#anki-terms-model').val();
- options.anki.terms.fields = ankiFieldsToDict($('#terms .anki-field-value'));
+ options.anki.terms.fields = utilBackgroundIsolate(ankiFieldsToDict($('#terms .anki-field-value')));
options.anki.kanji.deck = $('#anki-kanji-deck').val();
options.anki.kanji.model = $('#anki-kanji-model').val();
- options.anki.kanji.fields = ankiFieldsToDict($('#kanji .anki-field-value'));
+ options.anki.kanji.fields = utilBackgroundIsolate(ankiFieldsToDict($('#kanji .anki-field-value')));
}
options.general.mainDictionary = $('#dict-main').val();
$('.dict-group').each((index, element) => {
const dictionary = $(element);
- options.dictionaries[dictionary.data('title')] = {
+ options.dictionaries[dictionary.data('title')] = utilBackgroundIsolate({
priority: parseInt(dictionary.find('.dict-priority').val(), 10),
enabled: dictionary.find('.dict-enabled').prop('checked'),
allowSecondarySearches: dictionary.find('.dict-allow-secondary-searches').prop('checked')
- };
+ });
});
}
@@ -426,7 +426,7 @@ async function onDictionaryPurge(e) {
await utilDatabasePurge();
const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
- options.dictionaries = {};
+ options.dictionaries = utilBackgroundIsolate({});
options.general.mainDictionary = '';
await settingsSaveOptions();
@@ -468,7 +468,11 @@ async function onDictionaryImport(e) {
const summary = await utilDatabaseImport(e.target.files[0], updateProgress, exceptions);
const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
- options.dictionaries[summary.title] = {enabled: true, priority: 0, allowSecondarySearches: false};
+ options.dictionaries[summary.title] = utilBackgroundIsolate({
+ enabled: true,
+ priority: 0,
+ allowSecondarySearches: false
+ });
if (summary.sequenced && options.general.mainDictionary === '') {
options.general.mainDictionary = summary.title;
}
@@ -621,7 +625,7 @@ async function onAnkiModelChanged(e) {
const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
await formRead(options);
- options.anki[tabId].fields = {};
+ options.anki[tabId].fields = utilBackgroundIsolate({});
await settingsSaveOptions();
ankiSpinnerShow(true);
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 79229229..73a8396f 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -26,6 +26,11 @@ function utilIsolate(data) {
return JSON.parse(JSON.stringify(data));
}
+function utilBackgroundIsolate(data) {
+ const backgroundPage = chrome.extension.getBackgroundPage();
+ return backgroundPage.utilIsolate(data);
+}
+
function utilSetEqual(setA, setB) {
if (setA.size !== setB.size) {
return false;