summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/content/dactyl.js2
-rw-r--r--common/content/events.js4
-rw-r--r--common/content/marks.js2
-rw-r--r--common/content/modes.js2
-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
12 files changed, 25 insertions, 15 deletions
diff --git a/common/content/dactyl.js b/common/content/dactyl.js
index 17a72ea7..f3260f42 100644
--- a/common/content/dactyl.js
+++ b/common/content/dactyl.js
@@ -205,7 +205,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
registerObserver: function registerObserver(type, callback, weak) {
if (!(type in this._observers))
this._observers[type] = [];
- this._observers[type].push(weak ? Cu.getWeakReference(callback) : { get: function () callback });
+ this._observers[type].push(weak ? util.weakReference(callback) : { get: function () callback });
},
registerObservers: function registerObservers(obj, prop) {
diff --git a/common/content/events.js b/common/content/events.js
index a90e31bd..090e964c 100644
--- a/common/content/events.js
+++ b/common/content/events.js
@@ -50,8 +50,8 @@ var EventHive = Class("EventHive", Contexts.Hive, {
var [self, events] = this._events(event, callback);
for (let [event, callback] in Iterator(events)) {
- let args = [Cu.getWeakReference(target),
- self ? Cu.getWeakReference(self) : { get: function () null },
+ let args = [util.weakReference(target),
+ util.weakReference(self),
event,
this.wrapListener(callback, self),
capture,
diff --git a/common/content/marks.js b/common/content/marks.js
index a6eaa4be..d8c9736b 100644
--- a/common/content/marks.js
+++ b/common/content/marks.js
@@ -65,7 +65,7 @@ var Marks = Module("marks", {
let mark = this.Mark();
if (Marks.isURLMark(name)) {
- mark.tab = Cu.getWeakReference(tabs.getTab());
+ mark.tab = util.weakReference(tabs.getTab());
this._urlMarks.set(name, mark);
var message = "mark.addURL";
}
diff --git a/common/content/modes.js b/common/content/modes.js
index 03fa4090..35494578 100644
--- a/common/content/modes.js
+++ b/common/content/modes.js
@@ -333,7 +333,7 @@ var Modes = Module("modes", {
if (!(id in this.boundProperties))
for (let elem in array.iterValues(this._modeStack))
elem.saved[id] = { obj: obj, prop: prop, value: obj[prop], test: test };
- this.boundProperties[id] = { obj: Cu.getWeakReference(obj), prop: prop, test: test };
+ this.boundProperties[id] = { obj: util.weakReference(obj), prop: prop, test: test };
},
inSet: false,
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.
*