Bug 1505957 - Recover from failed UA Widget construction and destruction r=bgrins

This patch modifies UAWidgetsChild so that when the call into the UA Widget
script throws, it could correctly clean up the Shadow DOM, to avoid leaving
the DOM in a half-broken state.

This is needed because of bug 1506300 will cause the constructor of the videocontrols
UA Widget to throw, in our specific test case.

This exception also happens when the videocontrols XBL binding initializes,
but the way the XBL service calls into the XBL binding allow it to reach a usable
but a half-broken state, while our current approach will cause the UA Widget DOM
to be inserted twice, and layout to assert.

The new clean-up approach here will make UA Widget completely absent when the
constructor throws until the cause of the exception is fixed.

Differential Revision: https://phabricator.services.mozilla.com/D11542

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Timothy Guan-tin Chien 2018-11-14 23:08:41 +00:00
Родитель ce1e741264
Коммит 2400b2758e
1 изменённых файлов: 18 добавлений и 2 удалений

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

@ -75,7 +75,16 @@ class UAWidgetsChild extends ActorChild {
Services.scriptloader.loadSubScript(uri, sandbox, "UTF-8");
}
let widget = new sandbox[widgetName](shadowRoot);
let widget;
try {
widget = new sandbox[widgetName](shadowRoot);
} catch (ex) {
// The widget may have thrown during construction.
// Report the failure and recover by clearing the Shadow DOM.
shadowRoot.innerHTML = "";
Cu.reportError(ex);
return;
}
this.widgets.set(aElement, widget);
}
@ -85,7 +94,14 @@ class UAWidgetsChild extends ActorChild {
return;
}
if (typeof widget.wrappedJSObject.destructor == "function") {
widget.wrappedJSObject.destructor();
try {
widget.wrappedJSObject.destructor();
} catch (ex) {
// The widget may have thrown during destruction.
// Report the failure and recover by clearing the Shadow DOM.
aElement.openOrClosedShadowRoot.innerHTML = "";
Cu.reportError(ex);
}
}
this.widgets.delete(aElement);
}