Closed
Bug 838540
Opened 12 years ago
Closed 10 years ago
Implement ES6 @@create semantics
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
INVALID
People
(Reporter: bruant.d, Unassigned)
References
(Blocks 1 open bug)
Details
I haven't found a good description of @@create.
It originated on es-discuss (jorendorff) [1] and it's been integrated to the latest draft [2].
@@create allow to subclass exotic objects (Array, Date, Element, etc.)
It seems that WebComponents want it too [3]
[1] https://mail.mozilla.org/pipermail/es-discuss/2012-November/026746.html
[2] http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts
[3] http://lists.w3.org/Archives/Public/public-webapps/2013JanMar/0250.html
Reporter | ||
Updated•12 years ago
|
Blocks: harmony-classes, es6
Comment 1•12 years ago
|
||
Some notes on @@create from a spec perspective:
* It's a Symbol keyed method of functions that is called during construction
* It brings prototypal inheritance into object construction since it's a regular property of the constructor, rather than an internal property
* Most builtins override the default Function.prototype.@@create with their own (for example, Array.@@create) that is responsible for adding the [[Class]] to the object
* It splits object creation into two parts: allocation (in @@create) and initialization (the constructor)
* It is important for classes because it allows `super()` in constructors inheriting from builtins to actually work and it allows instances of subclassed builtins to have all the necessary internal state to be a legit instance of the builtin type. For example:
class MyArray extends Array {
constructor(...args){
this.isMyArray = true;
super(...args);
}
}
let arr = new MyArray(5, 10, 20);
Array.isArray(arr); // true
arr.length; // 3
Comment 2•12 years ago
|
||
A few points:
- To some extent, this is blocking DOM work on subclassing arrays for `Elements` [1].
- The easiest way to summarize @@create is `new X(...args)` <-> `X.call(X[@@create](), ...args)`.
- One particular user-facing consequence for current code, without ES6 class syntax, is:
function X() { }
X.__proto__ = Array;
var x = new X();
Array.isArray(x); // should be true
because `X[@@create]()` calls `Array[@@create]()` which allocates an exotic array object. (In addition to changing `Array.isArray`'s answer, exotic array objects have the special DefineOwnProperty behavior that messes with `length`.)
[1]: https://gist.github.com/domenic/5864658
Comment 4•11 years ago
|
||
To make this fast, we'll need to make isConstructing fast.
Depends on: 1002473
Comment 5•11 years ago
|
||
I don't know if this is too much work, but would be awesome to have this in Moz33 as well since Symbol landed in the same version!
Comment 6•11 years ago
|
||
Not only is this a very different feature from symbols (it relies on them, but nothing more), it's also a pretty big task, so it won't happen in this release cycle.
Additionally, it's not even clear what the final spec will say about this; there are at least two competing proposals for roughly what @@create is intended to be used for:
https://mail.mozilla.org/pipermail/es-discuss/2014-June/037810.html
https://mail.mozilla.org/pipermail/es-discuss/2014-June/038120.html
Comment 7•11 years ago
|
||
Yeah, I thought so, but did not know the spec hasn't even stabilized yet. Please ignore my comment.
Assignee | ||
Updated•11 years ago
|
Assignee: general → nobody
Comment 8•10 years ago
|
||
This spec design has been abandoned in favor of super() and new.target
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → INVALID
Comment 9•10 years ago
|
||
Eric, is there a bug about implementing that or any other information you can point us to?
Flags: needinfo?(efaustbmo)
Comment 10•10 years ago
|
||
Sure! The current work on this front is all in the dependency tree of bug 1141863. SuperCall is a ton of work, in the new spec, so it's proceeding slowly along.
Flags: needinfo?(efaustbmo)
Updated•10 years ago
|
No longer blocks: harmony-classes
You need to log in
before you can comment on or make changes to this bug.
Description
•