[Pkg-mozext-commits] [greasemonkey] 27/55: Style/grammar/whitespace/etc. cleanup.

David Prévot taffit at moszumanska.debian.org
Thu Oct 29 15:38:04 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository greasemonkey.

commit 726cbba4ea41e2fea317de1d5b7cf0f4b4809ae3
Author: Anthony Lieuallen <arantius at gmail.com>
Date:   Wed Sep 23 17:35:20 2015 -0400

    Style/grammar/whitespace/etc. cleanup.
---
 components/greasemonkey.js |  62 ++++++++++---------------
 content/framescript.js     |   4 +-
 modules/abstractScript.js  |   4 +-
 modules/ipcscript.js       | 112 +++++++++++++++++++++------------------------
 modules/miscapis.js        |   8 ++--
 modules/processScript.js   |   8 ++--
 modules/sandbox.js         |  45 ++++++++++--------
 modules/script.js          |   7 ++-
 modules/util.js            |   2 +-
 modules/util/fileXHR.js    |  15 ------
 modules/util/fileXhr.js    |  18 ++++++++
 11 files changed, 133 insertions(+), 152 deletions(-)

diff --git a/components/greasemonkey.js b/components/greasemonkey.js
index a661629..136041a 100644
--- a/components/greasemonkey.js
+++ b/components/greasemonkey.js
@@ -31,10 +31,8 @@ var GM_GUID = "{e4a8a97b-f2ed-450b-b12d-ee082ba24781}";
 var gGreasemonkeyVersion = 'unknown';
 Cu.import("resource://gre/modules/AddonManager.jsm");
 
-
 /////////////////////// Component-global Helper Functions //////////////////////
 
-
 function shutdown(aService) {
   aService.closeAllScriptValStores();
 }
