mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 15:57:57 +01:00
Use Object.keys/getOwnPropertyNames (and provide them if they don't exist).
This commit is contained in:
@@ -167,7 +167,7 @@ const AutoCommands = Module("autocommands", {
|
|||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
// NOTE: event can only be a comma separated list for |:au {event} {pat} {cmd}|
|
// NOTE: event can only be a comma separated list for |:au {event} {pat} {cmd}|
|
||||||
let validEvents = keys(config.autocommands);
|
let validEvents = Object.keys(config.autocommands);
|
||||||
validEvents.push("*");
|
validEvents.push("*");
|
||||||
|
|
||||||
events = event.split(",");
|
events = event.split(",");
|
||||||
@@ -227,7 +227,7 @@ const AutoCommands = Module("autocommands", {
|
|||||||
|
|
||||||
let [event, url] = args;
|
let [event, url] = args;
|
||||||
let defaultURL = url || buffer.URL;
|
let defaultURL = url || buffer.URL;
|
||||||
let validEvents = keys(config.autocommands);
|
let validEvents = Object.keys(config.autocommands);
|
||||||
|
|
||||||
// TODO: add command validators
|
// TODO: add command validators
|
||||||
dactyl.assert(event != "*",
|
dactyl.assert(event != "*",
|
||||||
|
|||||||
@@ -44,30 +44,34 @@ function allkeys(obj) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function keys(obj) {
|
function debuggerProperties(obj) {
|
||||||
if (modules.services) {
|
if (modules.services && options["jsdebugger"]) {
|
||||||
try {
|
let ret = {};
|
||||||
let ret = {};
|
services.get("debugger").wrapValue(obj).getProperties(ret, {});
|
||||||
services.get("debugger").wrapValue(obj).getProperties(ret, {});
|
return ret.value;
|
||||||
for (let prop in values(ret.value))
|
}
|
||||||
yield prop.name.stringValue;
|
}
|
||||||
return;
|
|
||||||
}
|
if (!Object.keys)
|
||||||
catch (e) {}
|
Object.keys = function keys(obj) [k for (k in obj) if (obj.hasOwnProperty(k))];
|
||||||
|
|
||||||
|
if (!Object.getOwnPropertyNames)
|
||||||
|
Object.getOwnPropertyNames = function getOwnPropertyNames(obj) {
|
||||||
|
let res = debuggerProperties(obj);
|
||||||
|
if (res)
|
||||||
|
return [prop.name.stringValue for (prop in values(res))];
|
||||||
|
return Object.keys(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("__iterator__" in obj) {
|
function properties(obj, prototypes) {
|
||||||
var iter = obj.__iterator__;
|
let orig = obj;
|
||||||
yield "__iterator__";
|
let seen = {};
|
||||||
// This is dangerous, but necessary.
|
for (; obj; obj = prototypes && obj.__proto__)
|
||||||
delete obj.__iterator__;
|
for (let key in values(Object.getOwnPropertyNames(obj)))
|
||||||
}
|
if (!prototypes || !set.add(seen, key) && obj != orig)
|
||||||
for (var k in obj)
|
yield key
|
||||||
if (obj.hasOwnProperty(k))
|
|
||||||
yield k;
|
|
||||||
if (iter !== undefined)
|
|
||||||
obj.__iterator__ = iter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function values(obj) {
|
function values(obj) {
|
||||||
for (var k in obj)
|
for (var k in obj)
|
||||||
if (obj.hasOwnProperty(k))
|
if (obj.hasOwnProperty(k))
|
||||||
@@ -273,7 +277,7 @@ function curry(fn, length, self, acc) {
|
|||||||
function update(target) {
|
function update(target) {
|
||||||
for (let i = 1; i < arguments.length; i++) {
|
for (let i = 1; i < arguments.length; i++) {
|
||||||
let src = arguments[i];
|
let src = arguments[i];
|
||||||
foreach(keys(src || {}), function (k) {
|
Object.getOwnPropertyNames(src || {}).forEach(function (k) {
|
||||||
var get = src.__lookupGetter__(k),
|
var get = src.__lookupGetter__(k),
|
||||||
set = src.__lookupSetter__(k);
|
set = src.__lookupSetter__(k);
|
||||||
if (!get && !set) {
|
if (!get && !set) {
|
||||||
|
|||||||
@@ -26,74 +26,39 @@ const JavaScript = Module("javascript", {
|
|||||||
// Some object members are only accessible as function calls
|
// Some object members are only accessible as function calls
|
||||||
getKey: function (obj, key) {
|
getKey: function (obj, key) {
|
||||||
try {
|
try {
|
||||||
|
// if (!Object.prototype.__lookupGetter__.call(obj, key))
|
||||||
return obj[key];
|
return obj[key];
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
iter: function iter(obj, toplevel) {
|
iter: function iter(obj, toplevel) {
|
||||||
"use strict";
|
"use strict";
|
||||||
toplevel = !!toplevel;
|
const self = this;
|
||||||
let seen = {};
|
|
||||||
let ret = {};
|
|
||||||
|
|
||||||
if(obj == null)
|
if(obj == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(options["jsdebugger"]) {
|
let orig = obj;
|
||||||
let orig = obj;
|
if(!options["jsdebugger"])
|
||||||
let top = services.get("debugger").wrapValue(obj);
|
function value(key) self.getKey(orig, key);
|
||||||
|
|
||||||
for (; obj; obj = !toplevel && obj.__proto__) {
|
|
||||||
services.get("debugger").wrapValue(obj).getProperties(ret, {});
|
|
||||||
for (let prop in values(ret.value)) {
|
|
||||||
if (set.add(seen, prop.name.stringValue))
|
|
||||||
continue;
|
|
||||||
if (toplevel || obj !== orig)
|
|
||||||
yield [prop.name.stringValue, top.getProperty(prop.name.stringValue).value.getWrappedValue()]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// The debugger doesn't list some properties. I can't guess why.
|
|
||||||
// This only lists ENUMERABLE properties.
|
|
||||||
try {
|
|
||||||
for (let k in orig)
|
|
||||||
if (k in orig && !(set.has(seen, k))
|
|
||||||
&& Object.hasOwnProperty(orig, k) == toplevel)
|
|
||||||
yield [k, this.getKey(orig, k)]
|
|
||||||
}
|
|
||||||
catch(e) {}
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
for (let k in allkeys(obj))
|
let top = services.get("debugger").wrapValue(obj);
|
||||||
try {
|
function value(key) top.getProperty(key).value.getWrappedValue();
|
||||||
if (Object.hasOwnProperty(obj, k) == toplevel)
|
|
||||||
yield [k, this.getKey(obj, k)];
|
|
||||||
}
|
|
||||||
catch (e) {}
|
|
||||||
}
|
}
|
||||||
|
for (let key in properties(obj, !toplevel))
|
||||||
|
yield [key, value(key)];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Search the object for strings starting with @key.
|
|
||||||
// If @last is defined, key is a quoted string, it's
|
|
||||||
// wrapped in @last after @offset characters are sliced
|
|
||||||
// off of it and it's quoted.
|
|
||||||
objectKeys: function objectKeys(obj, toplevel) {
|
objectKeys: function objectKeys(obj, toplevel) {
|
||||||
// Things we can dereference
|
// Things we can dereference
|
||||||
if (["object", "string", "function"].indexOf(typeof obj) == -1)
|
if (!obj || ["object", "string", "function"].indexOf(typeof obj) == -1)
|
||||||
return [];
|
return [];
|
||||||
if (!obj)
|
if (modules.isPrototypeOf(obj) && !toplevel)
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
let completions;
|
let completions = [k for (k in this.iter(obj, toplevel))];
|
||||||
if (modules.isPrototypeOf(obj))
|
|
||||||
completions = [v for (v in Iterator(obj))];
|
|
||||||
else {
|
|
||||||
completions = [k for (k in this.iter(obj, toplevel))];
|
|
||||||
if (!toplevel)
|
|
||||||
completions = util.Array.uniq(completions, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add keys for sorting later.
|
// Add keys for sorting later.
|
||||||
// Numbers are parsed to ints.
|
// Numbers are parsed to ints.
|
||||||
@@ -124,6 +89,7 @@ const JavaScript = Module("javascript", {
|
|||||||
return cache[key] = dactyl.eval(arg, context);
|
return cache[key] = dactyl.eval(arg, context);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
this.context.message = "Error: " + e;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ const Modes = Module("modes", {
|
|||||||
|
|
||||||
getCharModes: function (chr) [m for (m in values(this._modeMap)) if (m.char == chr)],
|
getCharModes: function (chr) [m for (m in values(this._modeMap)) if (m.char == chr)],
|
||||||
|
|
||||||
matchModes: function (obj) [m for (m in values(this._modeMap)) if (array(keys(obj)).every(function (k) obj[k] == (m[k] || false)))],
|
matchModes: function (obj) [m for (m in values(this._modeMap)) if (Object.keys(obj).every(function (k) obj[k] == (m[k] || false)))],
|
||||||
|
|
||||||
// show the current mode string in the command line
|
// show the current mode string in the command line
|
||||||
show: function () {
|
show: function () {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ window.addEventListener("load", function () {
|
|||||||
dactyl.reportError(e);
|
dactyl.reportError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let mod in keys(module.INIT)) {
|
for (let mod in values(Object.keys(module.INIT))) {
|
||||||
deferredInit[mod] = deferredInit[mod] || [];
|
deferredInit[mod] = deferredInit[mod] || [];
|
||||||
deferredInit[mod].push(init(mod, module));
|
deferredInit[mod].push(init(mod, module));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user