extends null #543

Closed
zloirock opened this Issue Apr 14, 2016 · 6 comments

Projects

None yet

5 participants

@zloirock
zloirock commented Apr 14, 2016 edited

It does not allow me to sleep for a year. It was broken after the last class reform. See the last sentence. For usage this should be called super, but we can't call null. This issue was closed. Now added many serious changes for ES6, so maybe makes sense fix extends null like it was proposed in #22? Usage this in extended from null constructors without super or a special case for super in those constructors should not break any current code, but should make extends null useful instead of current useless garbage in the spec.

@bterlson
Member

@zloirock not sleeping is definitely a bug. We should fix this. I think @allenwb's suggestion in #22 is sound (modulo early error restrictions, but I'm not seeing any).

@zloirock
zloirock commented Apr 14, 2016 edited

@bterlson special case for usage super in those constructors should remove early error and default constructor issues:

var this = Parent !== null ? Reflect.construct(Parent, args, new.target) : Object.create(new.target.prototype);
@allenwb
Member
allenwb commented Apr 14, 2016

I agree. I think it is a specification bug that extend null classes were marked as "derived"

@bterlson bterlson added a commit that closed this issue Apr 19, 2016
@bterlson bterlson Normative: Set this appropriately for class extends null
Previously, the [[ConstructorKind]] slot was set to "derived"
which would not allow accessing this in the constructor. We now
set [[ConstructorKind]] to "base" so [[Construct]] allocates and
binds this in the function body (to Object.create(C.prototype),
which will be Object.create(null) as per CDI).

Fixes #543.
98c67f2
@bterlson bterlson closed this in 98c67f2 Apr 19, 2016
@loganfsmyth

@bterlson Assuming I'm following this right, this still means the existing spec behavior of

class Foo extends null {
    constructor(){
        super();
    }
}

will throw because super() can't be used in an extends null class, correct? If so, it seems like step 10 should also be updated, since this will now initialize this by default, but still default to calling super() when no constructor is given.

I'll admit, auto-initializing this seems unfortunate to me though, it seems much more consistent to always require super() to initialize this even in cases where it is null, since "use super() when you have extends" is a more straightforward thing to understand from an end-user stand-point.

@bterlson
Member

Yep, good catch, overlooked it (and fixed via a35f0f3). I don't think super makes sense here since there is no super constructor.

@ljharb ljharb referenced this issue in kangax/compat-table Apr 29, 2016
Closed

class extends null 2017 updates #788

@jugglinmike jugglinmike added a commit to bocoup/test262 that referenced this issue May 30, 2016
@jugglinmike jugglinmike Update tests concerning null-extending classes
The latest revision of ECMA262 makes special provisions for classes
which extend the `null` value [1]. Update the relevant tests
accordingly.

[1] tc39/ecma262#543
029909f
@jugglinmike jugglinmike added a commit to bocoup/test262 that referenced this issue May 30, 2016
@jugglinmike jugglinmike Update tests concerning null-extending classes
The latest revision of ECMA262 makes special provisions for classes
which extend the `null` value [1]. Update the relevant tests
accordingly.

[1] tc39/ecma262#543
7a2d7c6
@jugglinmike jugglinmike added a commit to bocoup/test262 that referenced this issue May 30, 2016
@jugglinmike jugglinmike Update tests concerning null-extending classes
The latest revision of ECMA262 makes special provisions for classes
which extend the `null` value [1]. Update the relevant tests
accordingly.

[1] tc39/ecma262#543
6f76292
@leobalter leobalter added a commit to tc39/test262 that referenced this issue Jun 10, 2016
@jugglinmike @leobalter jugglinmike + leobalter Update tests concerning null-extending classes (#658)
The latest revision of ECMA262 makes special provisions for classes
which extend the `null` value [1]. Update the relevant tests
accordingly.

[1] tc39/ecma262#543
dee1526
@littledan
Contributor

The change here makes sense to me, but I missed this thread until the test262 test went in and V8 failed it. I'm wondering, for normative changes like this, would it make sense to summarize them at TC39 (or some other place which really highlights it), and get some implementation feedback (or documentation that an implementation already does this) before committing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment