Bug 982099 - Properly extend Array in PlacesTransaction.jsm. r=standard8
MozReview-Commit-ID: 1gQfVgDVcVm
--- a/toolkit/components/places/PlacesTransactions.jsm
+++ b/toolkit/components/places/PlacesTransactions.jsm
@@ -187,79 +187,80 @@ XPCOMUtils.defineLazyModuleGetter(this,
Cu.importGlobalProperties(["URL"]);
function setTimeout(callback, ms) {
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(callback, ms, timer.TYPE_ONE_SHOT);
}
-var TransactionsHistory = [];
-TransactionsHistory.__proto__ = {
- __proto__: Array.prototype,
+class TransactionsHistoryArray extends Array {
+ constructor() {
+ super();
- // The index of the first undo entry (if any) - See the documentation
- // at the top of this file.
- _undoPosition: 0,
+ // The index of the first undo entry (if any) - See the documentation
+ // at the top of this file.
+ this._undoPosition = 0;
+ // Outside of this module, the API of transactions is inaccessible, and so
+ // are any internal properties. To achieve that, transactions are proxified
+ // in their constructors. This maps the proxies to their respective raw
+ // objects.
+ this.proxifiedToRaw = new WeakMap();
+ }
+
get undoPosition() {
return this._undoPosition;
- },
+ }
// Handy shortcuts
get topUndoEntry() {
return this.undoPosition < this.length ? this[this.undoPosition] : null;
- },
+ }
get topRedoEntry() {
return this.undoPosition > 0 ? this[this.undoPosition - 1] : null;
- },
-
- // Outside of this module, the API of transactions is inaccessible, and so
- // are any internal properties. To achieve that, transactions are proxified
- // in their constructors. This maps the proxies to their respective raw
- // objects.
- proxifiedToRaw: new WeakMap(),
+ }
/**
* Proxify a transaction object for consumers.
* @param rawTransaction
* the raw transaction object.
* @return the proxified transaction object.
* @see getRawTransaction for retrieving the raw transaction.
*/
proxifyTransaction(rawTransaction) {
let proxy = Object.freeze({
transact() {
return TransactionsManager.transact(this);
}
});
this.proxifiedToRaw.set(proxy, rawTransaction);
return proxy;
- },
+ }
/**
* Check if the given object is a the proxy object for some transaction.
* @param aValue
* any JS value.
* @return true if aValue is the proxy object for some transaction, false
* otherwise.
*/
isProxifiedTransactionObject(value) {
return this.proxifiedToRaw.has(value);
- },
+ }
/**
* Get the raw transaction for the given proxy.
* @param aProxy
* the proxy object
* @return the transaction proxified by aProxy; |undefined| is returned if
* aProxy is not a proxified transaction.
*/
getRawTransaction(proxy) {
return this.proxifiedToRaw.get(proxy);
- },
+ }
/**
* Add a transaction either as a new entry, if forced or if there are no undo
* entries, or to the top undo entry.
*
* @param aProxifiedTransaction
* the proxified transaction object to be added to the transaction
* history.
@@ -273,47 +274,49 @@ TransactionsHistory.__proto__ = {
throw new Error("aProxifiedTransaction is not a proxified transaction");
if (this.length == 0 || forceNewEntry) {
this.clearRedoEntries();
this.unshift([proxifiedTransaction]);
} else {
this[this.undoPosition].unshift(proxifiedTransaction);
}
- },
+ }
/**
* Clear all undo entries.
*/
clearUndoEntries() {
if (this.undoPosition < this.length)
this.splice(this.undoPosition);
- },
+ }
/**
* Clear all redo entries.
*/
clearRedoEntries() {
if (this.undoPosition > 0) {
this.splice(0, this.undoPosition);
this._undoPosition = 0;
}
- },
+ }
/**
* Clear all entries.
*/
clearAllEntries() {
if (this.length > 0) {
this.splice(0);
this._undoPosition = 0;
}
}
-};
+}
+XPCOMUtils.defineLazyGetter(this, "TransactionsHistory",
+ () => new TransactionsHistoryArray());
var PlacesTransactions = {
/**
* @see Batches in the module documentation.
*/
batch(transactionsToBatch) {
if (Array.isArray(transactionsToBatch)) {
if (transactionsToBatch.length == 0)