Skip to content

Commit 57c43e3

Browse files
author
Ahmad Saleem
committed
Sync SVGLength with WebIDL specification
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
1 parent b5e7baa commit 57c43e3

File tree

4 files changed

+105
-24
lines changed

4 files changed

+105
-24
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

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

LayoutTests/svg/dom/SVGLength-expected.txt

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,61 @@ Check invalid arguments for 'newValueSpecifiedUnits'
3333
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_UNKNOWN, 4) threw exception NotSupportedError: The operation is not supported..
3434
PASS length.newValueSpecifiedUnits(-1, 4) threw exception NotSupportedError: The operation is not supported..
3535
PASS length.newValueSpecifiedUnits(11, 4) threw exception NotSupportedError: The operation is not supported..
36-
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 'aString') is undefined.
37-
PASS length.value is NaN
3836
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 0) is undefined.
39-
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, length) is undefined.
40-
PASS length.value is NaN
41-
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 0) is undefined.
42-
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, svgElement) is undefined.
43-
PASS length.value is NaN
37+
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 'aString') threw exception TypeError: The provided value is non-finite.
38+
PASS length.value is 0
39+
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, length) threw exception TypeError: The provided value is non-finite.
40+
PASS length.value is 0
41+
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, svgElement) threw exception TypeError: The provided value is non-finite.
42+
PASS length.value is 0
43+
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, NaN) threw exception TypeError: The provided value is non-finite.
44+
PASS length.value is 0
45+
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, Infinity) threw exception TypeError: The provided value is non-finite.
46+
PASS length.value is 0
4447
PASS length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX) threw exception TypeError: Not enough arguments.
4548
PASS length.newValueSpecifiedUnits('aString', 4) threw exception NotSupportedError: The operation is not supported..
4649
PASS length.newValueSpecifiedUnits(length, 4) threw exception NotSupportedError: The operation is not supported..
4750
PASS length.newValueSpecifiedUnits(svgElement, 4) threw exception NotSupportedError: The operation is not supported..
48-
PASS length.newValueSpecifiedUnits('aString', 'aString') threw exception NotSupportedError: The operation is not supported..
49-
PASS length.newValueSpecifiedUnits(length, length) threw exception NotSupportedError: The operation is not supported..
50-
PASS length.newValueSpecifiedUnits(svgElement, svgElement) threw exception NotSupportedError: The operation is not supported..
51+
PASS length.newValueSpecifiedUnits('aString', 'aString') threw exception TypeError: The provided value is non-finite.
52+
PASS length.newValueSpecifiedUnits(length, length) threw exception TypeError: The provided value is non-finite.
53+
PASS length.newValueSpecifiedUnits(svgElement, svgElement) threw exception TypeError: The provided value is non-finite.
54+
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX
55+
PASS length.value is 2
56+
PASS length.valueInSpecifiedUnits is 2
57+
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX
58+
59+
Check setting invalid 'valueAsString' arguments
60+
PASS length.valueAsString = '10deg' threw exception SyntaxError: The string did not match the expected pattern..
61+
PASS length.valueAsString is "2px"
62+
PASS length.value is 2
63+
PASS length.valueInSpecifiedUnits is 2
64+
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX
65+
PASS length.valueAsString is "2px"
66+
PASS length.valueAsString is "2px"
67+
PASS length.value is 2
68+
PASS length.valueInSpecifiedUnits is 2
69+
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX
70+
PASS length.valueAsString = ',5 em' threw exception SyntaxError: The string did not match the expected pattern..
71+
PASS length.valueAsString is "2px"
72+
PASS length.value is 2
73+
PASS length.valueInSpecifiedUnits is 2
74+
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX
75+
PASS length.valueAsString = null threw exception SyntaxError: The string did not match the expected pattern..
76+
PASS length.valueAsString is "2px"
77+
PASS length.value is 2
78+
PASS length.valueInSpecifiedUnits is 2
79+
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX
80+
81+
Check setting invalid 'value' arguments
82+
PASS length.value = NaN threw exception TypeError: The provided value is non-finite.
83+
PASS length.value = Infinity threw exception TypeError: The provided value is non-finite.
84+
PASS length.value is 2
85+
PASS length.valueInSpecifiedUnits is 2
5186
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX
87+
88+
Check setting invalid 'valueInSpecifiedUnits' arguments
89+
PASS length.valueInSpecifiedUnits = NaN threw exception TypeError: The provided value is non-finite.
90+
PASS length.valueInSpecifiedUnits = Infinity threw exception TypeError: The provided value is non-finite.
5291
PASS length.value is 2
5392
PASS length.valueInSpecifiedUnits is 2
5493
PASS length.unitType is SVGLength.SVG_LENGTHTYPE_PX

LayoutTests/svg/dom/SVGLength.html

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
22
<html>
33
<head>
4-
<script src="../../resources/js-test-pre.js"></script>
4+
<script src="../../resources/js-test.js"></script>
55
</head>
66
<body>
77
<p id="description"></p>
@@ -47,14 +47,17 @@
4747
shouldThrow("length.newValueSpecifiedUnits(-1, 4)");
4848
shouldThrow("length.newValueSpecifiedUnits(11, 4)");
4949
// ECMA-262, 9.3, "ToNumber"
50-
shouldBeUndefined("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 'aString')");
51-
shouldBe("length.value", "NaN");
5250
shouldBeUndefined("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 0)");
53-
shouldBeUndefined("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, length)");
54-
shouldBe("length.value", "NaN");
55-
shouldBeUndefined("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 0)");
56-
shouldBeUndefined("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, svgElement)");
57-
shouldBe("length.value", "NaN");
51+
shouldThrow("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 'aString')");
52+
shouldBe("length.value", "0");
53+
shouldThrow("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, length)");
54+
shouldBe("length.value", "0");
55+
shouldThrow("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, svgElement)");
56+
shouldBe("length.value", "0");
57+
shouldThrow("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, NaN)");
58+
shouldBe("length.value", "0");
59+
shouldThrow("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, Infinity)");
60+
shouldBe("length.value", "0");
5861
shouldThrow("length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX)");
5962
// Reset to original value above.
6063
length.valueAsString = "2px";
@@ -69,8 +72,47 @@
6972
shouldBe("length.valueInSpecifiedUnits", "2");
7073
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");
7174

75+
debug("");
76+
debug("Check setting invalid 'valueAsString' arguments");
77+
shouldThrow("length.valueAsString = '10deg'");
78+
shouldBeEqualToString("length.valueAsString", "2px");
79+
shouldBe("length.value", "2");
80+
shouldBe("length.valueInSpecifiedUnits", "2");
81+
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");
82+
shouldBeEqualToString("length.valueAsString", "2px");
83+
shouldBeEqualToString("length.valueAsString", "2px");
84+
shouldBe("length.value", "2");
85+
shouldBe("length.valueInSpecifiedUnits", "2");
86+
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");
87+
88+
shouldThrow("length.valueAsString = ',5 em'");
89+
shouldBeEqualToString("length.valueAsString", "2px");
90+
shouldBe("length.value", "2");
91+
shouldBe("length.valueInSpecifiedUnits", "2");
92+
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");
93+
shouldThrow("length.valueAsString = null");
94+
shouldBeEqualToString("length.valueAsString", "2px");
95+
shouldBe("length.value", "2");
96+
shouldBe("length.valueInSpecifiedUnits", "2");
97+
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");
98+
99+
debug("");
100+
debug("Check setting invalid 'value' arguments");
101+
shouldThrow("length.value = NaN");
102+
shouldThrow("length.value = Infinity");
103+
shouldBe("length.value", "2");
104+
shouldBe("length.valueInSpecifiedUnits", "2");
105+
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");
106+
107+
debug("");
108+
debug("Check setting invalid 'valueInSpecifiedUnits' arguments");
109+
shouldThrow("length.valueInSpecifiedUnits = NaN");
110+
shouldThrow("length.valueInSpecifiedUnits = Infinity");
111+
shouldBe("length.value", "2");
112+
shouldBe("length.valueInSpecifiedUnits", "2");
113+
shouldBe("length.unitType", "SVGLength.SVG_LENGTHTYPE_PX");
114+
72115
successfullyParsed = true;
73116
</script>
74-
<script src="../../resources/js-test-post.js"></script>
75117
</body>
76118
</html>

Source/WebCore/svg/SVGLength.idl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
33
* Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
44
* Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
5-
* Copyright (C) 2006 Apple Inc. All rights reserved.
5+
* Copyright (C) 2006-2024 Apple Inc. All rights reserved.
66
*
77
* This library is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU Library General Public
@@ -37,11 +37,11 @@
3737
const unsigned short SVG_LENGTHTYPE_PC = 10;
3838

3939
readonly attribute unsigned short unitType;
40-
[ImplementedAs=valueForBindings] attribute unrestricted float value;
40+
[ImplementedAs=valueForBindings] attribute float value;
4141

42-
attribute unrestricted float valueInSpecifiedUnits;
42+
attribute float valueInSpecifiedUnits;
4343
attribute DOMString valueAsString;
4444

45-
undefined newValueSpecifiedUnits(unsigned short unitType, unrestricted float valueInSpecifiedUnits);
45+
undefined newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits);
4646
undefined convertToSpecifiedUnits(unsigned short unitType);
4747
};

0 commit comments

Comments
 (0)