This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 26201 - DOMPointReadOnly and friends should have constructors
Summary: DOMPointReadOnly and friends should have constructors
Status: RESOLVED FIXED
Alias: None
Product: FXTF
Classification: Unclassified
Component: Geometry (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Simon Pieters
QA Contact: sideshowbarker+geometry
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-25 17:01 UTC by Domenic Denicola
Modified: 2014-12-02 13:45 UTC (History)
3 users (show)

See Also:


Attachments

Description Domenic Denicola 2014-06-25 17:01:38 UTC
Only DOMPoint and friends currently have constructors, but their base classes should too. It's impossible to do inheritance in JavaScript unless the base class is also constructible, so having DOMRect inherit from a non-constructible class is C++ magic that cannot match JavaScript semantics.

Besides, if the platform wants read-only interfaces, then so will users.
Comment 1 Dirk Schulze 2014-06-25 17:16:01 UTC
(In reply to Domenic Denicola from comment #0)
> Only DOMPoint and friends currently have constructors, but their base
> classes should too. It's impossible to do inheritance in JavaScript unless
> the base class is also constructible, so having DOMRect inherit from a
> non-constructible class is C++ magic that cannot match JavaScript semantics.
> 
> Besides, if the platform wants read-only interfaces, then so will users.

It is not correct that DOM*ReadOnly can not exist without constructors. Authors can just not create them.

There were no use case for adding constructors for DOM*ReadOnly. The idea for adding them is so that implementations can return mutable objects that can not be modified by the user. Especially layout and SVG has use cases for that.

If you have good use cases, please send them to the public mailing lists.
Comment 2 Domenic Denicola 2014-06-25 17:20:27 UTC
> It is not correct that DOM*ReadOnly can not exist without constructors. Authors can just not create them.

Right, they can only be created through C++ magic, which is not explicable through JavaScript semantics. This is not acceptable from a technical architecture point of view for the web platform, and is something the TAG has been repeatedly pointing out and correcting throughout specs recently in an attempt to align them with the semantics of the host language.
Comment 3 Dirk Schulze 2014-06-26 08:44:24 UTC
(In reply to Domenic Denicola from comment #2)
> > It is not correct that DOM*ReadOnly can not exist without constructors. Authors can just not create them.
> 
> Right, they can only be created through C++ magic, which is not explicable
> through JavaScript semantics. This is not acceptable from a technical
> architecture point of view for the web platform, and is something the TAG
> has been repeatedly pointing out and correcting throughout specs recently in
> an attempt to align them with the semantics of the host language.

These are DOM objects, no JS objects. It is important that the DOM can create the *ReadOnly objects, not the author.

I actually follow another sentiment where we should not expose any functionality that is not explicitly requested. Exposing unused functionality is much worst for the web platform because it is a bigger burden to get rid of it later when a different API replaces the functionality.
Comment 4 Domenic Denicola 2014-06-27 01:27:30 UTC
> These are DOM objects, no JS objects.

The point we're trying to make is that this distinction is actively hurtful to developer ergonomics and to the health of the web platform. We will be writing a TAG finding on this soon to make it clearer.

> It is important that the DOM can create the *ReadOnly objects, not the author.

Why? Is this a security boundary of some sort? If you create *ReadOnly objects, will users break the security of the browser? I didn't see any such holes in the spec.

> I actually follow another sentiment where we should not expose any functionality that is not explicitly requested.

This argument is not tenable when it involves breaking language semantics. You are not exposing any capabilities that don't already exist as part of the language.

Besides, if we're talking about requests, I'd love to see where anyone requested read-only versions of these objects at all. They are unidiomatic and useless to developers, who would simply expect mutable snapshots with data properties instead of these getter-laden prototypes.

(But that's another story.)

> Exposing unused functionality is much worst for the web platform because it is a bigger burden to get rid of it later when a different API replaces the functionality.

We wouldn't have to keep replacing APIs if they were designed to be idiomatic in the first place.
Comment 5 Dirk Schulze 2014-06-27 04:52:48 UTC
(In reply to Domenic Denicola from comment #4)
> Besides, if we're talking about requests, I'd love to see where anyone
> requested read-only versions of these objects at all. They are unidiomatic
> and useless to developers, who would simply expect mutable snapshots with
> data properties instead of these getter-laden prototypes.

We had very long discussions on public-script, www-style and even at WebApps F2F and CSS F2F in Shenzhen. The specified result was the conclusion of it.
Comment 6 Dirk Schulze 2014-07-22 10:14:33 UTC
(In reply to Dirk Schulze from comment #5)
> (In reply to Domenic Denicola from comment #4)
> > Besides, if we're talking about requests, I'd love to see where anyone
> > requested read-only versions of these objects at all. They are unidiomatic
> > and useless to developers, who would simply expect mutable snapshots with
> > data properties instead of these getter-laden prototypes.
> 
> We had very long discussions on public-script, www-style and even at WebApps
> F2F and CSS F2F in Shenzhen. The specified result was the conclusion of it.

I was told that Blink has similar issues as olliej described with constructors. For now Blink did not implement it with Blink-in-JS but with C++ in DOM.
https://codereview.chromium.org/404803002/
Comment 7 Dirk Schulze 2014-07-22 10:15:19 UTC
(In reply to Dirk Schulze from comment #6)
> (In reply to Dirk Schulze from comment #5)
> > (In reply to Domenic Denicola from comment #4)
> > > Besides, if we're talking about requests, I'd love to see where anyone
> > > requested read-only versions of these objects at all. They are unidiomatic
> > > and useless to developers, who would simply expect mutable snapshots with
> > > data properties instead of these getter-laden prototypes.
> > 
> > We had very long discussions on public-script, www-style and even at WebApps
> > F2F and CSS F2F in Shenzhen. The specified result was the conclusion of it.
> 
> I was told that Blink has similar issues as olliej described with
> constructors. For now Blink did not implement it with Blink-in-JS but with
> C++ in DOM.
> https://codereview.chromium.org/404803002/

Ignore this comment. It was not meant to be on this bug report.
Comment 8 Dirk Schulze 2014-09-15 08:10:42 UTC
I added constructors to all read-only interfaces in the spec now. Please review the changes to DOMMatrix
Comment 9 Simon Pieters 2014-09-15 08:50:43 UTC
IndexSizeError feels a bit wrong to me. I would have expected TypeError.
Comment 10 Dirk Schulze 2014-09-15 09:41:52 UTC
(In reply to Simon Pieters from comment #9)
> IndexSizeError feels a bit wrong to me. I would have expected TypeError.

We only throw IndexSizeError when you have more or less values in a sequence then expected. I thought it would be the proper way in those situations but can be convinced otherwise.
Comment 11 Simon Pieters 2014-09-15 12:47:30 UTC
Right. The description of IndexSizeError is "The index is not in the allowed range.".
https://dom.spec.whatwg.org/#indexsizeerror

However, there is no index provided. There is no allowed range.

What we have is more like arguments, with 6 or 16 arguments allowed. When an API is called with too few arguments, WebIDL throws TypeError.
Comment 12 Dirk Schulze 2014-09-15 16:58:11 UTC
(In reply to Simon Pieters from comment #11)
> Right. The description of IndexSizeError is "The index is not in the allowed
> range.".
> https://dom.spec.whatwg.org/#indexsizeerror
> 
> However, there is no index provided. There is no allowed range.
> 
> What we have is more like arguments, with 6 or 16 arguments allowed. When an
> API is called with too few arguments, WebIDL throws TypeError.

Sounds reasonable. I'll update the spec.
Comment 13 Domenic Denicola 2014-09-16 18:35:50 UTC
LGTM. I've added Alex to the CC since I think he was hoping for something that would allow users to modify the DOMRectReadOnly they create, e.g.

var setter;
var drro = new DOMRectReadOnly(setter_ => setter = setter_);

// give drro to someone; they cannot modify it

// but you can modify it:
setter({ x: 5, y: 10 });

I believe he was going to come up with use cases for this. I think it's a nice-to-have but not too important.
Comment 14 Simon Pieters 2014-12-02 13:45:58 UTC
Let's close this bug.