Skip to content

Commit

Permalink
add length property to window.SVGPathSegList (#27)
Browse files Browse the repository at this point in the history
* add length property to window.SVGPathSegList. its built in Firefox implements not in W3C specification.

* Update pathseg.js

adopt suggested comment.

* add Qunit Test for PathSegList.length
  • Loading branch information
isdh authored and progers committed Jul 9, 2018
1 parent 58a771a commit 96f27ee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pathseg.js
Expand Up @@ -387,6 +387,15 @@
enumerable: true
});

// The length property was not specified but was in Firefox 58.
Object.defineProperty(window.SVGPathSegList.prototype, "length", {
get: function() {
this._checkPathSynchronizedToList();
return this._list.length;
},
enumerable: true
});

// Add the pathSegList accessors to window.SVGPathElement.
// Spec: http://www.w3.org/TR/SVG11/single-page.html#paths-InterfaceSVGAnimatedPathData
Object.defineProperty(window.SVGPathElement.prototype, "pathSegList", {
Expand Down
24 changes: 24 additions & 0 deletions tests/tests.js
Expand Up @@ -891,3 +891,27 @@ QUnit.test("Test getPathSegAtLength with non-trivial paths", function(assert) {
assert.equal(path.getPathSegAtLength(100), "1");
assert.equal(path.getPathSegAtLength(101), "3");
});

QUnit.test("Test PathSegList.length", function(assert) {
var path = document.createElementNS("http://www.w3.org/2000/svg", "path");

// Empty path.
path.setAttribute("d", "");
assert.equal(path.pathSegList.length, path.pathSegList.numberOfItems);
assert.equal(path.pathSegList.length, 0);

// Path with one segment.
path.setAttribute("d", "M1 1");
assert.equal(path.pathSegList.length, path.pathSegList.numberOfItems);
assert.equal(path.pathSegList.length, 1);

// Path with one close segment.
path.setAttribute("d", "z");
assert.equal(path.pathSegList.length, path.pathSegList.numberOfItems);
assert.equal(path.pathSegList.length, 0);

// Path with two segments and a close.
path.setAttribute("d", "M1 1 L2 2Z");
assert.equal(path.pathSegList.length, path.pathSegList.numberOfItems);
assert.equal(path.pathSegList.length, 3);
});

0 comments on commit 96f27ee

Please sign in to comment.