1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 00:38:00 +01:00

Fix REPL with foreign window contexts. Other general cleanup.

This commit is contained in:
Kris Maglione
2011-09-05 08:46:31 -04:00
parent aa78825133
commit a5aafe63d9
6 changed files with 34 additions and 21 deletions

View File

@@ -142,7 +142,8 @@ var DOM = Class("DOM", {
util.withProperErrors(fn, this, munge(val.call(this, elem, i)), elem, i); util.withProperErrors(fn, this, munge(val.call(this, elem, i)), elem, i);
}, self || this); }, 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; return this;
}, },
@@ -266,7 +267,7 @@ var DOM = Class("DOM", {
add: function add(cls) this.each("add", cls), add: function add(cls) this.each("add", cls),
remove: function remove(cls) this.each("remove", 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) 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)); 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; 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)) if (isObject(key))
return this.each(function (elem) { 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) if (Set.has(hooks, k) && hooks[k].set)
hooks[k].set.call(this, elem, v, k); hooks[k].set.call(this, elem, v, k);
else if (v == null) else if (v == null)
elem.removeAttributeNS(ns, k); elem.removeAttributeNS(ns, k);
else else
elem.setAttributeNS(ns, k, v); elem.setAttributeNS(ns, k, v);
}
}); });
if (!this.length) if (!this.length)
@@ -593,7 +598,7 @@ var DOM = Class("DOM", {
return this; return this;
}, },
prependTo: function appendTo(elem) { prependTo: function prependTo(elem) {
if (!(elem instanceof this.constructor)) if (!(elem instanceof this.constructor))
elem = this.constructor(elem, this.document); elem = this.constructor(elem, this.document);
elem.prepend(this); elem.prepend(this);
@@ -662,7 +667,7 @@ var DOM = Class("DOM", {
getSet: function getSet(args, get, set) { getSet: function getSet(args, get, set) {
if (!args.length) if (!args.length)
return get.call(this, this[0]); return this[0] && get.call(this, this[0]);
let [fn, self] = args; let [fn, self] = args;
if (!callable(fn)) if (!callable(fn))
@@ -698,7 +703,7 @@ var DOM = Class("DOM", {
event = array.toObject([[event, listener]]); event = array.toObject([[event, listener]]);
for (let [k, v] in Iterator(event)) for (let [k, v] in Iterator(event))
event[k] = util.wrapCallback(v); event[k] = util.wrapCallback(v, true);
return this.each(function (elem) { return this.each(function (elem) {
for (let [k, v] in Iterator(event)) for (let [k, v] in Iterator(event))

View File

@@ -316,13 +316,16 @@ var IO = Module("io", {
* *
* @returns {File} * @returns {File}
*/ */
createTempFile: function createTempFile() { createTempFile: function createTempFile(name) {
let file = services.directory.get("TmpD", Ci.nsIFile); if (name instanceof Ci.nsIFile)
file.append(this.config.tempFile); 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)); file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(600));
Cc["@mozilla.org/uriloader/external-helper-app-service;1"] services.externalApp.deleteTemporaryFileOnExit(file);
.getService(Ci.nsPIExternalAppLauncher).deleteTemporaryFileOnExit(file);
return File(file); return File(file);
}, },

View File

@@ -761,7 +761,7 @@ var JavaScript = Module("javascript", {
init.supercall(this); init.supercall(this);
let self = this; let self = this;
let sandbox = isinstance(context, ["Sandbox"]); let sandbox = true || isinstance(context, ["Sandbox"]);
this.context = modules.newContext(context, !sandbox); this.context = modules.newContext(context, !sandbox);
this.js = modules.JavaScript(); this.js = modules.JavaScript();

View File

@@ -37,6 +37,7 @@ var Services = Module("Services", {
this.add("downloadManager", "@mozilla.org/download-manager;1", "nsIDownloadManager"); this.add("downloadManager", "@mozilla.org/download-manager;1", "nsIDownloadManager");
this.add("environment", "@mozilla.org/process/environment;1", "nsIEnvironment"); this.add("environment", "@mozilla.org/process/environment;1", "nsIEnvironment");
this.add("extensionManager", "@mozilla.org/extensions/manager;1", "nsIExtensionManager"); 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("externalProtocol", "@mozilla.org/uriloader/external-protocol-service;1", "nsIExternalProtocolService");
this.add("favicon", "@mozilla.org/browser/favicon-service;1", "nsIFaviconService"); this.add("favicon", "@mozilla.org/browser/favicon-service;1", "nsIFaviconService");
this.add("file:", "@mozilla.org/network/protocol;1?name=file", "nsIFileProtocolHandler"); 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("CharsetConv", "@mozilla.org/intl/scriptableunicodeconverter", "nsIScriptableUnicodeConverter", "charset");
this.addClass("CharsetStream","@mozilla.org/intl/converter-input-stream;1", ["nsIConverterInputStream", this.addClass("CharsetStream","@mozilla.org/intl/converter-input-stream;1", ["nsIConverterInputStream",
"nsIUnicharLineInputStream"], "init"); "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("File", "@mozilla.org/file/local;1", "nsILocalFile");
this.addClass("FileInStream", "@mozilla.org/network/file-input-stream;1", "nsIFileInputStream", "init", false); 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("Find", "@mozilla.org/embedcomp/rangefind;1", "nsIFind");
this.addClass("HtmlConverter","@mozilla.org/widget/htmlformatconverter;1", "nsIFormatConverter"); this.addClass("HtmlConverter","@mozilla.org/widget/htmlformatconverter;1", "nsIFormatConverter");
this.addClass("HtmlEncoder", "@mozilla.org/layout/htmlCopyEncoder;1", "nsIDocumentEncoder"); this.addClass("HtmlEncoder", "@mozilla.org/layout/htmlCopyEncoder;1", "nsIDocumentEncoder");

View File

@@ -425,11 +425,8 @@ this.File = Class("File", {
* @default #charset * @default #charset
*/ */
write: function (buf, mode, perms, encoding) { write: function (buf, mode, perms, encoding) {
let ofstream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
function getStream(defaultChar) { function getStream(defaultChar) {
let stream = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream); return services.ConvOutStream(ofstream, encoding, 0, defaultChar);
stream.init(ofstream, encoding, 0, defaultChar);
return stream;
} }
if (buf instanceof File) if (buf instanceof File)
buf = buf.read(); buf = buf.read();
@@ -447,7 +444,7 @@ this.File = Class("File", {
if (!this.exists()) // OCREAT won't create the directory if (!this.exists()) // OCREAT won't create the directory
this.create(this.NORMAL_FILE_TYPE, perms); this.create(this.NORMAL_FILE_TYPE, perms);
ofstream.init(this, mode, perms, 0); let ofstream = services.FileOutStream(this, mode, perms, 0);
try { try {
var ocstream = getStream(0); var ocstream = getStream(0);
ocstream.writeString(buf); ocstream.writeString(buf);

View File

@@ -28,11 +28,16 @@ var FailedAssertion = Class("FailedAssertion", ErrorBase, {
var Point = Struct("x", "y"); var Point = Struct("x", "y");
var wrapCallback = function wrapCallback(fn) { var wrapCallback = function wrapCallback(fn, isEvent) {
if (!fn.wrapper) if (!fn.wrapper)
fn.wrapper = function wrappedCallback() { fn.wrapper = function wrappedCallback() {
try { 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) { catch (e) {
util.reportError(e); util.reportError(e);