summaryrefslogtreecommitdiff
path: root/common/modules
diff options
context:
space:
mode:
Diffstat (limited to 'common/modules')
-rw-r--r--common/modules/buffer.jsm5
-rw-r--r--common/modules/contexts.jsm2
-rw-r--r--common/modules/finder.jsm6
-rw-r--r--common/modules/overlay.jsm2
-rw-r--r--common/modules/prefs.jsm2
-rw-r--r--common/modules/storage.jsm2
-rw-r--r--common/modules/styles.jsm2
-rw-r--r--common/modules/util.jsm9
8 files changed, 20 insertions, 10 deletions
diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm
index a59de322..8f053dcc 100644
--- a/common/modules/buffer.jsm
+++ b/common/modules/buffer.jsm
@@ -127,11 +127,12 @@ var Buffer = Module("Buffer", {
*/
get lastInputField() {
let field = this.localStore.lastInputField && this.localStore.lastInputField.get();
+
let doc = field && field.ownerDocument;
let win = doc && doc.defaultView;
return win && doc === win.document ? field : null;
},
- set lastInputField(value) { this.localStore.lastInputField = value && Cu.getWeakReference(value); },
+ set lastInputField(value) { this.localStore.lastInputField = util.weakReference(value); },
/**
* @property {nsIURI} The current top-level document.
@@ -241,7 +242,7 @@ var Buffer = Module("Buffer", {
return frame && frame.get() || this.win;
},
set focusedFrame(frame) {
- this.localStore.focusedFrame = Cu.getWeakReference(frame);
+ this.localStore.focusedFrame = util.weakReference(frame);
},
/**
diff --git a/common/modules/contexts.jsm b/common/modules/contexts.jsm
index 8a9ae42b..f5744d50 100644
--- a/common/modules/contexts.jsm
+++ b/common/modules/contexts.jsm
@@ -30,7 +30,7 @@ var Group = Class("Group", {
get contexts() this.modules.contexts,
- set lastDocument(val) { this._lastDocument = val && Cu.getWeakReference(val); },
+ set lastDocument(val) { this._lastDocument = util.weakReference(val); },
get lastDocument() this._lastDocument && this._lastDocument.get(),
modifiable: true,
diff --git a/common/modules/finder.jsm b/common/modules/finder.jsm
index a0d88aeb..fc99f31f 100644
--- a/common/modules/finder.jsm
+++ b/common/modules/finder.jsm
@@ -339,10 +339,10 @@ var RangeFinder = Module("rangefinder", {
*/
var RangeFind = Class("RangeFind", {
init: function init(window, content, matchCase, backward, elementPath, regexp) {
- this.window = Cu.getWeakReference(window);
+ this.window = util.weakReference(window);
this.content = content;
- this.baseDocument = Cu.getWeakReference(this.content.document);
+ this.baseDocument = util.weakReference(this.content.document);
this.elementPath = elementPath || null;
this.reverse = Boolean(backward);
@@ -381,7 +381,7 @@ var RangeFind = Class("RangeFind", {
this.range.selectionController.scrollSelectionIntoView(
this.range.selectionController.SELECTION_NORMAL, 0, false);
- this.store.focusedFrame = Cu.getWeakReference(range.startContainer.ownerDocument.defaultView);
+ this.store.focusedFrame = util.weakReference(range.startContainer.ownerDocument.defaultView);
},
cancel: function cancel() {
diff --git a/common/modules/overlay.jsm b/common/modules/overlay.jsm
index 14d29fea..cceb3905 100644
--- a/common/modules/overlay.jsm
+++ b/common/modules/overlay.jsm
@@ -74,7 +74,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
[self, events] = [event, event[callback || "events"]];
for (let [event, callback] in Iterator(events)) {
- let args = [Cu.getWeakReference(target),
+ let args = [util.weakReference(target),
event,
util.wrapCallback(callback, self),
capture,
diff --git a/common/modules/prefs.jsm b/common/modules/prefs.jsm
index 508add04..eb7c1873 100644
--- a/common/modules/prefs.jsm
+++ b/common/modules/prefs.jsm
@@ -113,7 +113,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
if (!this._observers[pref])
this._observers[pref] = [];
- this._observers[pref].push(!strong ? Cu.getWeakReference(callback) : { get: function () callback });
+ this._observers[pref].push(!strong ? util.weakReference(callback) : { get: function () callback });
},
/**
diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm
index ebc7e4fd..803cb00a 100644
--- a/common/modules/storage.jsm
+++ b/common/modules/storage.jsm
@@ -214,7 +214,7 @@ var Storage = Module("Storage", {
if (ref) {
let refs = overlay.getData(ref, "storage-refs");
refs.push(callback);
- var callbackRef = Cu.getWeakReference(callback);
+ var callbackRef = util.weakReference(callback);
}
else {
callbackRef = { get: function () callback };
diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm
index 1672a796..0d2fcb55 100644
--- a/common/modules/styles.jsm
+++ b/common/modules/styles.jsm
@@ -96,7 +96,7 @@ var Hive = Class("Hive", {
get modifiable() this.name !== "system",
addRef: function (obj) {
- this.refs.push(Cu.getWeakReference(obj));
+ this.refs.push(util.weakReference(obj));
this.dropRef(null);
},
dropRef: function (obj) {
diff --git a/common/modules/util.jsm b/common/modules/util.jsm
index 32223597..fb7f1878 100644
--- a/common/modules/util.jsm
+++ b/common/modules/util.jsm
@@ -1551,6 +1551,15 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
},
/**
+ * Like Cu.getWeakReference, but won't crash if you pass null.
+ */
+ weakReference: function weakReference(jsval) {
+ if (jsval == null)
+ return { get: function get() null };
+ return Cu.getWeakReference(jsval);
+ },
+
+ /**
* Wraps native exceptions thrown by the called function so that a
* proper stack trace may be retrieved from them.
*