Skip to content

Commit

Permalink
Sync SVGLength with WebIDL specification
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=275028

Reviewed by Simon Fraser.

This patch aligns WebKit with web-specification [1]:

[1] https://svgwg.org/svg2-draft/types.html#InterfaceSVGLength

From above, `value` and `valueInSpecifiedUnits` should not be
'unrestricted', so this patch remove it from both.

Unfortunately, we do still have few issues in 'valueAsString' to
fix and enable us to progress further in sub-tests but this patch
do reduce our failures further.

I synced additional tests for local copy from below Blink commit (minus
some changes).

Commit: https://chromium.googlesource.com/chromium/src/+/7d9f4bebeb65115c81918032278174ad01858d33

In future, we should delete local copy and just use WPT as reference.

* LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-expected.txt:
* LayoutTests/svg/dom/SVGLength-expected.txt:
* LayoutTests/svg/dom/SVGLength.html:
* Source/WebCore/svg/SVGLength.idl:

Canonical link: https://commits.webkit.org/279659@main
  • Loading branch information
Ahmad Saleem committed Jun 3, 2024
1 parent b5e7baa commit 57c43e3
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

FAIL SVGLength interface assert_throws_js: function "function() { length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 'aString'); }" did not throw
FAIL SVGLength interface The string did not match the expected pattern.

59 changes: 49 additions & 10 deletions LayoutTests/svg/dom/SVGLength-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,61 @@ Check invalid arguments for 'newValueSpecifiedUnits'
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_UNKNOWN, 4) threw exception NotSupportedError: The operation is not supported..
PASS length.newValueSpecifiedUnits(-1, 4) threw exception NotSupportedError: The operation is not supported..
PASS length.newValueSpecifiedUnits(11, 4) threw exception NotSupportedError: The operation is not supported..
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 'aString') is undefined.
PASS length.value is NaN
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 0) is undefined.
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, length) is undefined.
PASS length.value is NaN
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 0) is undefined.
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, svgElement) is undefined.
PASS length.value is NaN
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 'aString') threw exception TypeError: The provided value is non-finite.
PASS length.value is 0
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, length) threw exception TypeError: The provided value is non-finite.
PASS length.value is 0
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, svgElement) threw exception TypeError: The provided value is non-finite.
PASS length.value is 0
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, NaN) threw exception TypeError: The provided value is non-finite.
PASS length.value is 0
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, Infinity) threw exception TypeError: The provided value is non-finite.
PASS length.value is 0
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX) threw exception TypeError: Not enough arguments.
PASS length.newValueSpecifiedUnits('aString', 4) threw exception NotSupportedError: The operation is not supported..
PASS length.newValueSpecifiedUnits(length, 4) threw exception NotSupportedError: The operation is not supported..
PASS length.newValueSpecifiedUnits(svgElement, 4) threw exception NotSupportedError: The operation is not supported..
PASS length.newValueSpecifiedUnits('aString', 'aString') threw exception NotSupportedError: The operation is not supported..
PASS length.newValueSpecifiedUnits(length, length) threw exception NotSupportedError: The operation is not supported..
PASS length.newValueSpecifiedUnits(svgElement, svgElement) threw exception NotSupportedError: The operation is not supported..
PASS length.newValueSpecifiedUnits('aString', 'aString') threw exception TypeError: The provided value is non-finite.
PASS length.newValueSpecifiedUnits(length, length) threw exception TypeError: The provided value is non-finite.
PASS length.newValueSpecifiedUnits(svgElement, svgElement) threw exception TypeError: The provided value is non-finite.
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX
PASS length.value is 2
PASS length.valueInSpecifiedUnits is 2
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX

Check setting invalid 'valueAsString' arguments
PASS length.valueAsString = '10deg' threw exception SyntaxError: The string did not match the expected pattern..
PASS length.valueAsString is "2px"
PASS length.value is 2
PASS length.valueInSpecifiedUnits is 2
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX
PASS length.valueAsString is "2px"
PASS length.valueAsString is "2px"
PASS length.value is 2
PASS length.valueInSpecifiedUnits is 2
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX
PASS length.valueAsString = ',5 em' threw exception SyntaxError: The string did not match the expected pattern..
PASS length.valueAsString is "2px"
PASS length.value is 2
PASS length.valueInSpecifiedUnits is 2
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX
PASS length.valueAsString = null threw exception SyntaxError: The string did not match the expected pattern..
PASS length.valueAsString is "2px"
PASS length.value is 2
PASS length.valueInSpecifiedUnits is 2
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX

Check setting invalid 'value' arguments
PASS length.value = NaN threw exception TypeError: The provided value is non-finite.
PASS length.value = Infinity threw exception TypeError: The provided value is non-finite.
PASS length.value is 2
PASS length.valueInSpecifiedUnits is 2
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX

Check setting invalid 'valueInSpecifiedUnits' arguments
PASS length.valueInSpecifiedUnits = NaN threw exception TypeError: The provided value is non-finite.
PASS length.valueInSpecifiedUnits = Infinity threw exception TypeError: The provided value is non-finite.
PASS length.value is 2
PASS length.valueInSpecifiedUnits is 2
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX
Expand Down
60 changes: 51 additions & 9 deletions LayoutTests/svg/dom/SVGLength.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
Expand Down Expand Up @@ -47,14 +47,17 @@
shouldThrow("length.newValueSpecifiedUnits(-1, 4)");
shouldThrow("length.newValueSpecifiedUnits(11, 4)");
// ECMA-262, 9.3, "ToNumber"
shouldBeUndefined("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 'aString')");
shouldBe("length.value", "NaN");
shouldBeUndefined("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 0)");
shouldBeUndefined("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, length)");
shouldBe("length.value", "NaN");
shouldBeUndefined("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 0)");
shouldBeUndefined("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, svgElement)");
shouldBe("length.value", "NaN");
shouldThrow("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 'aString')");
shouldBe("length.value", "0");
shouldThrow("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, length)");
shouldBe("length.value", "0");
shouldThrow("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, svgElement)");
shouldBe("length.value", "0");
shouldThrow("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, NaN)");
shouldBe("length.value", "0");
shouldThrow("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, Infinity)");
shouldBe("length.value", "0");
shouldThrow("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX)");
// Reset to original value above.
length.valueAsString = "2px";
Expand All @@ -69,8 +72,47 @@
shouldBe("length.valueInSpecifiedUnits", "2");
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");

debug("");
debug("Check setting invalid 'valueAsString' arguments");
shouldThrow("length.valueAsString = '10deg'");
shouldBeEqualToString("length.valueAsString", "2px");
shouldBe("length.value", "2");
shouldBe("length.valueInSpecifiedUnits", "2");
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");
shouldBeEqualToString("length.valueAsString", "2px");
shouldBeEqualToString("length.valueAsString", "2px");
shouldBe("length.value", "2");
shouldBe("length.valueInSpecifiedUnits", "2");
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");

shouldThrow("length.valueAsString = ',5 em'");
shouldBeEqualToString("length.valueAsString", "2px");
shouldBe("length.value", "2");
shouldBe("length.valueInSpecifiedUnits", "2");
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");
shouldThrow("length.valueAsString = null");
shouldBeEqualToString("length.valueAsString", "2px");
shouldBe("length.value", "2");
shouldBe("length.valueInSpecifiedUnits", "2");
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");

debug("");
debug("Check setting invalid 'value' arguments");
shouldThrow("length.value = NaN");
shouldThrow("length.value = Infinity");
shouldBe("length.value", "2");
shouldBe("length.valueInSpecifiedUnits", "2");
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");

debug("");
debug("Check setting invalid 'valueInSpecifiedUnits' arguments");
shouldThrow("length.valueInSpecifiedUnits = NaN");
shouldThrow("length.valueInSpecifiedUnits = Infinity");
shouldBe("length.value", "2");
shouldBe("length.valueInSpecifiedUnits", "2");
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");

successfullyParsed = true;
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
8 changes: 4 additions & 4 deletions Source/WebCore/svg/SVGLength.idl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
* Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
* Copyright (C) 2006 Apple Inc. All rights reserved.
* Copyright (C) 2006-2024 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -37,11 +37,11 @@
const unsigned short SVG_LENGTHTYPE_PC = 10;

readonly attribute unsigned short unitType;
[ImplementedAs=valueForBindings] attribute unrestricted float value;
[ImplementedAs=valueForBindings] attribute float value;

attribute unrestricted float valueInSpecifiedUnits;
attribute float valueInSpecifiedUnits;
attribute DOMString valueAsString;

undefined newValueSpecifiedUnits(unsigned short unitType, unrestricted float valueInSpecifiedUnits);
undefined newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits);
undefined convertToSpecifiedUnits(unsigned short unitType);
};

0 comments on commit 57c43e3

Please sign in to comment.