1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-09 08:54:13 +01:00

Allow plugins onUnload handlers, fix some threadYield issues.

This commit is contained in:
Kris Maglione
2008-12-01 15:08:50 +00:00
parent 855caac185
commit a2550499c8
7 changed files with 24 additions and 15 deletions

View File

@@ -501,7 +501,7 @@ CompletionContext.prototype = {
{ {
let end = Date.now() + timeout; let end = Date.now() + timeout;
while (this.incomplete && (!timeout || Date.now() > end)) while (this.incomplete && (!timeout || Date.now() > end))
liberator.threadYield(true, interruptable); liberator.threadYield(false, interruptable);
return this.incomplete; return this.incomplete;
} }
} }

View File

@@ -566,13 +566,14 @@ function Events() //{{{
if (buffer.loaded == 1) if (buffer.loaded == 1)
return true; return true;
var ms = 25000; // maximum time to wait - TODO: add option let start = Date.now();
var then = new Date().getTime(); let end = start + 25000; // maximum time to wait - TODO: add option
for (let now = then; now - then < ms; now = new Date().getTime()) let now;
while (now = Date.now(), now < end)
{ {
liberator.threadYield(); liberator.threadYield();
if ((now - then) % 1000 < 10) if ((now - start) % 1000 < 10)
liberator.dump("waited: " + (now - then) + " ms"); liberator.dump("waited: " + (now - start) + " ms");
if (!events.feedingKeys) if (!events.feedingKeys)
return false; return false;

View File

@@ -204,7 +204,7 @@ function Search() //{{{
this.startPt.setStart(node, node.childNodes.length); this.startPt.setStart(node, node.childNodes.length);
this.startPt.setEnd(node, node.childNodes.length); this.startPt.setEnd(node, node.childNodes.length);
if (n++ % 20 == 0) if (n++ % 20 == 0)
liberator.threadYield(); liberator.threadYield(true);
if (liberator.interrupted) if (liberator.interrupted)
break; break;
} }

View File

@@ -30,8 +30,13 @@ the terms of any one of the MPL, the GPL or the LGPL.
plugins.contexts = {}; plugins.contexts = {};
function Script(name) function Script(name)
{ {
if (plugins.contexts[name]) let self = plugins.contexts[name]
return plugins.contexts[name]; if (self)
{
if (self.onUnload)
self.onUnload();
return self;
}
plugins.contexts[name] = this; plugins.contexts[name] = this;
this.NAME = name; this.NAME = name;
this.__context__ = this; this.__context__ = this;

View File

@@ -1021,7 +1021,10 @@ const liberator = (function () //{{{
if (urls.length > 20 && !force) if (urls.length > 20 && !force)
{ {
commandline.input("This will open " + urls.length + " new tabs. Would you like to continue? (yes/[no])", commandline.input("This will open " + urls.length + " new tabs. Would you like to continue? (yes/[no])",
function (resp) { if (resp && resp.match(/^y(es)?$/i)) liberator.open(urls, where, true); }); function (resp) {
if (resp && resp.match(/^y(es)?$/i))
liberator.open(urls, where, true);
});
return true; return true;
} }
@@ -1044,7 +1047,7 @@ const liberator = (function () //{{{
case liberator.NEW_BACKGROUND_TAB: case liberator.NEW_BACKGROUND_TAB:
case liberator.NEW_TAB: case liberator.NEW_TAB:
if (!liberator.has("tabs")) if (!liberator.has("tabs"))
open(urls, liberator.NEW_WINDOW); return open(urls, liberator.NEW_WINDOW);
let tab = getBrowser().addTab(url, null, null, postdata); let tab = getBrowser().addTab(url, null, null, postdata);
if (where == liberator.NEW_TAB) if (where == liberator.NEW_TAB)
@@ -1295,7 +1298,7 @@ const liberator = (function () //{{{
liberator.interrupted = false; liberator.interrupted = false;
do do
{ {
mainThread.processNextEvent(true); mainThread.processNextEvent(!flush);
if (liberator.interrupted) if (liberator.interrupted)
throw new Error("Interrupted"); throw new Error("Interrupted");
} }

View File

@@ -15,8 +15,8 @@ const template = {
continue; continue;
if (sep && n++) if (sep && n++)
ret += sep; ret += sep;
//if (interruptable && n % interruptable == 0) if (interruptable && n % interruptable == 0)
// liberator.threadYield(false, true); liberator.threadYield(true, true);
ret += val; ret += val;
} }
return ret; return ret;

View File

@@ -417,7 +417,7 @@ const util = { //{{{
{ {
if (Date.now() > endTime) if (Date.now() > endTime)
{ {
liberator.threadYield(false, true); liberator.threadYield(true, true);
endTime = Date.now() + time; endTime = Date.now() + time;
} }
yield start++; yield start++;