Files
scriptc/tests/corpus/6020-class-extends-function-constructor.js
T
Chris Tate 201857eb6c Read the class base after the callable-base case in super calls
superCallStmt asserted the class base before checking for a callable
base. A class that extends an ordinary function constructor has no base
class info, so the assertion held null. Node ignores the unused value;
the native compiler throws the TypeError of a non-null assertion that
held null, and failed to compile programs with such classes (for example
the Effect stream fixtures). The base is now read after that case
returns.
2026-10-18 07:54:21 -05:00

28 lines
768 B
JavaScript

// Classes whose base is an ordinary function constructor, with a declared
// constructor calling super and with the implicit derived constructor.
function Shape(name, sides) {
this.name = name;
this.sides = sides;
}
Shape.prototype.describe = function () {
return `${this.name} with ${this.sides} sides`;
};
class Polygon extends Shape {
constructor(name, sides, length) {
super(name, sides);
this.length = length;
}
perimeter() {
return this.sides * this.length;
}
}
class Unnamed extends Shape {}
const square = new Polygon("square", 4, 3);
console.log(square.describe(), square.perimeter());
console.log(square instanceof Polygon);
const shape = new Unnamed("triangle", 3);
console.log(shape.describe(), Object.keys(shape).join(","));