@@ -81,24 +79,23 @@ function startup(aService) {
   // Why?  Who knows!?
   globalMessageManager.loadFrameScript(
       'chrome://greasemonkey/content/framescript.js', true);
-  
 
-  
-  // beam down initial set of scripts
+  // Beam down initial set of scripts.
   aService.broadcastScriptUpdates();
-  
-  // notification is async
-  // send the scripts again once we have our version
+
+  // Notification is async; send the scripts again once we have our version.
   AddonManager.getAddonByID(GM_GUID, function(addon) {
     gGreasemonkeyVersion = '' + addon.version;
     aService.broadcastScriptUpdates();
   });
-  
-  // beam down on updates
+
+  // Beam down on updates.
   aService.config.addObserver({notifyEvent: function(script, event, data) {
-    if(["modified", "install", "move", "edit-enabled", "uninstall"].some(function(e) {return e == event;})) {
-      aService.broadcastScriptUpdates();
-    }
+    if (["modified", "install", "move", "edit-enabled", "uninstall"]
+        .some(function(e) {return e == event;})
+      ) {
+        aService.broadcastScriptUpdates();
+      }
   }});
 
   Services.obs.addObserver(aService, 'quit-application', false);
@@ -152,34 +149,26 @@ service.prototype.__defineGetter__('config', function() {
 
 service.prototype.scriptUpdateData = function() {
   var ipcScripts = this.config.scripts.map(function(script) {
-    return new IPCScript(script, gGreasemonkeyVersion);        
+    return new IPCScript(script, gGreasemonkeyVersion);
   });
-  
   var excludes = this.config._globalExcludes;
-  
-  var data = { scripts: ipcScripts, globalExcludes: excludes};
-  
-  return data;
-}
+  return {scripts: ipcScripts, globalExcludes: excludes};
+};
 
 service.prototype.broadcastScriptUpdates = function() {
-  
-  var data = this.scriptUpdateData();
-  
   var ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"]
-    .getService(Ci.nsIMessageListenerManager);
-  
-  
-  // check if initialProcessData is supported
-  // child will use sync message if not
-  if(ppmm.initialProcessData) {
-    // for new processes
+      .getService(Ci.nsIMessageListenerManager);
+
+  // Check if initialProcessData is supported, else child will use sync message.
+  var data = this.scriptUpdateData();
+  if (ppmm.initialProcessData) {
+    // For new processes.
     ppmm.initialProcessData["greasemonkey:scripts-update"] = data;
+  } else {
+    // For existing ones.
+    ppmm.broadcastAsyncMessage("greasemonkey:scripts-update", data);
   }
-  
-  // for existing ones
-  ppmm.broadcastAsyncMessage("greasemonkey:scripts-update", data);
-}
+};
 
 service.prototype.closeAllScriptValStores = function() {
   for (var scriptId in this.scriptValStores) {
@@ -189,15 +178,14 @@ service.prototype.closeAllScriptValStores = function() {
 };
 
 service.prototype.scriptRefresh = function(url, windowId, browser) {
-
-  if (!GM_util.getEnabled() || !url) return [];
+  if (!GM_util.getEnabled()) return [];
+  if (!url) return [];
   if (!GM_util.isGreasemonkeyable(url)) return [];
 
   if (GM_prefRoot.getValue('enableScriptRefreshing')) {
     this.config.updateModifiedScripts("document-start", url, windowId, browser);
     this.config.updateModifiedScripts("document-end", url, windowId, browser);
   }
-
 };
 
 service.prototype.getScriptsForUuid = function(aMessage) {
diff --git a/content/framescript.js b/content/framescript.js
index 282f731..e55f76e 100644
--- a/content/framescript.js
+++ b/content/framescript.js
@@ -146,9 +146,9 @@ function newScriptLoadStart(aMessage) {
 function runScripts(aRunWhen, aContentWin) {
   var url = urlForWin(aContentWin);
   if (!GM_util.isGreasemonkeyable(url)) return;
-  
-  var scripts = IPCScript.scriptsForUrl(url, aRunWhen, GM_util.windowId(aContentWin, 'outer'));
 
+  var scripts = IPCScript.scriptsForUrl(
+      url, aRunWhen, GM_util.windowId(aContentWin, 'outer'));
   injectScripts(scripts, aContentWin);
 }
 
diff --git a/modules/abstractScript.js b/modules/abstractScript.js
index 436c6f4..b9a4d7b 100644
--- a/modules/abstractScript.js
+++ b/modules/abstractScript.js
@@ -10,9 +10,7 @@ Cu.import('chrome://greasemonkey-modules/content/third-party/convert2RegExp.js')
 Cu.import('chrome://greasemonkey-modules/content/third-party/MatchPattern.js');
 Cu.import('chrome://greasemonkey-modules/content/util.js');
 
-function AbstractScript() {
-
-}
+function AbstractScript() { }
 
 Object.defineProperty(AbstractScript.prototype, "globalExcludes", {
   get: function() {
diff --git a/modules/ipcscript.js b/modules/ipcscript.js
index b064b9b..b309d73 100644
--- a/modules/ipcscript.js
+++ b/modules/ipcscript.js
@@ -4,38 +4,36 @@ Components.utils.import("chrome://greasemonkey-modules/content/util.js");
 Components.utils.import('chrome://greasemonkey-modules/content/abstractScript.js');
 
 
-// IPCScript class
-
-
 function IPCScript(aScript, addonVersion) {
   this.addonVersion = addonVersion;
-  this.enabled = aScript.enabled;
-  this.needsUninstall = aScript.needsUninstall;
-  this.pendingExec = {};
-  this.pendingExec.length = aScript.pendingExec.length || 0
   this.description = aScript.description;
+  this.enabled = aScript.enabled;
   this.excludes = aScript.excludes;
-  this.userExcludes = aScript.userExcludes;
   this.fileURL = aScript.fileURL;
   this.grants = aScript.grants;
   this.id = aScript.id;
   this.includes = aScript.includes;
-  this.userIncludes = aScript.userIncludes;
   this.localized = aScript.localized;
-  this.matches = aScript.matches.map(function(m) {
-    return m.pattern;
-  });
-  this.userMatches = aScript.userMatches.map(function(m) {
-    return m.pattern;
-  });
   this.name = aScript.name;
   this.namespace = aScript.namespace;
+  this.needsUninstall = aScript.needsUninstall;
   this.noframes = aScript.noframes;
+  this.pendingExec = {};
+  this.pendingExec.length = aScript.pendingExec.length || 0;
   this.runAt = aScript.runAt;
+  this.userExcludes = aScript.userExcludes;
+  this.userIncludes = aScript.userIncludes;
   this.uuid = aScript.uuid;
   this.version = aScript.version;
   this.willUpdate = aScript.isRemoteUpdateAllowed();
 
+  this.matches = aScript.matches.map(function(m) {
+    return m.pattern;
+  });
+  this.userMatches = aScript.userMatches.map(function(m) {
+    return m.pattern;
+  });
+
   this.requires = aScript.requires.map(function(req) {
     return {
       'fileURL': req.fileURL
@@ -51,54 +49,13 @@ function IPCScript(aScript, addonVersion) {
   });
 };
 
-//inheritance magic
 IPCScript.prototype = Object.create(AbstractScript.prototype, {
   constructor: {
-    value: IPCScript 
+    value: IPCScript
   }
 });
 
 
-// initialize module-scoped stuff, after prototype override
-
-var scripts = [];
-
-const cpmm = Components.classes["@mozilla.org/childprocessmessagemanager;1"]
-    .getService(Components.interfaces.nsISyncMessageSender);
-
-function objectToScript(obj) {
-  var script = Object.create(IPCScript.prototype);
-  Object.keys(obj).forEach(function(k) {
-    script[k] = obj[k];
-  });
-  Object.freeze(script);
-  return script;
-}
-
-function updateData(data) {
-  if (!data) return;
-  var newScripts = data.scripts.map(objectToScript);
-  Object.freeze(newScripts);
-  scripts = newScripts;
-  IPCScript.prototype.globalExcludes = data.globalExcludes;
-}
-
-if (cpmm.initialProcessData) {
-  updateData(cpmm.initialProcessData["greasemonkey:scripts-update"]);
-} else {
-  // support FF < 41
-  var results = cpmm.sendSyncMessage("greasemonkey:scripts-update");
-  updateData(results[0]);
-}
-
-cpmm.addMessageListener("greasemonkey:scripts-update", function(message) {
-  updateData(message.data);
-});
-
-
-
-// static method
-
 IPCScript.scriptsForUrl = function(url, when, windowId) {
     return scripts.filter(function(script) {
       try {
@@ -110,9 +67,7 @@ IPCScript.scriptsForUrl = function(url, when, windowId) {
         return false;
       }
    });
-}
-
-// instance methods
+};
 
 
 IPCScript.prototype.info = function() {
@@ -145,4 +100,39 @@ IPCScript.prototype.info = function() {
       'version': this.version
     }
   };
-};
\ No newline at end of file
+};
+
+
+var scripts = [];
+
+const cpmm = Components.classes["@mozilla.org/childprocessmessagemanager;1"]
+    .getService(Components.interfaces.nsISyncMessageSender);
+
+function objectToScript(obj) {
+  var script = Object.create(IPCScript.prototype);
+  Object.keys(obj).forEach(function(k) {
+    script[k] = obj[k];
+  });
+  Object.freeze(script);
+  return script;
+}
+
+function updateData(data) {
+  if (!data) return;
+  var newScripts = data.scripts.map(objectToScript);
+  Object.freeze(newScripts);
+  scripts = newScripts;
+  IPCScript.prototype.globalExcludes = data.globalExcludes;
+}
+
+if (cpmm.initialProcessData) {
+  updateData(cpmm.initialProcessData["greasemonkey:scripts-update"]);
+} else {
+  // Support FF < 41.
+  var results = cpmm.sendSyncMessage("greasemonkey:scripts-update");
+  updateData(results[0]);
+}
+
+cpmm.addMessageListener("greasemonkey:scripts-update", function(message) {
+  updateData(message.data);
+});
diff --git a/modules/miscapis.js b/modules/miscapis.js
index 70f0e41..a0bebe4 100644
--- a/modules/miscapis.js
+++ b/modules/miscapis.js
@@ -26,11 +26,9 @@ GM_Resources.prototype.getResourceURL = function(aScript, name) {
 
 
 GM_Resources.prototype.getResourceText = function(name) {
-  var dep = this._getDep(name)
-  if(dep.textContent !== undefined)
-    return dep.textContent;
-  // lazy resources in IPC scripts
-  return GM_util.fileXHR(dep.url, "text/plain");
+  var dep = this._getDep(name);
+  if (dep.textContent !== undefined) return dep.textContent;
+  return GM_util.fileXhr(dep.url, "text/plain");
 };
 
 GM_Resources.prototype._getDep = function(name) {
diff --git a/modules/processScript.js b/modules/processScript.js
index 3aa3271..4916418 100644
--- a/modules/processScript.js
+++ b/modules/processScript.js
@@ -2,13 +2,13 @@
 
 // frame scripts, including all their functions, block scopes etc. are instantiated for each tab
 // having a single per-process script has a lower footprint for stateless things.
-// avoid keeping references to frame scripts or their content, this could leak frames! 
+// avoid keeping references to frame scripts or their content, this could leak frames!
 
 const EXPORTED_SYMBOLS = ['addFrame'];
 
- 
+
 function addFrame(frameMM) {
-  frameMM.addMessageListener("greasemonkey:frame-urls", urlTree)
+  frameMM.addMessageListener("greasemonkey:frame-urls", urlTree);
 }
 
 
@@ -26,4 +26,4 @@ function urlTree(message) {
   var urls = urlsOfAllFrames(frameMM.content);
   var response = {urls: urls};
   frameMM.sendAsyncMessage("greasemonkey:frame-urls", response);
-}
\ No newline at end of file
+}
diff --git a/modules/sandbox.js b/modules/sandbox.js
index a9f9c45..77efb79 100644
--- a/modules/sandbox.js
+++ b/modules/sandbox.js
@@ -136,16 +136,16 @@ function injectGMInfo(aScript, sandbox) {
 
   // TODO: also delay top level clone via lazy getter? XPCOMUtils.defineLazyGetter
   sandbox.GM_info = Cu.cloneInto(rawInfo, sandbox);
-  
+
   var waivedInfo = Components.utils.waiveXrays(sandbox.GM_info);
-  
+
   var fileCache = new Map();
-  
+
 
   function getScriptSource() {
     var content = fileCache.get("scriptSource");
     if (content === undefined) {
-      content = GM_util.fileXHR(scriptURL, "application/javascript");
+      content = GM_util.fileXhr(scriptURL, "application/javascript");
       fileCache.set("scriptSource", content);
     }
     return content;
@@ -172,20 +172,12 @@ function injectGMInfo(aScript, sandbox) {
 
 }
 
-function uriToString(uri) {
-  var channel = NetUtil.newChannel({ uri: NetUtil.newURI(uri, "UTF-8"), loadUsingSystemPrincipal: true});
-  var stream = channel.open();
-
-  var count = stream.available();
-  var data = NetUtil.readInputStreamToString(stream, count, { charset : "utf-8" });
-  return data;
-}
 
 function runScriptInSandbox(script, sandbox) {
   // Eval the code, with anonymous wrappers when/if appropriate.
-  function evalWithWrapper(uri) {
+  function evalWithWrapper(url) {
     try {
-    	subLoader.loadSubScript(uri, sandbox, "UTF-8");
+      subLoader.loadSubScript(url, sandbox, "UTF-8");
     } catch (e) {
       if ("return not in function" == e.message) {
         // See #1592; we never anon wrap anymore, unless forced to by a return
@@ -196,11 +188,10 @@ function runScriptInSandbox(script, sandbox) {
             fileName,
             e.lineNumber
             );
-        
-        var code = GM_util.fileXHR(uri, "application/javascript");
-        
+
+        var code = GM_util.fileXhr(url, "application/javascript");
         Components.utils.evalInSandbox(
-            '(function(){ '+code+'\n})()', sandbox, gMaxJSVersion, uri, 1);
+            '(function(){ '+code+'\n})()', sandbox, gMaxJSVersion, url, 1);
       } else {
         // Otherwise raise.
         throw e;
@@ -209,9 +200,9 @@ function runScriptInSandbox(script, sandbox) {
   }
 
   // Eval the code, with a try/catch to report errors cleanly.
-  function evalWithCatch(uri) {
+  function evalWithCatch(url) {
     try {
-      evalWithWrapper(uri);
+      evalWithWrapper(url);
     } catch (e) {
       // Log it properly.
       GM_util.logError(e, false, e.fileName, e.lineNumber);
@@ -228,3 +219,17 @@ function runScriptInSandbox(script, sandbox) {
   }
   evalWithCatch(script.fileURL);
 }
+
+
+function urlToString(url) {
+  var channel = NetUtil.newChannel({
+      uri: NetUtil.newURI(url, "UTF-8"),
+      loadUsingSystemPrincipal: true,
+  });
+  var stream = channel.open();
+
+  var count = stream.available();
+  var data = NetUtil.readInputStreamToString(
+      stream, count, { charset : "utf-8" });
+  return data;
+}
diff --git a/modules/script.js b/modules/script.js
index ef7da32..a3e0f1e 100644
--- a/modules/script.js
+++ b/modules/script.js
@@ -76,16 +76,15 @@ function Script(configNode) {
   if (configNode) this._loadFromConfigNode(configNode);
 }
 
-// inheritance magic
 Script.prototype = Object.create(AbstractScript.prototype, {
   constructor: {
-    value: Script 
+    value: Script
   }
 });
 
 Object.defineProperty(Script.prototype, "globalExcludes", {
-  get: function(){return GM_util.getService().config._globalExcludes;}
-})
+  get: function(){ return GM_util.getService().config._globalExcludes; }
+});
 
 Script.prototype._changed = function(event, data) {
   var dontSave = ('val-set' == event || 'val-del' == event);
diff --git a/modules/util.js b/modules/util.js
index acfeb1e..6299951 100644
--- a/modules/util.js
+++ b/modules/util.js
@@ -28,7 +28,7 @@ XPCOMUtils.defineLazyModuleGetter(GM_util, 'channelFromUri', 'chrome://greasemon
 XPCOMUtils.defineLazyModuleGetter(GM_util, 'compareFirefoxVersion', 'chrome://greasemonkey-modules/content/util/compareFirefoxVersion.js');
 XPCOMUtils.defineLazyModuleGetter(GM_util, 'emptyEl', 'chrome://greasemonkey-modules/content/util/emptyEl.js');
 XPCOMUtils.defineLazyModuleGetter(GM_util, 'enqueueRemoveFile', 'chrome://greasemonkey-modules/content/util/enqueueRemoveFile.js');
-XPCOMUtils.defineLazyModuleGetter(GM_util, 'fileXHR', 'chrome://greasemonkey-modules/content/util/fileXHR.js');
+XPCOMUtils.defineLazyModuleGetter(GM_util, 'fileXhr', 'chrome://greasemonkey-modules/content/util/fileXhr.js');
 XPCOMUtils.defineLazyModuleGetter(GM_util, 'findMessageManager', 'chrome://greasemonkey-modules/content/util/findMessageManager.js');
 XPCOMUtils.defineLazyModuleGetter(GM_util, 'getBestLocaleMatch', 'chrome://greasemonkey-modules/content/util/getBestLocaleMatch.js');
 XPCOMUtils.defineLazyModuleGetter(GM_util, 'getBinaryContents', 'chrome://greasemonkey-modules/content/util/getBinaryContents.js');
diff --git a/modules/util/fileXHR.js b/modules/util/fileXHR.js
deleted file mode 100644
index ccc13d2..0000000
--- a/modules/util/fileXHR.js
+++ /dev/null
@@ -1,15 +0,0 @@
-'use strict';
-
-var EXPORTED_SYMBOLS = ['fileXHR'];
-
-Components.utils.importGlobalProperties(["XMLHttpRequest"]);
-
-// sync XHR. it's just meant to fetch file:// uris that aren't otherwise accessible in content
-// don't use it in the parent process or for web URLs
-function fileXHR(uri, mimetype) {
-  var xhr = new XMLHttpRequest();
-  xhr.open("open", uri, false);
-  xhr.overrideMimeType(mimetype);
-  xhr.send(null);  
-  return xhr.responseText;
-}
\ No newline at end of file
diff --git a/modules/util/fileXhr.js b/modules/util/fileXhr.js
new file mode 100644
index 0000000..64a813d
--- /dev/null
+++ b/modules/util/fileXhr.js
@@ -0,0 +1,18 @@
+'use strict';
+
+var EXPORTED_SYMBOLS = ['fileXhr'];
+
+Components.utils.importGlobalProperties(["XMLHttpRequest"]);
+
+// Sync XHR.  It's just meant to fetch file:// URLs that aren't otherwise
+// accessible in content.  Don't use it in the parent process or for web URLs.
+function fileXhr(url, mimetype) {
+  if (!url.match(/^file:\/\//)) {
+    throw new Error('fileXhr() used for non-file URL: ' + url + '\n');
+  }
+  var xhr = new XMLHttpRequest();
+  xhr.open("open", url, false);
+  xhr.overrideMimeType(mimetype);
+  xhr.send(null);
+  return xhr.responseText;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/greasemonkey.git



More information about the Pkg-mozext-commits mailing list