1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 18:27:57 +01:00

Some minor fixes, and add ctypes support to iter().

--HG--
branch : mode-refactoring
This commit is contained in:
Kris Maglione
2010-10-07 23:18:09 -04:00
parent 76e331afea
commit 248c906e9c
4 changed files with 45 additions and 23 deletions

View File

@@ -25,16 +25,16 @@ const FailedAssertion = Class("FailedAssertion", Error, {
} }
}); });
deprecated.seen = { "chrome://dactyl/content/javascript.js": true }; function deprecated(reason, fn) update(
function deprecated(reason, fn)
function deprecatedMethod() { function deprecatedMethod() {
let frame = Components.stack.caller; let frame = Components.stack.caller;
if (!set.add(deprecated.seen, frame.filename)) if (!set.add(deprecatedMethod.seen, frame.filename))
dactyl.echoerr(frame.filename + ":" + frame.lineNumber + ": " + dactyl.echoerr(frame.filename + ":" + frame.lineNumber + ": " +
(this.className || this.constructor.className) + "." + fn.name + (this.className || this.constructor.className) + "." + fn.name +
" is deprecated: " + reason); " is deprecated: " + reason);
return fn.apply(this, arguments); return fn.apply(this, arguments);
} },
{ seen: { "chrome://dactyl/content/javascript.js": true } });
const Dactyl = Module("dactyl", { const Dactyl = Module("dactyl", {
init: function () { init: function () {

View File

@@ -345,13 +345,15 @@ lookup:
dactyl.helpInitialized = false; dactyl.helpInitialized = false;
} }
catch (e) { catch (e) {
if (isString(e)) if (e.fileName)
e = { message: e }; try {
let err = new Error(); e.fileName = e.fileName.replace(/^(chrome|resource):.*? -> /, "");
for (let [k, v] in Iterator(e)) if (e.fileName == uri.spec)
err[k] = v; e.fileName = filename;
err.echoerr = <>{file.path}:{e.lineNumber}: {e}</>; e.echoerr = <>{e.fileName}:{e.lineNumber}: {e}</>
throw err; }
catch (e) {}
throw e;
} }
} }
else if (/\.css$/.test(filename)) else if (/\.css$/.test(filename))

View File

@@ -358,8 +358,6 @@ const JavaScript = Module("javascript", {
} }
let args = { let args = {
completer: compl,
anchored: true,
filter: last == null ? key : string, filter: last == null ? key : string,
last: last, last: last,
prefix: last != null ? key : "" prefix: last != null ? key : ""
@@ -369,39 +367,42 @@ const JavaScript = Module("javascript", {
// TODO: Make this a generic completion helper function. // TODO: Make this a generic completion helper function.
for (let [, obj] in Iterator(objects)) for (let [, obj] in Iterator(objects))
this.context.fork(obj[1], this._top.offset, this, this._fill, this.context.fork(obj[1], this._top.offset, this, this._fill,
update({}, args, { update({
obj: obj[0], obj: obj[0],
name: obj[1] name: obj[1],
})); anchored: true,
completer: compl
}, args));
if (orig) if (orig)
return; return;
for (let [, obj] in Iterator(objects)) for (let [, obj] in Iterator(objects))
this.context.fork(obj[1] + "/prototypes", this._top.offset, this, this._fill, this.context.fork(obj[1] + "/prototypes", this._top.offset, this, this._fill,
update({}, args, { update({
obj: obj[0], obj: obj[0],
name: obj[1] + " (prototypes)", name: obj[1] + " (prototypes)",
anchored: true,
completer: function (a, b) compl(a, b, true) completer: function (a, b) compl(a, b, true)
})); }, args));
for (let [, obj] in Iterator(objects)) for (let [, obj] in Iterator(objects))
this.context.fork(obj[1] + "/substrings", this._top.offset, this, this._fill, this.context.fork(obj[1] + "/substrings", this._top.offset, this, this._fill,
update({}, args, { update({
obj: obj[0], obj: obj[0],
name: obj[1] + " (substrings)", name: obj[1] + " (substrings)",
anchored: false, anchored: false,
completer: compl completer: compl
})); }, args));
for (let [, obj] in Iterator(objects)) for (let [, obj] in Iterator(objects))
this.context.fork(obj[1] + "/prototypes/substrings", this._top.offset, this, this._fill, this.context.fork(obj[1] + "/prototypes/substrings", this._top.offset, this, this._fill,
update({}, args, { update({
obj: obj[0], obj: obj[0],
name: obj[1] + " (prototype substrings)", name: obj[1] + " (prototype substrings)",
anchored: false, anchored: false,
completer: function (a, b) compl(a, b, true) completer: function (a, b) compl(a, b, true)
})); }, args));
}, },
_getKey: function () { _getKey: function () {

View File

@@ -10,6 +10,11 @@ const Cr = Components.results;
const Cu = Components.utils; const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
try {
var ctypes;
Components.utils.import("resource://gre/modules/ctypes.jsm");
}
catch (e) {}
let objproto = Object.prototype; let objproto = Object.prototype;
let hasOwnProperty = objproto.hasOwnProperty; let hasOwnProperty = objproto.hasOwnProperty;
@@ -149,7 +154,7 @@ defineModule("base", {
exports: [ exports: [
"Cc", "Ci", "Class", "Cr", "Cu", "Module", "Object", "Runnable", "Cc", "Ci", "Class", "Cr", "Cu", "Module", "Object", "Runnable",
"Struct", "StructBase", "Timer", "UTF8", "XPCOM", "XPCOMUtils", "array", "Struct", "StructBase", "Timer", "UTF8", "XPCOM", "XPCOMUtils", "array",
"call", "callable", "curry", "debuggerProperties", "defineModule", "call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule",
"endModule", "forEach", "isArray", "isGenerator", "isinstance", "endModule", "forEach", "isArray", "isGenerator", "isinstance",
"isObject", "isString", "isSubclass", "iter", "iterAll", "keys", "isObject", "isString", "isSubclass", "iter", "iterAll", "keys",
"memoize", "properties", "requiresMainThread", "set", "update", "values" "memoize", "properties", "requiresMainThread", "set", "update", "values"
@@ -356,6 +361,20 @@ set.remove = function (set, key) {
* @returns {Generator} * @returns {Generator}
*/ */
function iter(obj) { function iter(obj) {
if (ctypes && obj instanceof ctypes.CData) {
while (obj.constructor instanceof ctypes.PointerType)
obj = obj.contents;
if (obj.constructor instanceof ctypes.ArrayType)
return array.iterItems(obj);
if (obj.constructor instanceof ctypes.StructType)
return (function () {
for (let prop in values(obj.constructor.fields))
let ([name, type] = Iterator(prop).next()) {
yield [name, obj[name]];
}
})();
obj = {};
}
if (isinstance(obj, [Ci.nsIDOMHTMLCollection, Ci.nsIDOMNodeList])) if (isinstance(obj, [Ci.nsIDOMHTMLCollection, Ci.nsIDOMNodeList]))
return array.iterItems(obj); return array.iterItems(obj);
if (obj instanceof Ci.nsIDOMNamedNodeMap) if (obj instanceof Ci.nsIDOMNamedNodeMap)