summaryrefslogtreecommitdiff
path: root/common/modules
diff options
context:
space:
mode:
Diffstat (limited to 'common/modules')
-rw-r--r--common/modules/dom.jsm21
-rw-r--r--common/modules/io.jsm13
-rw-r--r--common/modules/javascript.jsm2
-rw-r--r--common/modules/services.jsm3
-rw-r--r--common/modules/storage.jsm7
-rw-r--r--common/modules/util.jsm9
6 files changed, 34 insertions, 21 deletions
diff --git a/common/modules/dom.jsm b/common/modules/dom.jsm
index fb007282..3e4f4ff9 100644
--- a/common/modules/dom.jsm
+++ b/common/modules/dom.jsm
@@ -142,7 +142,8 @@ var DOM = Class("DOM", {
util.withProperErrors(fn, this, munge(val.call(this, elem, i)), elem, i);
}, self || this);
- util.withProperErrors(fn, self || this, munge(val), this[0], 0);
+ if (this.length)
+ util.withProperErrors(fn, self || this, munge(val), this[0], 0);
return this;
},
@@ -266,7 +267,7 @@ var DOM = Class("DOM", {
add: function add(cls) this.each("add", cls),
remove: function remove(cls) this.each("remove", cls),
- toggle: function toggle(cls) this.each("toggle", cls),
+ toggle: function toggle(cls, val) this.each(val == null ? "toggle" : val ? "add" : "remove", cls),
has: function has(cls) this[0].classList.has(cls)
}),
@@ -290,9 +291,9 @@ var DOM = Class("DOM", {
this.highlight.list.filter(function (h) h != hl));
}),
- toggle: function toggle(hl) self.each(function () {
+ toggle: function toggle(hl, val) self.each(function () {
let { highlight } = this;
- highlight[highlight.has(hl) ? "remove" : "add"](hl)
+ highlight[val == null ? highlight.has(hl) : val ? "remove" : "add"](hl)
}),
}),
@@ -523,13 +524,17 @@ var DOM = Class("DOM", {
if (isObject(key))
return this.each(function (elem) {
- for (let [k, v] in Iterator(key))
+ for (let [k, v] in Iterator(key)) {
+ if (callable(v))
+ v = v.call(this, elem, i);
+
if (Set.has(hooks, k) && hooks[k].set)
hooks[k].set.call(this, elem, v, k);
else if (v == null)
elem.removeAttributeNS(ns, k);
else
elem.setAttributeNS(ns, k, v);
+ }
});
if (!this.length)
@@ -593,7 +598,7 @@ var DOM = Class("DOM", {
return this;
},
- prependTo: function appendTo(elem) {
+ prependTo: function prependTo(elem) {
if (!(elem instanceof this.constructor))
elem = this.constructor(elem, this.document);
elem.prepend(this);
@@ -662,7 +667,7 @@ var DOM = Class("DOM", {
getSet: function getSet(args, get, set) {
if (!args.length)
- return get.call(this, this[0]);
+ return this[0] && get.call(this, this[0]);
let [fn, self] = args;
if (!callable(fn))
@@ -698,7 +703,7 @@ var DOM = Class("DOM", {
event = array.toObject([[event, listener]]);
for (let [k, v] in Iterator(event))
- event[k] = util.wrapCallback(v);
+ event[k] = util.wrapCallback(v, true);
return this.each(function (elem) {
for (let [k, v] in Iterator(event))
diff --git a/common/modules/io.jsm b/common/modules/io.jsm
index 18029944..a43c55e3 100644
--- a/common/modules/io.jsm
+++ b/common/modules/io.jsm
@@ -316,13 +316,16 @@ var IO = Module("io", {
*
* @returns {File}
*/
- createTempFile: function createTempFile() {
- let file = services.directory.get("TmpD", Ci.nsIFile);
- file.append(this.config.tempFile);
+ createTempFile: function createTempFile(name) {
+ if (name instanceof Ci.nsIFile)
+ var file = name.clone();
+ else {
+ file = services.directory.get("TmpD", Ci.nsIFile);
+ file.append(name || config.addon.name);
+ }
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(600));
- Cc["@mozilla.org/uriloader/external-helper-app-service;1"]
- .getService(Ci.nsPIExternalAppLauncher).deleteTemporaryFileOnExit(file);
+ services.externalApp.deleteTemporaryFileOnExit(file);
return File(file);
},
diff --git a/common/modules/javascript.jsm b/common/modules/javascript.jsm
index aa2ab6f3..d1e92337 100644
--- a/common/modules/javascript.jsm
+++ b/common/modules/javascript.jsm
@@ -761,7 +761,7 @@ var JavaScript = Module("javascript", {
init.supercall(this);
let self = this;
- let sandbox = isinstance(context, ["Sandbox"]);
+ let sandbox = true || isinstance(context, ["Sandbox"]);
this.context = modules.newContext(context, !sandbox);
this.js = modules.JavaScript();
diff --git a/common/modules/services.jsm b/common/modules/services.jsm
index 6072d4d0..00ed5e8e 100644
--- a/common/modules/services.jsm
+++ b/common/modules/services.jsm
@@ -37,6 +37,7 @@ var Services = Module("Services", {
this.add("downloadManager", "@mozilla.org/download-manager;1", "nsIDownloadManager");
this.add("environment", "@mozilla.org/process/environment;1", "nsIEnvironment");
this.add("extensionManager", "@mozilla.org/extensions/manager;1", "nsIExtensionManager");
+ this.add("externalApp", "@mozilla.org/uriloader/external-helper-app-service;1", "nsPIExternalAppLauncher")
this.add("externalProtocol", "@mozilla.org/uriloader/external-protocol-service;1", "nsIExternalProtocolService");
this.add("favicon", "@mozilla.org/browser/favicon-service;1", "nsIFaviconService");
this.add("file:", "@mozilla.org/network/protocol;1?name=file", "nsIFileProtocolHandler");
@@ -72,8 +73,10 @@ var Services = Module("Services", {
this.addClass("CharsetConv", "@mozilla.org/intl/scriptableunicodeconverter", "nsIScriptableUnicodeConverter", "charset");
this.addClass("CharsetStream","@mozilla.org/intl/converter-input-stream;1", ["nsIConverterInputStream",
"nsIUnicharLineInputStream"], "init");
+ this.addClass("ConvOutStream","@mozilla.org/intl/converter-output-stream;1", "nsIConverterOutputStream", "init", false);
this.addClass("File", "@mozilla.org/file/local;1", "nsILocalFile");
this.addClass("FileInStream", "@mozilla.org/network/file-input-stream;1", "nsIFileInputStream", "init", false);
+ this.addClass("FileOutStream","@mozilla.org/network/file-output-stream;1", "nsIFileOutputStream", "init", false);
this.addClass("Find", "@mozilla.org/embedcomp/rangefind;1", "nsIFind");
this.addClass("HtmlConverter","@mozilla.org/widget/htmlformatconverter;1", "nsIFormatConverter");
this.addClass("HtmlEncoder", "@mozilla.org/layout/htmlCopyEncoder;1", "nsIDocumentEncoder");
diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm
index 23164566..b73bf444 100644
--- a/common/modules/storage.jsm
+++ b/common/modules/storage.jsm
@@ -425,11 +425,8 @@ this.File = Class("File", {
* @default #charset
*/
write: function (buf, mode, perms, encoding) {
- let ofstream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
function getStream(defaultChar) {
- let stream = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
- stream.init(ofstream, encoding, 0, defaultChar);
- return stream;
+ return services.ConvOutStream(ofstream, encoding, 0, defaultChar);
}
if (buf instanceof File)
buf = buf.read();
@@ -447,7 +444,7 @@ this.File = Class("File", {
if (!this.exists()) // OCREAT won't create the directory
this.create(this.NORMAL_FILE_TYPE, perms);
- ofstream.init(this, mode, perms, 0);
+ let ofstream = services.FileOutStream(this, mode, perms, 0);
try {
var ocstream = getStream(0);
ocstream.writeString(buf);
diff --git a/common/modules/util.jsm b/common/modules/util.jsm
index 1e7feacb..4a194819 100644
--- a/common/modules/util.jsm
+++ b/common/modules/util.jsm
@@ -28,11 +28,16 @@ var FailedAssertion = Class("FailedAssertion", ErrorBase, {
var Point = Struct("x", "y");
-var wrapCallback = function wrapCallback(fn) {
+var wrapCallback = function wrapCallback(fn, isEvent) {
if (!fn.wrapper)
fn.wrapper = function wrappedCallback() {
try {
- return fn.apply(this, arguments);
+ let res = fn.apply(this, arguments);
+ if (isEvent && res === false) {
+ arguments[0].preventDefault();
+ arguments[0].stopPropagation();
+ }
+ return res;
}
catch (e) {
util.reportError(e);