Permalink
Browse files

fix namespace pollution

fix exception handling
  • Loading branch information...
1 parent e77efc1 commit 1e32ef7e1d40dfc41fab77fb7d12ab01056656bd @benmmurphy committed Nov 2, 2010
Showing with 60 additions and 54 deletions.
  1. +34 −12 chrome/content/module.js
  2. +23 −18 chrome/content/overlay.js
  3. +3 −2 install.rdf
  4. +0 −22 jsbeautifier_xpi_licence.txt
View
@@ -11,9 +11,7 @@ jsbeautifier.removeListener = function(l) {
if (i < 0) {
return;
}
- Components.utils.reportError("removing listener: " + i);
this.listeners.splice(i, 1);
- Components.utils.reportError("listeners: " + this.listeners);
};
jsbeautifier.toggle = function() {
@@ -33,7 +31,6 @@ var jsb = function() {
var httpRequestObserver = {
observe: function(subject, topic, data) {
-
if (jsbeautifier.active && (topic == 'http-on-examine-response' || topic == 'http-on-examine-cached-response')) {
if (subject instanceof Components.interfaces.nsIHttpChannel) {
var newListener = new JSBeautifierListener();
@@ -67,9 +64,13 @@ var jsb = function() {
}
JSBeautifierListener.prototype.isJavascript = function(subject) {
- if (subject instanceof Components.interfaces.nsIHttpChannel) {
- var contentType = subject.getResponseHeader("Content-Type");
- return contentType != null && (contentType.indexOf("text/javascript") !== -1 || contentType.indexOf("application/javascript") !== -1);
+ try {
+ if (subject instanceof Components.interfaces.nsIHttpChannel) {
+ var contentType = subject.getResponseHeader("Content-Type");
+ return contentType != null && (contentType.indexOf("text/javascript") !== -1 || contentType.indexOf("application/javascript") !== -1 || contentType.indexOf("application/x-javascript") !== -1);
+ }
+ } catch (err) {
+ // ignore
}
return false;
@@ -84,14 +85,21 @@ var jsb = function() {
var data = binaryInputStream.readBytes(count);
this.receivedData.push(data);
} else {
- this.originalListener.onDataAvailable(request, context, inputStream, offset, count);
+ try {
+ this.originalListener.onDataAvailable(request, context, inputStream, offset, count);
+ } catch (err) {
+ request.cancel(err.result);
+ }
}
};
JSBeautifierListener.prototype.onStartRequest = function(request, context) {
this.intercept = this.isJavascript(request);
-
- this.originalListener.onStartRequest(request, context);
+ try {
+ this.originalListener.onStartRequest(request, context);
+ } catch (err) {
+ request.cancel(err.result);
+ }
};
JSBeautifierListener.prototype.spawnWorker = function(request, context, statusCode) {
@@ -107,8 +115,18 @@ var jsb = function() {
var os = storageStream.getOutputStream(0);
os.write(new_js, new_js.length);
os.close();
- t.originalListener.onDataAvailable(request, context, storageStream.newInputStream(0), 0, new_js.length);
- t.originalListener.onStopRequest(request, context, statusCode);
+
+ try {
+ t.originalListener.onDataAvailable(request, context, storageStream.newInputStream(0), 0, new_js.length);
+ } catch (err) {
+ // ignore .. this is after onStopRequest.. so there is not much we can do..
+ }
+
+ try {
+ t.originalListener.onStopRequest(request, context, statusCode);
+ } catch (err) {
+ // ignore .. this is after onStopRequest.. so there is not much we can do..
+ }
};
worker.onmessage = onMessage;
};
@@ -117,7 +135,11 @@ var jsb = function() {
if (this.intercept) {
this.spawnWorker(request, context, statusCode);
} else {
- this.originalListener.onStopRequest(request, context, statusCode);
+ try {
+ this.originalListener.onStopRequest(request, context, statusCode);
+ } catch (err) {
+ // ignore
+ }
}
};
View
@@ -1,23 +1,28 @@
-Components.utils.import("resource://modules/module.js");
-jsbeautifier.Worker = Worker;
+(function() {
+ Components.utils.import("resource://modules/module.js");
+ jsbeautifier.Worker = Worker;
-function update_text() {
- document.getElementById("jsbStatus").label = jsbeautifier.active ? "JSB ON" : "JSB OFF";
-};
-function toggle() {
- jsbeautifier.toggle();
-};
+ function update_text() {
+ document.getElementById("jsbStatus").label = jsbeautifier.active ? "JSB ON" : "JSB OFF";
+ };
-function load() {
- update_text();
- jsbeautifier.addListener(update_text);
- document.getElementById("jsbStatus").addEventListener("click", toggle, false);
-};
+ function toggle() {
+ jsbeautifier.toggle();
+ };
-function unload() {
- jsbeautifier.removeListener(update_text);
-};
+ function load() {
+ update_text();
+ jsbeautifier.addListener(update_text);
+ document.getElementById("jsbStatus").addEventListener("click", toggle, false);
+ };
+
+ function unload() {
+ jsbeautifier.removeListener(update_text);
+ };
+
+ window.addEventListener("load", load, false);
+ window.addEventListener("unload", unload, false);
+
+})();
-window.addEventListener("load", load, false);
-window.addEventListener("unload", unload, false);
View
@@ -6,10 +6,11 @@
<Description about="urn:mozilla:install-manifest">
<!-- Required Items -->
- <em:id>jsbeautifier@murphy.ben.name</em:id>
- <em:name>JS Beautifier</em:name>
+ <em:id>jsdeminifier@murphy.ben.name</em:id>
+ <em:name>JS Deminifier</em:name>
<em:version>1.0</em:version>
+
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
@@ -1,22 +0,0 @@
-Copyright (c) 2010 Ben Murphy
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.

0 comments on commit 1e32ef7

Please sign in to comment.