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

TypeError: clazz is not a constructor on ≥ v11.6.0 #25451

Closed
nakhodkin opened this issue Jan 11, 2019 · 4 comments
Closed

TypeError: clazz is not a constructor on ≥ v11.6.0 #25451

nakhodkin opened this issue Jan 11, 2019 · 4 comments
Labels
confirmed-bug Issues with confirmed bugs. util Issues and PRs related to the built-in util module.

Comments

@nakhodkin
Copy link

I'm experiencing an issue with a following piece of code

screen shot 2019-01-11 at 10 27 41 pm

'use strict';

const people = [
  ['John', 19, 'm'],
  ['Valentine', 28, 'f'],
  ['Christina', 25, 'f']
];

class Person {
  get name() {
    return this[0];
  }
  
  get age() {
    return this[1];
  }
  
  get sex() {
    return this[2];
  }
}

people.forEach(person => Object.setPrototypeOf(person, Person.prototype));

const query = person => person.age > 25;

people.filter(query);

You can see a more detailed information about the stacktrace right below
screen shot 2019-01-11 at 10 49 55 pm

  • Node: v11.6.0:
  • Platform: macOS Mojave Version 10.14.2:
@mscdex
Copy link
Contributor

mscdex commented Jan 11, 2019

There probably is a bug here with util.inspect(), but the issue here is that you overwriting each array's prototype (Array.prototype) with Person.prototype, so when you try to access the getter, the indexed properties no longer work because those are implemented by Array.prototype.

@mscdex
Copy link
Contributor

mscdex commented Jan 11, 2019

You can fix the prototype issue by changing class Person to class Person extends Array and then you will get the expected result.

@devsnek
Copy link
Member

devsnek commented Jan 11, 2019

this happens with the indexed/keyed collections when they have the right internal slots but the wrong prototype (prototype constructor is missing, from noIteratorPrototype util). I think it's worth fixing.

@BridgeAR BridgeAR added confirmed-bug Issues with confirmed bugs. util Issues and PRs related to the built-in util module. labels Jan 11, 2019
@BridgeAR
Copy link
Member

Yes, there's a check missing if the prototype is null or not.

If it is not null, we should keep the prototype and fall back to the regular object inspection.

BridgeAR added a commit to BridgeAR/node that referenced this issue Jan 16, 2019
The fallback should only be taken for a null prototype. If an
iterable data type (e.g., Array) has a prototype without
`Symbol.iterator`, just try the best to visualize it as object.

Fixes: nodejs#25451
@danbev danbev closed this as completed in 2c0a751 Jan 18, 2019
addaleax pushed a commit that referenced this issue Jan 23, 2019
The fallback should only be taken for a null prototype. If an
iterable data type (e.g., Array) has a prototype without
`Symbol.iterator`, just try the best to visualize it as object.

PR-URL: #25457
Fixes: #25451
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants