add rudimentary reject/catch for mozParser inside worker
This commit is contained in:
parent
08c70a5192
commit
f40dc29497
|
@ -579,7 +579,7 @@ var usercss = (() => {
|
|||
worker.instance = new Worker('/vendor-overwrites/csslint/csslint-worker.js');
|
||||
worker.queue = [];
|
||||
worker.instance.onmessage = ({data}) => {
|
||||
worker.queue.shift().resolve(data);
|
||||
worker.queue.shift().resolve(data.__ERROR__ ? Promise.reject(data.__ERROR__) : data);
|
||||
if (worker.queue.length) {
|
||||
worker.instance.postMessage(worker.queue[0].message);
|
||||
}
|
||||
|
|
|
@ -30,11 +30,7 @@ function configDialog(style) {
|
|||
{textContent: t('confirmClose'), dataset: {cmd: 'close'}},
|
||||
],
|
||||
onshow,
|
||||
}).then(() => {
|
||||
document.body.style.minWidth = '';
|
||||
document.body.style.minHeight = '';
|
||||
colorpicker.hide();
|
||||
});
|
||||
}).then(onhide);
|
||||
|
||||
function getInitialValues(source) {
|
||||
const data = {};
|
||||
|
@ -69,6 +65,12 @@ function configDialog(style) {
|
|||
updateButtons();
|
||||
}
|
||||
|
||||
function onhide() {
|
||||
document.body.style.minWidth = '';
|
||||
document.body.style.minHeight = '';
|
||||
colorpicker.hide();
|
||||
}
|
||||
|
||||
function onchange({target}) {
|
||||
// invoked after element's own onchange so 'va' contains the updated value
|
||||
const va = target.va;
|
||||
|
@ -129,6 +131,7 @@ function configDialog(style) {
|
|||
}
|
||||
}
|
||||
if (invalid.length) {
|
||||
onhide();
|
||||
messageBox.alert([
|
||||
$create('div', {style: 'max-width: 34em'}, t('usercssConfigIncomplete')),
|
||||
$create('ol', {style: 'text-align: left'},
|
||||
|
@ -136,11 +139,16 @@ function configDialog(style) {
|
|||
$create({tag: 'li', appendChild: msg}))),
|
||||
]);
|
||||
}
|
||||
return numValid && BG.usercssHelper.save(style).then(saved => {
|
||||
varsInitial = getInitialValues(deepCopy(saved.usercssData.vars));
|
||||
vars.forEach(va => onchange({target: va.input}));
|
||||
updateButtons();
|
||||
});
|
||||
if (!numValid) {
|
||||
return;
|
||||
}
|
||||
return BG.usercssHelper.save(style)
|
||||
.then(saved => {
|
||||
varsInitial = getInitialValues(deepCopy(saved.usercssData.vars));
|
||||
vars.forEach(va => onchange({target: va.input}));
|
||||
updateButtons();
|
||||
})
|
||||
.catch(errors => onhide() + messageBox.alert(Array.isArray(errors) ? errors.join('\n') : errors));
|
||||
}
|
||||
|
||||
function useDefault() {
|
||||
|
|
|
@ -11008,19 +11008,19 @@ self.onmessage = ({data: {action = 'run', code, config}}) => {
|
|||
self.postMessage(CSSLint.getRules().map(rule => JSON.parse(JSON.stringify(rule))));
|
||||
return;
|
||||
|
||||
case 'run':
|
||||
self.postMessage(CSSLint.verify(code, config).messages.map(m => {
|
||||
// the functions are non-tranferable and we need only an id
|
||||
m.rule = {id: m.rule.id};
|
||||
return m;
|
||||
}).filter(m => !m.message.includes('/*[[') && !m.message.includes(']]*/')));
|
||||
case 'run': {
|
||||
const results = CSSLint.verify(code, config).messages
|
||||
.filter(m => !m.message.includes('/*[[') && !m.message.includes(']]*/'))
|
||||
.map(m => Object.assign(m, {rule: {id: m.rule.id}}));
|
||||
self.postMessage(results);
|
||||
return;
|
||||
|
||||
}
|
||||
case 'parse':
|
||||
if (!self.mozParser) {
|
||||
self.importScripts('/js/moz-parser.js');
|
||||
}
|
||||
mozParser.parse(code)
|
||||
.then(sections => self.postMessage(sections));
|
||||
.then(sections => self.postMessage(sections))
|
||||
.catch(info => self.postMessage({__ERROR__: info}));
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user