Skip to content

[geometry] DOMMatrix constructor is a performance and code portability footgun #346

@bzbarsky

Description

@bzbarsky

Consider what happens if one does:

new DOMMatrix(new DOMMatrix())

(or in general passes a DOMMatrix instance to the DOMMatrix constructor). The answer is that, since DOMMatrix is not iterable, it will get converted to a string of the form "matrix(stuff)", per https://drafts.fxtf.org/geometry/#dommatrixreadonly-stringification-behavior and then the constructor will either re-parse that string to create a DOMMatrix or throw, depending on whether it's running in a Window or a worker. This seems like a code portability (between windows and workers) footgun, as well as a performance footgun in the Window case.

Why, exactly, was the overload of the constructor that takes DOMMatrixReadOnly removed? It seems to me that we should reinstate it and either make it consistently work (so people can use it) or consistently throw (so people know to not use it and use the fromMatrix thing instead)... The current setup where it kinda works, but only in Window scopes doesn't seem great.

@zcorpan do you recall why this was set up like this?

@saschanaz

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions