Files
sousa-gecko/testing/web-platform/tests/svg/path/interfaces/setPathData-plain-object.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

62 lines
2.1 KiB
HTML

<!doctype html>
<title>SVGPathElement.setPathData() with plain JS objects</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>
// WebIDL dictionary conversion accepts plain JS objects with the required
// own properties.
test(() => {
const path = createPath();
path.setPathData([
{ type: "M", values: [0, 0] },
{ type: "L", values: [10, 10] }
]);
const segs = path.getPathData();
assert_equals(segs.length, 2);
assert_equals(segs[0].type, "M");
assert_array_equals(segs[0].values, [0, 0]);
assert_equals(segs[1].type, "L");
assert_array_equals(segs[1].values, [10, 10]);
}, "setPathData() accepts plain object literals");
test(() => {
const path = createPath();
// Array-like (not a real Array) with iterator should also be accepted
// because sequence<T> uses the iterable protocol.
function* gen() {
yield { type: "M", values: [0, 0] };
yield { type: "L", values: [5, 5] };
}
path.setPathData([...gen()]);
assert_equals(path.getAttribute("d"), "M 0 0 L 5 5");
}, "setPathData() accepts spread from a generator");
test(() => {
const path = createPath();
// `values` must be iterable for sequence<unrestricted float>. Typed arrays
// are iterable, so Float32Array works.
path.setPathData([
{ type: "M", values: new Float32Array([0, 0]) },
{ type: "L", values: new Float64Array([7, 7]) }
]);
assert_equals(path.getAttribute("d"), "M 0 0 L 7 7");
}, "setPathData() accepts typed-array values");
test(() => {
const path = createPath();
// Extra own properties on the segment object are ignored by WebIDL
// dictionary conversion.
path.setPathData([
{ type: "M", values: [0, 0], extra: "ignored" },
{ type: "L", values: [3, 3], foo: 42 }
]);
assert_equals(path.getAttribute("d"), "M 0 0 L 3 3");
}, "setPathData() ignores extra properties on segment objects");
</script>