From efeb0e3e9724461bf5a2ac19b525e193f97f0736 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Mon, 9 Jan 2023 10:52:49 +0100 Subject: [PATCH] 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 --- dom/canvas/CanvasRenderingContext2D.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index f83fdcb5bf..f56f2bdf53 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -3758,7 +3758,11 @@ CanvasRenderingContext2D::SetFontInternal(const nsAString& aFont, nsCOMPtr 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; }