Skip to content

Commit

Permalink
Sync 'SVGNumber.idl' with WebIDL Specification
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=267186

Reviewed by Tim Nguyen.

This patch is to align WebKit with Web-Specification [1]:

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

It removes 'unrestricted' from `value`.

Additionally, the test is synced from below Blink upstream (main), which uses 'testharness'.

* Source/WebCore/svg/SVGNumber.idl:
* LayoutTests/svg/dom/SVGNumber.html: Updated from Blink / Chromium source
* LayoutTests/svg/dom/SVGNumber-expected.txt: Rebaselined

Canonical link: https://commits.webkit.org/272741@main
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed Jan 7, 2024
1 parent 7b2588d commit 25c142f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 73 deletions.
31 changes: 1 addition & 30 deletions LayoutTests/svg/dom/SVGNumber-expected.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,3 @@
This test checks the SVGNumber API

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".



Check initial number value
PASS num.value is 0

Check assigning number
PASS num.value = 100 is 100
PASS num.value = -100 is -100
PASS num.value = 12345678 is 12345678
PASS num.value = -num.value is -12345678

Check that numbers are static, caching value in a local variable and modifying it, should have no effect
PASS numRef is 1000
PASS num.value is -12345678

Check assigning invalid number, number should be 0 afterwards
PASS num.value = num is num
PASS num.value = 'aString' is 'aString'
PASS num.value = svgElement is svgElement
PASS num.value is NaN
PASS num.value = null is null

Check that the number is now null
PASS num.value is 0
PASS successfullyParsed is true

TEST COMPLETE
PASS SVGNumber interface

79 changes: 37 additions & 42 deletions LayoutTests/svg/dom/SVGNumber.html
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<!DOCTYPE html>
<title>SVGNumber interface</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
description("This test checks the SVGNumber API");
test(function() {
// This test checks the SVGNumber API.

var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
var num = svgElement.createSVGNumber();
var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
var num = svgElement.createSVGNumber();

debug("");
debug("Check initial number value");
shouldBe("num.value", "0");
// Check initial number value.
assert_equals(num.value, 0);

debug("");
debug("Check assigning number");
shouldBe("num.value = 100", "100");
shouldBe("num.value = -100", "-100");
shouldBe("num.value = 12345678", "12345678");
shouldBe("num.value = -num.value", "-12345678");
// Check assigning number.
num.value = 100;
assert_equals(num.value, 100);
num.value = -100;
assert_equals(num.value, -100);
num.value = 12345678;
assert_equals(num.value, 12345678);
num.value = -num.value;
assert_equals(num.value, -12345678);

debug("");
debug("Check that numbers are static, caching value in a local variable and modifying it, should have no effect");
var numRef = num.value;
numRef = 1000;
shouldBe("numRef", "1000");
shouldBe("num.value", "-12345678");
// Check that numbers are static, caching value in a local variable and modifying it, should have no effect.
var numRef = num.value;
numRef = 1000;
assert_equals(numRef, 1000);
assert_equals(num.value, -12345678);

debug("");
debug("Check assigning invalid number, number should be 0 afterwards");
shouldBe("num.value = num", "num");
shouldBe("num.value = 'aString'", "'aString'");
shouldBe("num.value = svgElement", "svgElement");
shouldBe("num.value", "NaN");
shouldBeNull("num.value = null");

debug("");
debug("Check that the number is now null");
shouldBe("num.value", "0");

successfullyParsed = true;
// Check assigning invalid number, number should be 0 afterwards.
num.value = 0;
assert_equals(num.value, 0);
assert_throws_js(TypeError, function() { num.value = num; });
assert_throws_js(TypeError, function() { num.value = 'aString'; });
assert_throws_js(TypeError, function() { num.value = svgElement; });
assert_throws_js(TypeError, function() { num.value = NaN; });
assert_throws_js(TypeError, function() { num.value = Infinity; });
assert_equals(num.value, 0);
num.value = null;
// Check that the number is now null.
assert_equals(num.value, 0);
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
4 changes: 3 additions & 1 deletion Source/WebCore/svg/SVGNumber.idl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
* Boston, MA 02110-1301, USA.
*/

// https://svgwg.org/svg2-draft/types.html#InterfaceSVGNumber

[
Exposed=Window
] interface SVGNumber {
[ImplementedAs=valueForBindings] attribute unrestricted float value;
[ImplementedAs=valueForBindings] attribute float value;
};

0 comments on commit 25c142f

Please sign in to comment.