[blink-dev: FYI]Classes syntax are part of ES6. The spec in Editor's draft is stable.IE has classes in preview release [1]. No other browser currently ships classes (Mozilla bug [2]).V8 implementation of classes is up-to-date with the latest ES6 spec modulo the limitations noted below.Limitations:- Classes are dependent on lexical declarations. Since the latter are currently only supported in strict mode, we currently only support classes in strict mode as well.- At this time we do not support subclassing built-ins and DOM objects- Current ES6 specification (in particular, [[CreateAction]] hook that takes arguments) makes design of subclassable exotic (in particular DOM) objects unclear. We intend to work with involved parties on resolving this difficulty, but for now we add an extra limitation to calls to super constructor in subclasses: if a subclass constructor calls a superclass constructor via ‘super(...)’ call, that call must be the first statement of constructor’s body, and arguments to ‘super(...)’ call can not refer to ‘this’.We intend to lift this restriction in the future, once we clarify the design for exotic objects’ subclassing.
On Mon, Dec 15, 2014 at 6:15 AM, Dmitry Lomov <dsl...@chromium.org> wrote:[blink-dev: FYI]Classes syntax are part of ES6. The spec in Editor's draft is stable.IE has classes in preview release [1]. No other browser currently ships classes (Mozilla bug [2]).V8 implementation of classes is up-to-date with the latest ES6 spec modulo the limitations noted below.Limitations:- Classes are dependent on lexical declarations. Since the latter are currently only supported in strict mode, we currently only support classes in strict mode as well.- At this time we do not support subclassing built-ins and DOM objects- Current ES6 specification (in particular, [[CreateAction]] hook that takes arguments) makes design of subclassable exotic (in particular DOM) objects unclear. We intend to work with involved parties on resolving this difficulty, but for now we add an extra limitation to calls to super constructor in subclasses: if a subclass constructor calls a superclass constructor via ‘super(...)’ call, that call must be the first statement of constructor’s body, and arguments to ‘super(...)’ call can not refer to ‘this’.We intend to lift this restriction in the future, once we clarify the design for exotic objects’ subclassing.Is the super() restriction true for all subclassing, or just exotic subclassing?
On 12/16/14, 1:56 AM, Dmitry Lomov wrote:
the problem with this option is that between entry to the constructor
and call to super(...) `this` is necessarily an exotic ImageData in some
sort of semi-initialized state.
That semi-initialized state has never been exposed to Javascript before,
and our code is just not ready for this.
This was also my take on the situation in Gecko+SpiderMonkey, until I realized that we can simply allocate an object with the right memory layout but not actually brand it as an ImageData object until the ImageData constructor executes.
The hard part, of course, is "brand it as an ImageData object" in a dynamic way. That's not possible with the current SpiderMonkey API, but internally SpiderMonkey already has facilities for doing things like that, and we can add API for them. Such facilities may not exist in all ES implementations, of course....
All methods on ImageData or accepting ImageData need to make sure that
ImageData they get is fully initialized, or throw (?) otherwise.
With the above approach this is not an issue, because such methods will behave just like they would if the object involved were created via "new Object".
This is a lot of work to implement and obviously a (security) bug-farm -
for very little gain.
I agree that there's work involved here, but I disagree that this is a security bug-farm if things are done in a principled way.
More to the point, this has been hashed out ad nauseam in TC39 meetings and on es-discuss. The two options you describe are the only ones that people have managed to come up with that are at all sane.
Is there a concrete plan for proposing something else, or is the concrete plan to simply never allow subclassing of builtins? Because that's the one concrete option 3 here, and it's not a very palatable or desirable one either....
Is there a concrete plan for proposing something else, or is the concrete plan to simply never allow subclassing of builtins? Because that's the one concrete option 3 here, and it's not a very palatable or desirable one either....What we would propose is `this` being in TDZ until the call to 'super(...)'. Here is a brief summary:1. [[CreateAction]] takes no arguments2. Inherited [[CreateAction]] is only invoked if your subclass constructor calls 'super(...)', otherwise you get a plain Object.3. If your subclass constructor calls 'super(...)', `this` is in TDZ until that super call.This has be be beaten on by the committee of course.
On Tuesday, December 16, 2014 2:50:40 AM UTC-8, Dmitry Lomov wrote:
...Is there a concrete plan for proposing something else, or is the concrete plan to simply never allow subclassing of builtins? Because that's the one concrete option 3 here, and it's not a very palatable or desirable one either....What we would propose is `this` being in TDZ until the call to 'super(...)'. Here is a brief summary:1. [[CreateAction]] takes no arguments2. Inherited [[CreateAction]] is only invoked if your subclass constructor calls 'super(...)', otherwise you get a plain Object.3. If your subclass constructor calls 'super(...)', `this` is in TDZ until that super call.This has be be beaten on by the committee of course.
Unless you intend to try to delay ES6 for at least 6 months there is no time for the committee to beat on this. The final technical draft must be be completed before the Jan. TC39 meeting in order to be on track for Ecma approval in June. This week would be good time to resolve any remaining issues. Why has this not been on es-discuss or the TC39 internal mailing list?
Let me turn this around on you. What in the current draft prevents you from implementing object allocation lazily exactly as you describe above? And is there anything in the current draft that would be incompatible with future spec. changes such as formalizing the above or even going with the full new^ proposal? I don't think so, but if you see something let me know.
Consider: No ES6 specified [[CreateAction]] has any dependencies upon the constructor arguments and there is no current language level way to specify the equivalent of a [[CreateAction]] for a class declaration. That means that (for ES6) adding additional classes (for example DOM classes) that provide a [[CreateAction]] is something that must happen in a implementation specific manner using implementation specific interfaces. Just as with "host objects" in previous ES editions, such implementation level extensions are completely under your control. You can allow or forbid [[CreateActions]] that use the constructor arguments, as you see fit.
On Dec 16, 2014, at 11:25 AM, Dmitry Lomov wrote:On Tue, Dec 16, 2014 at 7:04 PM, Allen Wirfs-Brock <al...@wirfs-brock.com> wrote:
The V8 concern seems to be about hypothetical that aren't actually in the Es6 specification. Anything other than the [[CreateAction]]'s defined in the ES6 spec. are non-standard implementation specific extensions. What an implementation allows or doesn't allow for such extensions (if it allows them at all) is completely up to it. But, making the above illegal would clearly be a significant unilateral deviation from the specification, the benefit of which I still don't see.Our concern here is not hypothetical, as my example with ImageData clearly illustrates - just replace Foo with ImageData in Dominic's example (or derive Foo from ImageData).These extensions might be non-standard from ES point-of-view, but DOM classes are very-very much standard in our browsers, and we just do not have either a standard for how to subclass these things, or a very good guidance for what those subclasses will be ([[CreateAction]] is problematic for the reasons above). Therefore we opt for a conservative thing.We extend this conservative point of view on normal ES classes as well out of abundance of caution. As the first implementors, we need to tread water carefully here.DmitryBut there is noting called ImageData in the ES6 specification nor any requirement that, if you implement this DOM class, that it be usefully subclassable, You may implement it using any sort of exotic object restrictions including providing a [[Construct]] semantics that does anything you want. The ES level definition of things like ImageData and the ability to subclass them is certainly a concern for post-ES6 editions of the standard but is not something that can be addressed right now.
You are certainly free to stage you implementation of ES6 in whatever order words best for you and ultimately confirming to ES6 or not is a your choice. Your ImageData concerns are not a problem for any of the ES6 specified built-ins and certainly not an issue for ES level class definitions that don't subclass such built-ins.
Other implementation have alway weighed in and said that they can live with what is current in the ES6 spec. I hope that your conservatism isn't really a form of obstructionism.
On 12/16/14, 1:56 AM, Dmitry Lomov wrote:
Option 2: pass arguments to [[CreateAction]] hook.
[[CreateAction]] hook is the hook that is invoked directly before
construction, and has access to constructor arguments.
Dmitry,
I finally have all this stuff paged in again. Sending one last mail here to make sure we're on the same page, and my apologies for hijacking your lists.
So if I recall correctly, the setup with [[CreateAction]] is meant to allow subclassing of builtins without requiring implementations to expose uninitialized builtin objects, with the restriction you mention: the constructor arguments have to have the builtin constructor arguments as a prefix.
I _believe_ the idea is that this allows some subclassing of builtins and that once we (TC39 + WebIDL) have sorted out how to do whatever it is we're doing in ES7 we can loosen the argument order restriction without breaking anything that's already using the current setup.
I know you think the argument order restriction is unacceptable, but it's not being proposed to stay long-term.
On Tue, Dec 16, 2014 at 11:19 PM, Boris Zbarsky <bzba...@mit.edu> wrote:
On 12/16/14, 1:56 AM, Dmitry Lomov wrote:
...
I _believe_ the idea is that this allows some subclassing of builtins and that once we (TC39 + WebIDL) have sorted out how to do whatever it is we're doing in ES7 we can loosen the argument order restriction without breaking anything that's already using the current setup.
I know you think the argument order restriction is unacceptable, but it's not being proposed to stay long-term.Nothing is more permanent than temporary measures, as the saying goes.[[CreateAction]] with arguments is clearly a wrong design, and until we see a clear path for removing the argument order restriction, it is irresponsible to ship a broken thing with no recourse.
It is my understanding (I might be incorrect) that IE implements Option 2 in preview release.
I finally have all this stuff paged in again. Sending one last mail
here to make sure we're on the same page, and my apologies for hijacking
your lists.