Files
sousa-gecko/testing/web-platform/tests/svg/path/interfaces/setPathData-overrides-d.html
T
Virali Purbey 4a8f10611e Bug 2049945 [wpt PR 60835] - [SVG] Implement setPathData() on SVGPathElement, a=testonly
Automatic update from web-platform-tests
[SVG] Implement `setPathData()` on `SVGPathElement`

Implements `setPathData(sequence<SVGPathSegment> pathData)` from the
SVG Paths spec [1] on `SVGPathElement`.

Valid segments are built into an SVGPathByteStream (via
SVGPathByteStreamBuilder), then applied through `setAttribute("d", …)`
so the existing mutation pipeline (invalidation, <use> instances,
MutationObservers) fires. A leading non-moveto yields an empty path;
on the first invalid segment (unknown type, wrong arity, non-finite
value, non-binary arc flag) that segment and all after it are dropped.

Gated behind the existing experimental runtime flag `SVGPathDataAPI`.
Instrumented via the `SVGPathElementSetPathData` use counter.

[1] https://svgwg.org/specs/paths/#__svg__SVGPathData__setPathData

Design: https://docs.google.com/document/d/1uCVUqYGKgsCCu7LEtEdO3Yuea-MT-I2XsU6Eoe3mlQI/edit?usp=sharing

Bug: 40441025
Change-Id: I70419142ad23736d2e0e0f1a4ed4833e6c76fef8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7863903
Reviewed-by: Fredrik Söderquist <fs@opera.com>
Reviewed-by: Divyansh Mangal <dmangal@microsoft.com>
Commit-Queue: Virali Purbey <viralipurbey@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1651484}

--

wpt-commits: 3c7d417eaf128fa7bfad500611b4e071a1e0627e
wpt-pr: 60835
2026-07-06 08:44:10 +00:00

37 lines
1.2 KiB
HTML

<!doctype html>
<title>SVGPathElement.setPathData() overrides previous d attribute</title>
<link rel="help" href="https://svgwg.org/specs/paths/#__svg__SVGPathData__setPathData">
<link rel="author" title="Virali Purbey" href="mailto:viralipurbey@microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/getPathData-helpers.js"></script>
<svg></svg>
<script>
test(() => {
const path = createPath("M 0 0 L 99 99 Z");
path.setPathData([
{ type: "M", values: [1, 2] },
{ type: "L", values: [3, 4] }
]);
assert_equals(path.getAttribute("d"), "M 1 2 L 3 4");
}, "setPathData() replaces the existing d attribute");
test(() => {
// Detached path with no initial d.
const path = createPath();
path.setPathData([
{ type: "M", values: [0, 0] },
{ type: "L", values: [5, 5] }
]);
assert_equals(path.getAttribute("d"), "M 0 0 L 5 5");
}, "setPathData() works on a detached path");
test(() => {
const path = createPath("M 5 5 L 10 10");
path.setPathData([]);
assert_equals(path.getAttribute("d"), null,
"Empty sequence removes the d attribute");
}, "setPathData() with an empty sequence");
</script>