Bug 773980 - Don't touch dead objects in BrowserElementParent.js. r=mounir

This commit is contained in:
Justin Lebar 2012-07-19 12:39:44 -04:00
Родитель 488861592f
Коммит e3da02bc90
1 изменённых файлов: 26 добавлений и 3 удалений

Просмотреть файл

@ -136,7 +136,12 @@ function BrowserElementParent(frameLoader) {
let self = this;
function addMessageListener(msg, handler) {
self._mm.addMessageListener('browser-element-api:' + msg, handler.bind(self));
function checkedHandler() {
if (self._isAlive()) {
handler.apply(self, arguments);
}
}
self._mm.addMessageListener('browser-element-api:' + msg, checkedHandler);
}
addMessageListener("hello", this._recvHello);
@ -157,11 +162,19 @@ function BrowserElementParent(frameLoader) {
addMessageListener('got-can-go-forward', this._gotDOMRequestResult);
function defineMethod(name, fn) {
XPCNativeWrapper.unwrap(self._frameElement)[name] = fn.bind(self);
XPCNativeWrapper.unwrap(self._frameElement)[name] = function() {
if (self._isAlive()) {
return fn.apply(self, arguments);
}
};
}
function defineDOMRequestMethod(domName, msgName) {
XPCNativeWrapper.unwrap(self._frameElement)[domName] = self._sendDOMRequest.bind(self, msgName);
XPCNativeWrapper.unwrap(self._frameElement)[domName] = function() {
if (self._isAlive()) {
return self._sendDOMRequest(msgName);
}
};
}
// Define methods on the frame element.
@ -176,6 +189,16 @@ function BrowserElementParent(frameLoader) {
}
BrowserElementParent.prototype = {
/**
* You shouldn't touch this._frameElement or this._window if _isAlive is
* false. (You'll likely get an exception if you do.)
*/
_isAlive: function() {
return !Cu.isDeadWrapper(this._frameElement) &&
!Cu.isDeadWrapper(this._frameElement.ownerDocument) &&
!Cu.isDeadWrapper(this._frameElement.ownerDocument.defaultView);
},
get _window() {
return this._frameElement.ownerDocument.defaultView;
},