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

Console output for class instance __proto__ seems wrong #33419

Closed
hashseed opened this issue May 15, 2020 · 1 comment
Closed

Console output for class instance __proto__ seems wrong #33419

hashseed opened this issue May 15, 2020 · 1 comment
Labels
confirmed-bug Issues with confirmed bugs. util Issues and PRs related to the built-in util module.

Comments

@hashseed
Copy link
Member

hashseed commented May 15, 2020

Consider following code

class A {
    getA() { return 0; }
    constructor() {}
}
class B extends A {
    getB() { return 0; }
    constructor() { super(); }
}
console.log((new A()));
console.log((new A()).__proto__);
console.log((new A()).__proto__ instanceof A);
console.log((new A()).__proto__ instanceof Object);
console.log((new B()));
console.log((new B()).__proto__);
console.log((new B()).__proto__ instanceof B);
console.log((new B()).__proto__ instanceof A);

Node 14 produces:

A {}
A {}
false
true
B {}
B {}
false
true

This is wrong since (new B()).__proto__ is an instance of A. I guess the confusing part is that (new B()).__proto__.constructor is class B (which is because of https://tc39.es/ecma262/#sec-makeconstructor)

For reference, Chrome DevTools produces:

A {}
{constructor: ƒ, getA: ƒ}
false
true
B {}
A {constructor: ƒ, getB: ƒ}
false
true
@BridgeAR BridgeAR added the util Issues and PRs related to the built-in util module. label May 15, 2020
@BridgeAR
Copy link
Member

@hashseed do you have a suggestion how to differentiate these easily? We currently check for the constructor and that does not seem to be sufficient. Since you might already know how to improve the check, this could safe me some time digging into this.

@BridgeAR BridgeAR added the confirmed-bug Issues with confirmed bugs. label May 16, 2020
@BridgeAR BridgeAR reopened this May 23, 2020
BridgeAR added a commit to BridgeAR/node that referenced this issue May 23, 2020
To achieve this, some internal custom inspect functions had to be
changed. They relied upon the former behavior.

Fixes: nodejs#33419

Signed-off-by: Ruben Bridgewater <[email protected]>

PR-URL: nodejs#33449
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
codebytere pushed a commit that referenced this issue Jun 18, 2020
To achieve this, some internal custom inspect functions had to be
changed. They relied upon the former behavior.

Signed-off-by: Ruben Bridgewater <[email protected]>

PR-URL: #33449
Fixes: #33419
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
codebytere pushed a commit that referenced this issue Jun 30, 2020
To achieve this, some internal custom inspect functions had to be
changed. They relied upon the former behavior.

Signed-off-by: Ruben Bridgewater <[email protected]>

PR-URL: #33449
Fixes: #33419
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
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.

2 participants