Closed Bug 838540 Opened 12 years ago Closed 10 years ago

Implement ES6 @@create semantics

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

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
Blocks: 804279
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
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
Blocks: 915669
No longer blocks: 915669
Blocks: 982671
To make this fast, we'll need to make isConstructing fast.
Depends on: 1002473
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!
Depends on: harmony:symbols
OS: Linux → All
Hardware: x86 → All
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
Yeah, I thought so, but did not know the spec hasn't even stabilized yet. Please ignore my comment.
Assignee: general → nobody
Blocks: 1142337
This spec design has been abandoned in favor of super() and new.target
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → INVALID
Eric, is there a bug about implementing that or any other information you can point us to?
Flags: needinfo?(efaustbmo)
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)
No longer blocks: harmony-classes
No longer blocks: 1142337
You need to log in before you can comment on or make changes to this bug.