Use toIterable for cross-window origin objects
This commit is contained in:
parent
8195e5109b
commit
8b7558a757
@ -36,7 +36,7 @@ ConditionsUI.Container = class Container {
|
|||||||
|
|
||||||
this.container.empty();
|
this.container.empty();
|
||||||
|
|
||||||
for (const conditionGroup of conditionGroups) {
|
for (const conditionGroup of toIterable(conditionGroups)) {
|
||||||
this.children.push(new ConditionsUI.ConditionGroup(this, conditionGroup));
|
this.children.push(new ConditionsUI.ConditionGroup(this, conditionGroup));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ ConditionsUI.ConditionGroup = class ConditionGroup {
|
|||||||
this.separator = ConditionsUI.instantiateTemplate('#condition-group-separator-template').appendTo(parent.container);
|
this.separator = ConditionsUI.instantiateTemplate('#condition-group-separator-template').appendTo(parent.container);
|
||||||
this.addButton = this.options.find('.condition-add');
|
this.addButton = this.options.find('.condition-add');
|
||||||
|
|
||||||
for (const condition of conditionGroup.conditions) {
|
for (const condition of toIterable(conditionGroup.conditions)) {
|
||||||
this.children.push(new ConditionsUI.Condition(this, condition));
|
this.children.push(new ConditionsUI.Condition(this, condition));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +422,7 @@ async function onDictionaryPurge(e) {
|
|||||||
dictionarySpinnerShow(true);
|
dictionarySpinnerShow(true);
|
||||||
|
|
||||||
await utilDatabasePurge();
|
await utilDatabasePurge();
|
||||||
for (const options of await getOptionsArray()) {
|
for (const options of toIterable(await getOptionsArray())) {
|
||||||
options.dictionaries = utilBackgroundIsolate({});
|
options.dictionaries = utilBackgroundIsolate({});
|
||||||
options.general.mainDictionary = '';
|
options.general.mainDictionary = '';
|
||||||
}
|
}
|
||||||
@ -466,7 +466,7 @@ async function onDictionaryImport(e) {
|
|||||||
|
|
||||||
const exceptions = [];
|
const exceptions = [];
|
||||||
const summary = await utilDatabaseImport(e.target.files[0], updateProgress, exceptions);
|
const summary = await utilDatabaseImport(e.target.files[0], updateProgress, exceptions);
|
||||||
for (const options of await getOptionsArray()) {
|
for (const options of toIterable(await getOptionsArray())) {
|
||||||
options.dictionaries[summary.title] = utilBackgroundIsolate({
|
options.dictionaries[summary.title] = utilBackgroundIsolate({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
priority: 0,
|
priority: 0,
|
||||||
|
@ -17,13 +17,24 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// toIterable is required on Edge for cross-window origin objects.
|
||||||
function toIterable(value) {
|
function toIterable(value) {
|
||||||
if (typeof Symbol !== 'undefined' && typeof value[Symbol.iterator] !== 'undefined') {
|
if (typeof Symbol !== 'undefined' && typeof value[Symbol.iterator] !== 'undefined') {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const array = JSON.parse(JSON.stringify(value));
|
if (value !== null && typeof value === 'object') {
|
||||||
return Array.isArray(array) ? array : [];
|
const length = value.length;
|
||||||
|
if (typeof length === 'number' && Number.isFinite(length)) {
|
||||||
|
const array = [];
|
||||||
|
for (let i = 0; i < length; ++i) {
|
||||||
|
array.push(value[i]);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw 'Could not convert to iterable';
|
||||||
}
|
}
|
||||||
|
|
||||||
function extensionHasChrome() {
|
function extensionHasChrome() {
|
||||||
|
Loading…
Reference in New Issue
Block a user