mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 17:55:07 +02:00
When a canvas belongs to a detached document (e.g. one created via document.implementation.createHTMLDocument()), document->window() returns null, causing a null pointer crash in set_font. Use Length::ResolutionContext::for_document() instead of for_window(), which handles the no-navigable case gracefully and is already the recommended pattern (per existing FIXME in Length.h). This also fixes the same crash path via fillText, strokeText, and measureText which trigger lazy font initialization through set_font. Fixes #8515. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
24 lines
799 B
HTML
24 lines
799 B
HTML
<!DOCTYPE html>
|
|
<script src="../include.js"></script>
|
|
<script>
|
|
test(() => {
|
|
const doc = document.implementation.createHTMLDocument("");
|
|
|
|
// Setting font on a canvas belonging to a detached document should not crash.
|
|
const canvas1 = doc.createElement("canvas");
|
|
const ctx1 = canvas1.getContext("2d");
|
|
ctx1.font = "bold 24px serif";
|
|
println("set_font: PASS");
|
|
|
|
// Calling fillText/strokeText/measureText with default font (lazy init) should not crash.
|
|
const canvas2 = doc.createElement("canvas");
|
|
const ctx2 = canvas2.getContext("2d");
|
|
ctx2.fillText("hello", 0, 0);
|
|
println("fillText: PASS");
|
|
ctx2.strokeText("hello", 0, 0);
|
|
println("strokeText: PASS");
|
|
const metrics = ctx2.measureText("hello");
|
|
println("measureText: PASS");
|
|
});
|
|
</script>
|