add rudimentary reject/catch for mozParser inside worker

This commit is contained in:
tophf 2017-12-07 08:41:52 +03:00
parent 08c70a5192
commit f40dc29497
3 changed files with 27 additions and 19 deletions

View File

@ -579,7 +579,7 @@ var usercss = (() => {
worker.instance = new Worker('/vendor-overwrites/csslint/csslint-worker.js'); worker.instance = new Worker('/vendor-overwrites/csslint/csslint-worker.js');
worker.queue = []; worker.queue = [];
worker.instance.onmessage = ({data}) => { worker.instance.onmessage = ({data}) => {
worker.queue.shift().resolve(data); worker.queue.shift().resolve(data.__ERROR__ ? Promise.reject(data.__ERROR__) : data);
if (worker.queue.length) { if (worker.queue.length) {
worker.instance.postMessage(worker.queue[0].message); worker.instance.postMessage(worker.queue[0].message);
} }

View File

@ -30,11 +30,7 @@ function configDialog(style) {
{textContent: t('confirmClose'), dataset: {cmd: 'close'}}, {textContent: t('confirmClose'), dataset: {cmd: 'close'}},
], ],
onshow, onshow,
}).then(() => { }).then(onhide);
document.body.style.minWidth = '';
document.body.style.minHeight = '';
colorpicker.hide();
});
function getInitialValues(source) { function getInitialValues(source) {
const data = {}; const data = {};
@ -69,6 +65,12 @@ function configDialog(style) {
updateButtons(); updateButtons();
} }
function onhide() {
document.body.style.minWidth = '';
document.body.style.minHeight = '';
colorpicker.hide();
}
function onchange({target}) { function onchange({target}) {
// invoked after element's own onchange so 'va' contains the updated value // invoked after element's own onchange so 'va' contains the updated value
const va = target.va; const va = target.va;
@ -129,6 +131,7 @@ function configDialog(style) {
} }
} }
if (invalid.length) { if (invalid.length) {
onhide();
messageBox.alert([ messageBox.alert([
$create('div', {style: 'max-width: 34em'}, t('usercssConfigIncomplete')), $create('div', {style: 'max-width: 34em'}, t('usercssConfigIncomplete')),
$create('ol', {style: 'text-align: left'}, $create('ol', {style: 'text-align: left'},
@ -136,11 +139,16 @@ function configDialog(style) {
$create({tag: 'li', appendChild: msg}))), $create({tag: 'li', appendChild: msg}))),
]); ]);
} }
return numValid && BG.usercssHelper.save(style).then(saved => { if (!numValid) {
varsInitial = getInitialValues(deepCopy(saved.usercssData.vars)); return;
vars.forEach(va => onchange({target: va.input})); }
updateButtons(); 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() { function useDefault() {

View File

@ -11008,19 +11008,19 @@ self.onmessage = ({data: {action = 'run', code, config}}) => {
self.postMessage(CSSLint.getRules().map(rule => JSON.parse(JSON.stringify(rule)))); self.postMessage(CSSLint.getRules().map(rule => JSON.parse(JSON.stringify(rule))));
return; return;
case 'run': case 'run': {
self.postMessage(CSSLint.verify(code, config).messages.map(m => { const results = CSSLint.verify(code, config).messages
// the functions are non-tranferable and we need only an id .filter(m => !m.message.includes('/*[[') && !m.message.includes(']]*/'))
m.rule = {id: m.rule.id}; .map(m => Object.assign(m, {rule: {id: m.rule.id}}));
return m; self.postMessage(results);
}).filter(m => !m.message.includes('/*[[') && !m.message.includes(']]*/')));
return; return;
}
case 'parse': case 'parse':
if (!self.mozParser) { if (!self.mozParser) {
self.importScripts('/js/moz-parser.js'); self.importScripts('/js/moz-parser.js');
} }
mozParser.parse(code) mozParser.parse(code)
.then(sections => self.postMessage(sections)); .then(sections => self.postMessage(sections))
.catch(info => self.postMessage({__ERROR__: info}));
} }
}; };