Issue #2087 - Don't throw on lacking PresShell in SetFontInternal

In CanvasRenderingContext2D::SetFontInternal, we should not throw if
there is no PresShell due to (sandboxed/hidden) iframe use that has not
initialized its presentation yet at the time of property manipulation.
This removes the throwing of the error and just silently fails.

Resolves #2087
This commit is contained in:
Moonchild 2023-01-09 10:52:49 +01:00 committed by roytam1
commit efeb0e3e97

View file

@ -3758,7 +3758,11 @@ CanvasRenderingContext2D::SetFontInternal(const nsAString& aFont,
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
if (!presShell) {
aError.Throw(NS_ERROR_FAILURE);
// Do not throw here. We may be in a situation where we're loading in an iframe
// that is sandboxed, and/or initially hidden with display:none, in which case
// we don't want to throw an error but silently fail.
// If we don't do this, JS trying to set context.font to something will abort,
// breaking e.g. third party serviced graphs.
return false;
}