diff --git a/common/bootstrap.js b/common/bootstrap.js index 226a69ad..07169e83 100755 --- a/common/bootstrap.js +++ b/common/bootstrap.js @@ -17,7 +17,11 @@ function module(uri) { const DEBUG = true; -__defineGetter__("BOOTSTRAP", () => "resource://" + moduleName + "/bootstrap.jsm"); +Object.defineProperty(global, "BOOTSTRAP", { + get: () => "resource://" + moduleName + "/bootstrap.jsm", + enumerable: true, + configurable: true +}); var { AddonManager } = module("resource://gre/modules/AddonManager.jsm"); var { XPCOMUtils } = module("resource://gre/modules/XPCOMUtils.jsm"); diff --git a/common/content/commandline.js b/common/content/commandline.js index 3b3bce56..a55e2869 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -180,8 +180,16 @@ var CommandWidgets = Class("CommandWidgets", { return (obj.getElement || identity)(map[id] || document.getElementById(prefix + id)); } - this.active.__defineGetter__(obj.name, () => this.activeGroup[obj.name][obj.name]); - this.activeGroup.__defineGetter__(obj.name, () => this.getGroup(obj.name)); + Object.defineProperty(this.active, obj.name, { + get: () => this.activeGroup[obj.name][obj.name], + enumerable: true, + configurable: true, + }); + Object.defineProperty(this.activeGroup, obj.name, { + get: () => this.getGroup(obj.name), + enumerable: true, + configurable: true, + }); memoize(this.statusbar, obj.name, () => get("dactyl-statusline-field-", statusline.widgets, (obj.id || obj.name))); memoize(this.commandbar, obj.name, () => get("dactyl-", {}, (obj.id || obj.name))); diff --git a/common/content/editor.js b/common/content/editor.js index 5a31c878..b346a5d9 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -16,13 +16,17 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { if (elem) this.element = elem; else - this.__defineGetter__("element", () => { - let elem = dactyl.focusedElement; - if (elem) - return elem.inputField || elem; + Object.defineProperty(this, "element", { + get: () => { + let elem = dactyl.focusedElement; + if (elem) + return elem.inputField || elem; - let win = document.commandDispatcher.focusedWindow; - return DOM(win).isEditable && win || null; + let win = document.commandDispatcher.focusedWindow; + return DOM(win).isEditable && win || null; + }, + enumerable: true, + configurable: true }); }, diff --git a/common/content/hints.js b/common/content/hints.js index a0df5846..30bd0ded 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -762,9 +762,13 @@ var Hints = Module("hints", { events.listen(appContent, "scroll", this.resizeTimer.bound.tell, false); const Mode = Hints.Mode; - Mode.prototype.__defineGetter__("matcher", function () { - return options.get("extendedhinttags") - .getKey(this.name, options.get("hinttags").matcher); + Object.defineProperty(Mode.prototype, "matcher", { + get() { + return options.get("extendedhinttags") + .getKey(this.name, options.get("hinttags").matcher); + }, + enumerable: true, + configurable: true }); function cleanLoc(loc) { diff --git a/common/content/history.js b/common/content/history.js index d4ecc4d8..b254f784 100644 --- a/common/content/history.js +++ b/common/content/history.js @@ -63,8 +63,12 @@ var History = Module("history", { let sh = webNav.sessionHistory; let obj = []; - obj.__defineGetter__("index", () => sh.index); - obj.__defineSetter__("index", val => { webNav.gotoIndex(val); }); + Object.defineProperty(obj, "index", { + get: () => sh.index, + set: val => webNav.gotoIndex(val), + enumerable: true, + configurable: true + }); obj[Symbol.iterator] = function () { return this.entries(); }; for (let item of iter(sh.SHistoryEnumerator, Ci.nsISHEntry)) diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 74136b68..eef3ae1e 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -26,8 +26,7 @@ try { catch (e) {} let objproto = Object.prototype; -var { __lookupGetter__, __lookupSetter__, __defineGetter__, __defineSetter__, - hasOwnProperty, propertyIsEnumerable } = objproto; +var { hasOwnProperty, propertyIsEnumerable } = objproto; var hasOwnProp = Function.call.bind(hasOwnProperty); @@ -780,7 +779,7 @@ function memoize(obj, key, getter) { if (arguments.length == 1) { let res = update(Object.create(obj), obj); for (let prop of Object.getOwnPropertyNames(obj)) { - let get = __lookupGetter__.call(obj, prop); + let get = Object.getOwnPropertyDescriptor(obj, prop).get; if (get) memoize(res, prop, get); } @@ -847,8 +846,12 @@ function update(target) { let func = desc.value.wrapped || desc.value; if (!func.superapply) { - func.__defineGetter__("super", function get_super() { - return Object.getPrototypeOf(target)[k]; + Object.defineProperty(func, "super", { + get: function get_super() { + return Object.getPrototypeOf(target)[k]; + }, + enumerable: true, + configurable: true }); func.superapply = function superapply(self, args) { @@ -1169,7 +1172,11 @@ Class.prototype = { if (typeof desc.value === "function") { let func = desc.value.wrapped || desc.value; if (!func.superapply) { - func.__defineGetter__("super", () => Object.getPrototypeOf(this)[k]); + Object.defineProperty(func, "super", { + get: () => Object.getPrototypeOf(this)[k], + enumerable: true, + configurable: true + }); func.superapply = function superapply(self, args) { let meth = Object.getPrototypeOf(self)[k]; @@ -1403,11 +1410,15 @@ function Struct(...args) { members: Ary.toObject(args.map((v, k) => [v, k])), }); args.forEach(function (name, i) { - Struct.prototype.__defineGetter__(name, function () { - return this[i]; - }); - Struct.prototype.__defineSetter__(name, function (val) { - this[i] = val; + Object.defineProperty(Struct.prototype, name, { + get() { + return this[i]; + }, + set(val) { + this[i] = val; + }, + enumerable: true, + configurable: true }); }); return Struct; @@ -1467,11 +1478,15 @@ var StructBase = Class("StructBase", Array, { */ defaultValue: function defaultValue(key, val) { let i = this.prototype.members[key]; - this.prototype.__defineGetter__(i, function () { - return this[i] = val.call(this); - }); - this.prototype.__defineSetter__(i, function (value) { - return Class.replaceProperty(this, i, value); + Object.defineProperty(this.prototype, i, { + get() { + return this[i] = val.call(this); + }, + set(value) { + Class.replaceProperty(this, i, value); + }, + enumerable: true, + configurable: true }); return this; }, diff --git a/common/modules/bookmarkcache.jsm b/common/modules/bookmarkcache.jsm index eab3bba0..bbe3ab67 100644 --- a/common/modules/bookmarkcache.jsm +++ b/common/modules/bookmarkcache.jsm @@ -61,7 +61,13 @@ update(Bookmark.prototype, { } }); Bookmark.prototype.members.uri = Bookmark.prototype.members.url; -Bookmark.setter = function (key, func) { return this.prototype.__defineSetter__(key, func); }; +Bookmark.setter = function (key, func) { + return Object.defineProperty(this.prototype, key, { + set: func, + enumerable: true, + configurable: true + }); +}; Bookmark.setter("url", function (val) { this.uri = isString(val) ? newURI(val) : val; }); Bookmark.setter("title", function (val) { services.bookmarks.setItemTitle(this.id, val); }); Bookmark.setter("post", function (val) { bookmarkcache.annotate(this.id, bookmarkcache.POST, val); }); diff --git a/common/modules/completion.jsm b/common/modules/completion.jsm index 265e881c..aded49ce 100644 --- a/common/modules/completion.jsm +++ b/common/modules/completion.jsm @@ -62,8 +62,12 @@ var CompletionContext = Class("CompletionContext", { ["anchored", "compare", "editor", "_filter", "filterFunc", "forceAnchored", "top"] .forEach(key => self[key] = parent[key]); - self.__defineGetter__("value", function get_value() { - return this.top.value; + Object.defineProperty(self, "value", { + get() { + return this.top.value; + }, + enumerable: true, + configurable: true }); self.offset = parent.offset; @@ -90,11 +94,15 @@ var CompletionContext = Class("CompletionContext", { if (self != this) return self; ["_caret", "contextList", "maxItems", "onUpdate", "selectionTypes", "tabPressed", "updateAsync", "value"].forEach(function fe(key) { - self.__defineGetter__(key, function () { - return this.top[key]; - }); - self.__defineSetter__(key, function (val) { - this.top[key] = val; + Object.defineProperty(self, key, { + get() { + return this.top[key]; + }, + set(val) { + this.top[key] = val; + }, + enumerable: true, + configurable: true }); }); } @@ -175,19 +183,29 @@ var CompletionContext = Class("CompletionContext", { * @property {CompletionContext} The top-level completion context. */ this.top = this; - this.__defineGetter__("incomplete", function get_incomplete() { - return this._incomplete || - this.contextList.some(c => c.parent && c.incomplete); - }); - this.__defineGetter__("waitingForTab", function get_waitingForTab() { - return this._waitingForTab || - this.contextList.some(c => c.parent && c.waitingForTab); - }); - this.__defineSetter__("incomplete", function get_incomplete(val) { - this._incomplete = val; - }); - this.__defineSetter__("waitingForTab", function get_waitingForTab(val) { - this._waitingForTab = val; + Object.defineProperties(this, { + "incomplete": { + get() { + return this._incomplete || + this.contextList.some(c => c.parent && c.incomplete); + }, + set(val) { + this._incomplete = val; + }, + enumerable: true, + configurable: true + }, + "waitingForTab": { + get() { + return this._waitingForTab || + this.contextList.some(c => c.parent && c.waitingForTab); + }, + set(val) { + this._waitingForTab = val; + }, + enumerable: true, + configurable: true + } }); this.reset(); } @@ -432,17 +450,22 @@ var CompletionContext = Class("CompletionContext", { // This is only allowed to be a simple accessor, and shouldn't // reference any variables. Don't bother with eval context. v = Function("i", "return i" + v); + let descriptor = { + enumerable: true, + configurable: true + }; if (typeof v == "function") - res.__defineGetter__(k, function p_gf() { + descriptor.get = function p_gf() { return Class.replaceProperty(this, k, v.call(this, this.item, self)); - }); + }; else - res.__defineGetter__(k, function p_gp() { + descriptor.get = function p_gp() { return Class.replaceProperty(this, k, this.item[v]); - }); - res.__defineSetter__(k, function p_s(val) { + }; + descriptor.set = function p_s(val) { Class.replaceProperty(this, k, val); - }); + }; + Object.defineProperty(res, k, descriptor); } return res; }, @@ -811,8 +834,12 @@ var CompletionContext = Class("CompletionContext", { split: function split(name, obj, fn, ...args) { let context = this.fork(name); let alias = prop => { - context.__defineGetter__(prop, () => this[prop]); - context.__defineSetter__(prop, val => this[prop] = val); + Object.defineProperty(context, prop, { + get: () => this[prop], + set: val => this[prop] = val, + enumerable: true, + configurable: true, + }); }; alias("_cache"); alias("_completions"); diff --git a/common/modules/contexts.jsm b/common/modules/contexts.jsm index 2a10a481..66e180be 100644 --- a/common/modules/contexts.jsm +++ b/common/modules/contexts.jsm @@ -459,8 +459,12 @@ var Contexts = Module("contexts", { group = this.Group(name, description, filter, persist); this.groupList.unshift(group); this.groupMap[name] = group; - this.hiveProto.__defineGetter__(name, function () { - return group[this._hive]; + Object.defineProperty(this.hiveProto, name, { + get() { + return group[this._hive]; + }, + enumerable: true, + configurable: true }); } diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index 882dac4c..a9bc9834 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -17,27 +17,31 @@ var Highlight = Struct("class", "selector", "sites", "value", "extends", "agent", "base", "baseClass", "style"); Highlight.liveProperty = function (name, prop) { - this.prototype.__defineGetter__(name, function () { - return this.get(name); - }); - this.prototype.__defineSetter__(name, function (val) { - if (isObject(val) && name !== "style") { - if (isArray(val)) - val = Array.slice(val); - else - val = update({}, val); - Object.freeze(val); - } - this.set(name, val); + Object.defineProperty(this.prototype, name, { + get() { + return this.get(name); + }, + set(val) { + if (isObject(val) && name !== "style") { + if (isArray(val)) + val = Array.slice(val); + else + val = update({}, val); + Object.freeze(val); + } + this.set(name, val); - if (name === "value" || name === "extends") - for (let h of highlight) - if (h.extends.indexOf(this.class) >= 0) - h.style.css = h.css; + if (name === "value" || name === "extends") + for (let h of highlight) + if (h.extends.indexOf(this.class) >= 0) + h.style.css = h.css; - this.style[prop || name] = this[prop || name]; - if (this.onChange) - this.onChange(); + this.style[prop || name] = this[prop || name]; + if (this.onChange) + this.onChange(); + }, + enumerable: true, + configurable: true, }); }; Highlight.liveProperty("agent"); @@ -155,19 +159,23 @@ var Highlights = Module("Highlight", { if (!old && obj.base && obj.base.style.enabled) obj.style.enabled = true; else - this.loaded.__defineSetter__(obj.class, function () { - Object.defineProperty(this, obj.class, { - value: true, - configurable: true, - enumerable: true, - writable: true - }); + Object.defineProperty(this.loaded, obj.class, { + set() { + Object.defineProperty(this, obj.class, { + value: true, + configurable: true, + enumerable: true, + writable: true + }); - if (obj.class === obj.baseClass) - for (let h of highlight) - if (h.baseClass === obj.class) - this[h.class] = true; - obj.style.enabled = true; + if (obj.class === obj.baseClass) + for (let h of highlight) + if (h.baseClass === obj.class) + this[h.class] = true; + obj.style.enabled = true; + }, + enumerable: true, + configurable: true }); return obj; }, diff --git a/common/modules/io.jsm b/common/modules/io.jsm index 353fde59..8eeb5231 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -886,8 +886,11 @@ unlet s:cpo_save sep = sep || " "; let width = 0; let lines = []; - lines.__defineGetter__("last", function () { - return this[this.length - 1]; + Object.defineProperty(lines, "last", { + get() { + return this[this.length - 1]; + }, + configurable: true }); for (let item of values(items.array || items)) { diff --git a/common/modules/main.jsm b/common/modules/main.jsm index 2b6ae6ee..f4e6994f 100644 --- a/common/modules/main.jsm +++ b/common/modules/main.jsm @@ -253,15 +253,19 @@ overlay.overlayWindow(Object.keys(config.overlays), this.initDependencies(className); } else - modules.__defineGetter__(className, () => { - let module = modules.jsmodules[className]; - Class.replaceProperty(modules, className, module); - if (module.reallyInit) - module.reallyInit(); // :( + Object.defineProperty(modules, className, { + get: () => { + let module = modules.jsmodules[className]; + Class.replaceProperty(modules, className, module); + if (module.reallyInit) + module.reallyInit(); // :( - if (!module.lazyDepends) - self.initDependencies(className); - return module; + if (!module.lazyDepends) + this.initDependencies(className); + return module; + }, + enumerable: true, + configurable: true, }); }, this); }, @@ -380,9 +384,12 @@ overlay.overlayWindow(Object.keys(config.overlays), Module.list.forEach(mod => { if (!mod.frobbed) { - modules.__defineGetter__(mod.className, () => { - delete modules[mod.className]; - return this.loadModule(mod.className, null, Components.stack.caller); + Object.defineProperty(modules, mod.className, { + get: () => { + return this.loadModule(mod.className, null, Components.stack.caller); + }, + enumerable: true, + configurable: true }); Object.keys(mod.prototype.INIT) .forEach(name => { this.deferInit(name, mod.prototype.INIT, mod); }); diff --git a/common/modules/options.jsm b/common/modules/options.jsm index 872201db..daa240f2 100644 --- a/common/modules/options.jsm +++ b/common/modules/options.jsm @@ -1060,11 +1060,15 @@ var Options = Module("options", { memoize(this._options, this._options.length, closure); // quickly access options with options["wildmode"]: - this.__defineGetter__(name, function () { - return this._optionMap[name].value; - }); - this.__defineSetter__(name, function (value) { - this._optionMap[name].value = value; + Object.defineProperty(this, name, { + get() { + return this._optionMap[name].value; + }, + set(value) { + this._optionMap[name].value = value; + }, + enumerable: true, + configurable: true }); } }; diff --git a/common/modules/services.jsm b/common/modules/services.jsm index abf17f33..5d68935f 100644 --- a/common/modules/services.jsm +++ b/common/modules/services.jsm @@ -160,7 +160,7 @@ var Services = Module("Services", { add: function add(name, class_, ifaces, meth) { const self = this; this.services[name] = { method: meth, class: class_, interfaces: Array.concat(ifaces || []) }; - if (name in this && ifaces && !this.__lookupGetter__(name) && !(this[name] instanceof Ci.nsISupports)) + if (name in this && ifaces && !Object.getOwnPropertyDescriptor(this, name).get && !(this[name] instanceof Ci.nsISupports)) throw TypeError(); memoize(this, name, () => self._create(name)); }, diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index 7f3bafeb..d9f6d166 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -31,8 +31,20 @@ var StoreBase = Class("StoreBase", { this._load = load; this._options = options; - this.__defineGetter__("store", () => store); - this.__defineGetter__("name", () => name); + Object.defineProperties(this, { + "store": { + value: store, + writable: false, + enumerable: true, + configurable: true, + }, + "name": { + value: name, + writable: false, + enumerable: true, + configurable: true, + } + }); for (let [k, v] of iter(options)) if (this.OPTIONS.indexOf(k) >= 0) this[k] = v; @@ -301,8 +313,12 @@ var Storage = Module("Storage", { this.keys[key] = new constructor(key, params.store, load, params); this.keys[key].timer = new Timer(1000, 10000, () => this.save(key)); - this.__defineGetter__(key, function () { - return this.keys[key]; + Object.defineProperty(this, key, { + get() { + return this.keys[key]; + }, + enumerable: true, + configurable: true, }); } return this.keys[key]; diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 5383cabc..5d13cda9 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -19,14 +19,20 @@ var namespace = "@namespace html " + JSON.stringify(XHTML) + ";\n" + var Sheet = Struct("name", "id", "sites", "css", "hive", "agent"); Sheet.liveProperty = function (name) { let i = this.prototype.members[name]; - this.prototype.__defineGetter__(name, function () { return this[i]; }); - this.prototype.__defineSetter__(name, function (val) { - if (isArray(val)) - val = Array.slice(val); - if (isArray(val)) - Object.freeze(val); - this[i] = val; - this.enabled = this.enabled; + Object.defineProperty(this.prototype, name, { + get() { + return this[i]; + }, + set(val) { + if (isArray(val)) + val = Array.slice(val); + if (isArray(val)) + Object.freeze(val); + this[i] = val; + this.enabled = this.enabled; + }, + enumerable: true, + configurable: true }); }; Sheet.liveProperty("agent"); diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 5c2bb3e8..4bae6d54 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -283,8 +283,11 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), compileFormat: function compileFormat(format) { let stack = [frame()]; - stack.__defineGetter__("top", function () { - return this[this.length - 1]; + Object.defineProperty(stack, "top", { + get() { + return this[this.length - 1]; + }, + configurable: true }); function frame() { @@ -370,8 +373,11 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), */ compileMacro: function compileMacro(macro, keepUnknown) { let stack = [frame()]; - stack.__defineGetter__("top", function () { - return this[this.length - 1]; + Object.defineProperty(stack, "top", { + get() { + return this[this.length - 1]; + }, + configurable: true, }); let unknown = identity; diff --git a/common/tests/functional/shared-modules/private-browsing.js b/common/tests/functional/shared-modules/private-browsing.js index 12344d6b..704f39db 100644 --- a/common/tests/functional/shared-modules/private-browsing.js +++ b/common/tests/functional/shared-modules/private-browsing.js @@ -69,10 +69,13 @@ function privateBrowsing(controller) { this._pbMenuItem = new elementslib.Elem(this._controller.menus['tools-menu'].privateBrowsingItem); this._pbTransitionItem = new elementslib.ID(this._controller.window.document, "Tools:PrivateBrowsing"); - this.__defineGetter__('_pbs', function() { - delete this._pbs; - return this._pbs = Cc["@mozilla.org/privatebrowsing;1"]. - getService(Ci.nsIPrivateBrowsingService); + Object.defineProperty(this, '_pbs', { + enumerable: true, + configurable: true, + get() { + return Cc["@mozilla.org/privatebrowsing;1"]. + getService(Ci.nsIPrivateBrowsingService); + } }); } diff --git a/plugins/useragent.js b/plugins/useragent.js index ec5793d8..284e9cad 100755 --- a/plugins/useragent.js +++ b/plugins/useragent.js @@ -62,9 +62,13 @@ let init = function init_() { UserAgent = Struct("name", "useragent", "appname", "appcodename", "appversion", "platform", "vendor", "vendorsub", "userset"); - UserAgent.prototype.__defineGetter__("options", function () { - return opts.slice(1).map(opt => [opt.name, this[opt.name]]) - .filter(opt => opt[1]); + Object.defineProperty(UserAgent.prototype, "options", { + get() { + return opts.slice(1).map(opt => [opt.name, this[opt.name]]) + .filter(opt => opt[1]); + }, + enumerable: true, + configurable: true }); useragents = array([ diff --git a/plugins/xpcom.js b/plugins/xpcom.js index 058b0ecd..fcd8b157 100755 --- a/plugins/xpcom.js +++ b/plugins/xpcom.js @@ -98,16 +98,20 @@ userContext.xpwrapper = function xpwrapper(obj, iface) { try { let shim = XPCOMShim([iface]); iter.forEach(properties(shim), function (prop) { - res.__defineGetter__(prop, function () { - let res = obj.QueryInterface(Ci[iface])[prop]; - if (callable(res)) { - let fn = (...args) => res.apply(obj, args); - fn.toString = () => res.toString(); - fn.toSource = () => res.toSource(); - return fn; - } - return res; - }) + Object.defineProperty(res, prop, { + get() { + let res = obj.QueryInterface(Ci[iface])[prop]; + if (callable(res)) { + let fn = (...args) => res.apply(obj, args); + fn.toString = () => res.toString(); + fn.toSource = () => res.toSource(); + return fn; + } + return res; + }, + enumerable: true, + configurable: true + }); }); } catch (e if e === Cr.NS_ERROR_NO_INTERFACE) { @@ -146,7 +150,11 @@ memoize(userContext, "xpclasses", function () { return userContext.xpwrapper(cls); } Object.keys(Cc).forEach(function (k) { - xpclasses.__defineGetter__(k, () => xpclasses(k)); + Object.defineProperty(xpclasses, k, { + get: () => xpclasses(k), + enumerable: true, + configurable: true + }); }); JavaScript.setCompleter([xpclasses], Completer(Cc)); return xpclasses; @@ -179,7 +187,11 @@ memoize(userContext, "xpservices", function () { return userContext.xpwrapper(cls); } Object.keys(Cc).forEach(function (k) { - xpservices.__defineGetter__(k, () => xpservices(k)); + Object.defineProperty(xpservices, k, { + get: () => xpservices(k), + enumerable: true, + configurable: true + }); }); JavaScript.setCompleter([xpservices], Completer(Cc)); return xpservices;