Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class extends null is broken by ECMAScript #98

Open
shinenelson opened this issue May 29, 2020 · 7 comments
Open

class extends null is broken by ECMAScript #98

shinenelson opened this issue May 29, 2020 · 7 comments

Comments

@shinenelson
Copy link
Contributor

class extends null was reverted by ECMAScript in tc39/ecma262#781 ( tc39/ecma262@c57ef95 ) and is still broken.

The kata is abnormal since it doesn't have a solution in the test itself.
So, the question is whether we should have that test for class extends null?

However, I found a possible solution thanks to devdocs.io ( which had a previous version of the MDN Web Docs; revision ) :

class NullClass extends null {}
assert.equal(Object.getPrototypeOf(NullClass), Function.prototype);
@wolframkriesing
Copy link
Collaborator

if i read the spec (I am not sure if I read the wrong part) it looks like its is possible
https://tc39.es/ecma262/#sec-runtime-semantics-classdefinitionevaluation
in 5e it says "If superclass is null, then" and MDN also still says "The .prototype of the extension must be an Object or null."

Do I read those wrong?

@wolframkriesing
Copy link
Collaborator

wolframkriesing commented May 30, 2020

though i dont get it work anywhere neither, here chrome (canary) console

> class A extends null {}
undefined
> new A
VM79:1 Uncaught TypeError: Super constructor null of A is not a constructor
    at new A (<anonymous>:1:1)
    at <anonymous>:1:1

and node repl

> class A extends null {}
undefined
> new A
Uncaught TypeError: Super constructor null of A is not a constructor
    at new A (repl:1:1)

@wolframkriesing
Copy link
Collaborator

wolframkriesing commented May 30, 2020

yeah the only useful thing to learn is what you described. But not really of any practical value, is it?

So I would rather change this test to verify that a parent must be callable with super() and since null has no super it throws. Does that makes sense?

    it('a class extending `null` can not be instantiated, since calling `super()` on null fails', () => {
      class NullClass extends null {}
      assert.throws(() => new NullClass);
    });

like this

@shinenelson
Copy link
Contributor Author

I'm not really sure. Wouldn't that be kind of misleading new developers to assume that a class may extend null?

We should either remove the whole test or explain the rationale behind the use-case. And also somehow probably document somewhere ( in the test itself ) that this is a gray-area test.

Do I read those wrong?

No, what you're reading is correct. The spec was first made to extend null, but then apparently many bad things happened and they reverted it ( see links in issue description )

I found this question on StackOverflow that questions this use-case altogether. The question has different errors of this use-case not working

PS : the issue title is probably misleading, what I meant was that it was broken by ECMAScript and that it wasn't our fault.

@shinenelson shinenelson changed the title class extends null is unsupported by ECMAScript class extends null is broken by ECMAScript May 30, 2020
@wolframkriesing
Copy link
Collaborator

wolframkriesing commented May 30, 2020

i agree, either 1) remove the test or 2) make it more explicit, maybe like that:

it('`extends null` is not supported', () => {
      class NullClass extends null {}
      assert.throws(() => new NullClass);
});

just to mention the edge case and its solution.
What do you think?

@shinenelson
Copy link
Contributor Author

actually, it is supported by the spec, it's just not working as intended. So, maybe, the test should be extends null is broken or something along those lines maybe?

@shinenelson
Copy link
Contributor Author

the MDN revision used the term 'not allowed', so, I guess 'not supported' is close enough. I'd favor 'not allowed' though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants