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

Use the debugger for object property completion.

This commit is contained in:
Kris Maglione
2009-11-11 07:53:47 -05:00
parent f8ddb3e9c3
commit ee91adc5ad
4 changed files with 29 additions and 17 deletions

View File

@@ -29,7 +29,23 @@ function array(obj) {
return util.Array(obj); return util.Array(obj);
} }
function allkeys(obj) {
let ret = {};
for (; obj; obj = obj.__proto__) {
services.get("debugger").wrapValue(obj).getProperties(ret, {});
for (let prop in values(ret.value))
yield prop.name.stringValue;
}
}
function keys(obj) { function keys(obj) {
if (modules.services) {
let ret = {};
services.get("debugger").wrapValue(obj).getProperties(ret, {});
for (let prop in values(ret.value))
yield prop.name.stringValue;
return;
}
if ('__iterator__' in obj) { if ('__iterator__' in obj) {
var iter = obj.__iterator__; var iter = obj.__iterator__;
yield '__iterator__'; yield '__iterator__';

View File

@@ -783,24 +783,18 @@ const Completion = Module("completion", {
} }
this.iter = function iter(obj) { this.iter = function iter(obj) {
let iterator = ([k, getKey(obj, k)] for (k in obj)); let seen = {};
try { let ret = {};
// The point of 'for k in obj' is to get keys for (; obj; obj = obj.__proto__) {
// that are accessible via . or [] notation. services.get("debugger").wrapValue(obj).getProperties(ret, {});
// Iterators quite often return values of no for (let prop in values(ret.value)) {
// use whatsoever for this purpose, so, we try let name = '|' + prop.name.stringValue;
// this rather dirty hack of getting a standard if (name in seen)
// object iterator for any object that defines its continue;
// own. seen[name] = 1;
if ("__iterator__" in obj) { yield [prop.name.stringValue, prop.value.getWrappedValue()]
let oldIter = obj.__iterator__;
delete obj.__iterator__;
iterator = Iterator(obj);
obj.__iterator__ = oldIter;
} }
} }
catch (e) {}
return iterator;
}; };
// Search the object for strings starting with @key. // Search the object for strings starting with @key.
@@ -829,6 +823,7 @@ const Completion = Module("completion", {
// objects are problematic, to say the least. // objects are problematic, to say the least.
compl = [v for (v in this.iter(obj)) compl = [v for (v in this.iter(obj))
if (v && (typeof orig == "object" && v[0] in orig || getKey(orig, v[0]) !== undefined))]; if (v && (typeof orig == "object" && v[0] in orig || getKey(orig, v[0]) !== undefined))];
compl = util.Array.uniq(compl, true);
} }
// And if wrappedJSObject happens to be available, // And if wrappedJSObject happens to be available,

View File

@@ -61,7 +61,7 @@ window.addEventListener("load", function () {
fn(); fn();
} }
catch (e) { catch (e) {
dump("Loading " + (module && module.name) + ": " + e); dump("Loading " + (module && module.name) + ": " + e + "\n");
if (e.stack) if (e.stack)
dump(e.stack); dump(e.stack);
} }

View File

@@ -22,6 +22,7 @@ const Services = Module("services", {
this.add("cache", "@mozilla.org/network/cache-service;1", Ci.nsICacheService); this.add("cache", "@mozilla.org/network/cache-service;1", Ci.nsICacheService);
this.add("console", "@mozilla.org/consoleservice;1", Ci.nsIConsoleService); this.add("console", "@mozilla.org/consoleservice;1", Ci.nsIConsoleService);
this.add("liberator:", "@mozilla.org/network/protocol;1?name=liberator"); this.add("liberator:", "@mozilla.org/network/protocol;1?name=liberator");
this.add("debugger", "@mozilla.org/js/jsd/debugger-service;1", Ci.jsdIDebuggerService);
this.add("directory", "@mozilla.org/file/directory_service;1", Ci.nsIProperties); this.add("directory", "@mozilla.org/file/directory_service;1", Ci.nsIProperties);
this.add("downloadManager", "@mozilla.org/download-manager;1", Ci.nsIDownloadManager); this.add("downloadManager", "@mozilla.org/download-manager;1", Ci.nsIDownloadManager);
this.add("environment", "@mozilla.org/process/environment;1", Ci.nsIEnvironment); this.add("environment", "@mozilla.org/process/environment;1", Ci.nsIEnvironment);