From a2550499c8d7391a7f3033f04fb9dea2f9c2e293 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 1 Dec 2008 15:08:50 +0000 Subject: [PATCH] Allow plugins onUnload handlers, fix some threadYield issues. --- content/completion.js | 2 +- content/events.js | 11 ++++++----- content/find.js | 2 +- content/io.js | 9 +++++++-- content/liberator.js | 9 ++++++--- content/template.js | 4 ++-- content/util.js | 2 +- 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/content/completion.js b/content/completion.js index 1840faa4..5f84b0d6 100644 --- a/content/completion.js +++ b/content/completion.js @@ -501,7 +501,7 @@ CompletionContext.prototype = { { let end = Date.now() + timeout; while (this.incomplete && (!timeout || Date.now() > end)) - liberator.threadYield(true, interruptable); + liberator.threadYield(false, interruptable); return this.incomplete; } } diff --git a/content/events.js b/content/events.js index a5cecd83..730ec02f 100644 --- a/content/events.js +++ b/content/events.js @@ -566,13 +566,14 @@ function Events() //{{{ if (buffer.loaded == 1) return true; - var ms = 25000; // maximum time to wait - TODO: add option - var then = new Date().getTime(); - for (let now = then; now - then < ms; now = new Date().getTime()) + let start = Date.now(); + let end = start + 25000; // maximum time to wait - TODO: add option + let now; + while (now = Date.now(), now < end) { liberator.threadYield(); - if ((now - then) % 1000 < 10) - liberator.dump("waited: " + (now - then) + " ms"); + if ((now - start) % 1000 < 10) + liberator.dump("waited: " + (now - start) + " ms"); if (!events.feedingKeys) return false; diff --git a/content/find.js b/content/find.js index a3f35f7a..b4c0ffe6 100644 --- a/content/find.js +++ b/content/find.js @@ -204,7 +204,7 @@ function Search() //{{{ this.startPt.setStart(node, node.childNodes.length); this.startPt.setEnd(node, node.childNodes.length); if (n++ % 20 == 0) - liberator.threadYield(); + liberator.threadYield(true); if (liberator.interrupted) break; } diff --git a/content/io.js b/content/io.js index 0a746761..c61e42a9 100644 --- a/content/io.js +++ b/content/io.js @@ -30,8 +30,13 @@ the terms of any one of the MPL, the GPL or the LGPL. plugins.contexts = {}; function Script(name) { - if (plugins.contexts[name]) - return plugins.contexts[name]; + let self = plugins.contexts[name] + if (self) + { + if (self.onUnload) + self.onUnload(); + return self; + } plugins.contexts[name] = this; this.NAME = name; this.__context__ = this; diff --git a/content/liberator.js b/content/liberator.js index 479aded3..0608e2ce 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -1021,7 +1021,10 @@ const liberator = (function () //{{{ if (urls.length > 20 && !force) { 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; } @@ -1044,7 +1047,7 @@ const liberator = (function () //{{{ case liberator.NEW_BACKGROUND_TAB: case liberator.NEW_TAB: if (!liberator.has("tabs")) - open(urls, liberator.NEW_WINDOW); + return open(urls, liberator.NEW_WINDOW); let tab = getBrowser().addTab(url, null, null, postdata); if (where == liberator.NEW_TAB) @@ -1295,7 +1298,7 @@ const liberator = (function () //{{{ liberator.interrupted = false; do { - mainThread.processNextEvent(true); + mainThread.processNextEvent(!flush); if (liberator.interrupted) throw new Error("Interrupted"); } diff --git a/content/template.js b/content/template.js index e1a7a227..9b339b91 100644 --- a/content/template.js +++ b/content/template.js @@ -15,8 +15,8 @@ const template = { continue; if (sep && n++) ret += sep; - //if (interruptable && n % interruptable == 0) - // liberator.threadYield(false, true); + if (interruptable && n % interruptable == 0) + liberator.threadYield(true, true); ret += val; } return ret; diff --git a/content/util.js b/content/util.js index 484468c1..cc961c54 100644 --- a/content/util.js +++ b/content/util.js @@ -417,7 +417,7 @@ const util = { //{{{ { if (Date.now() > endTime) { - liberator.threadYield(false, true); + liberator.threadYield(true, true); endTime = Date.now() + time; } yield start++;