mirror of https://github.com/gorhill/uBlock.git
Code review: ensure vAPI.shutdown.exec is called from root context only
This prevents uncaught errors in content scripts when uBO's main process is terminated (i.e. disabled, updated).
This commit is contained in:
parent
a6ebcc85be
commit
920eee88be
|
@ -53,10 +53,15 @@ vAPI.shutdown = {
|
||||||
this.jobs.push(job);
|
this.jobs.push(job);
|
||||||
},
|
},
|
||||||
exec: function() {
|
exec: function() {
|
||||||
let job;
|
// Shutdown asynchronously, to ensure shutdown jobs are called from
|
||||||
while ( (job = this.jobs.pop()) ) {
|
// the top context.
|
||||||
job();
|
self.requestIdleCallback(( ) => {
|
||||||
}
|
const jobs = this.jobs.slice();
|
||||||
|
this.jobs.length = 0;
|
||||||
|
while ( jobs.length !== 0 ) {
|
||||||
|
(jobs.pop())();
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
remove: function(job) {
|
remove: function(job) {
|
||||||
let pos;
|
let pos;
|
||||||
|
@ -238,16 +243,20 @@ vAPI.messaging = {
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
this.port = null;
|
this.port = null;
|
||||||
}
|
}
|
||||||
if ( this.port !== null ) {
|
// Not having a valid port at this point means the main process is
|
||||||
this.port.onMessage.addListener(this.messageListenerCallback);
|
// not available: no point keeping the content scripts alive.
|
||||||
this.port.onDisconnect.addListener(this.disconnectListenerBound);
|
if ( this.port === null ) {
|
||||||
this.portTimerDelay = 10000;
|
vAPI.shutdown.exec();
|
||||||
if ( this.portTimer === null ) {
|
return null;
|
||||||
this.portTimer = vAPI.setTimeout(
|
}
|
||||||
this.portPollerBound,
|
this.port.onMessage.addListener(this.messageListenerCallback);
|
||||||
this.portTimerDelay
|
this.port.onDisconnect.addListener(this.disconnectListenerBound);
|
||||||
);
|
this.portTimerDelay = 10000;
|
||||||
}
|
if ( this.portTimer === null ) {
|
||||||
|
this.portTimer = vAPI.setTimeout(
|
||||||
|
this.portPollerBound,
|
||||||
|
this.portTimerDelay
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return this.port;
|
return this.port;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue